tribe 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,13 +36,13 @@ Or install it yourself as:
36
36
  end
37
37
 
38
38
  def exception_handler(e)
39
- puts concat_e("MyActor (#{identifier}) died.", e)
40
39
  super
40
+ puts concat_e("MyActor (#{identifier}) died.", e)
41
41
  end
42
42
 
43
43
  def shutdown_handler(event)
44
- puts "MyActor (#{identifier}) is shutting down. Put cleanup code here."
45
44
  super
45
+ puts "MyActor (#{identifier}) is shutting down. Put cleanup code here."
46
46
  end
47
47
  end
48
48
 
data/lib/tribe/actable.rb CHANGED
@@ -42,17 +42,15 @@ module Tribe
42
42
  while (event = @mailbox.shift)
43
43
  case event.command
44
44
  when :shutdown
45
+ cleanup
45
46
  shutdown_handler(event)
46
- @pool.shutdown if @dedicated
47
- @mailbox.synchronize { @alive = false }
48
47
  else
49
48
  process_event(event)
50
49
  end
51
50
  end
52
51
 
53
52
  rescue Exception => e
54
- @alive = false
55
- @pool.shutdown if @dedicated
53
+ cleanup
56
54
  exception_handler(e)
57
55
  ensure
58
56
  @mailbox.release do
@@ -62,13 +60,24 @@ module Tribe
62
60
  return nil
63
61
  end
64
62
 
63
+ def cleanup
64
+ @pool.shutdown if @dedicated
65
+ @mailbox.synchronize { @alive = false }
66
+ @registry.unregister(self)
67
+
68
+ return nil
69
+ end
70
+
71
+ # Override and call super as necessary.
65
72
  def process_event(event)
66
73
  send("on_#{event.command}", event)
67
74
  end
68
75
 
76
+ # Override and call super as necessary.
69
77
  def exception_handler(e)
70
78
  end
71
79
 
80
+ # Override and call super as necessary.
72
81
  def shutdown_handler(event)
73
82
  end
74
83
  end
@@ -1,5 +1,7 @@
1
1
  module Tribe
2
2
  class DedicatedActor < Tribe::Actor
3
+ private
4
+
3
5
  def initialize(options = {})
4
6
  options[:dedicated] = true
5
7
 
@@ -3,30 +3,26 @@ module Tribe
3
3
  def initialize
4
4
  @mutex = Mutex.new
5
5
  @actors_by_name = {}
6
+ @actors_by_oid = {}
6
7
  end
7
8
 
8
9
  def register(actor)
9
10
  @mutex.synchronize do
10
- return false unless actor.name
11
+ raise("Actor already exists (#{actor.name}).") if @actors_by_name.key?(actor.name)
11
12
 
12
- if @actors_by_name[actor.name]
13
- raise "Actor already exists (#{actor.name})."
14
- else
15
- @actors_by_name[actor.name] = actor
16
- end
13
+ @actors_by_name[actor.name] = actor if actor.name
14
+ @actors_by_oid[actor.object_id] = actor
17
15
 
18
- return true
16
+ return nil
19
17
  end
20
18
  end
21
19
 
22
20
  def unregister(actor)
23
21
  @mutex.synchronize do
24
- return false unless actor.name
25
- return false unless @actors_by_name[actor.name]
22
+ @actors_by_name.delete(actor.name) if actor.name
23
+ @actors_by_oid.delete(actor.object_id)
26
24
 
27
- @actors_by_name.delete(actor.name)
28
-
29
- return true
25
+ return nil
30
26
  end
31
27
  end
32
28
 
@@ -39,6 +35,15 @@ module Tribe
39
35
  def dispose
40
36
  @mutex.synchronize do
41
37
  @actors_by_name.clear
38
+ @actors_by_oid.clear
39
+
40
+ return nil
41
+ end
42
+ end
43
+
44
+ def inspect
45
+ @mutex.synchronize do
46
+ return "#<#{self.class.to_s}:0x#{(object_id << 1).to_s(16)} oid_count=#{@actors_by_oid.count}, named_count=#{@actors_by_name.count}>"
42
47
  end
43
48
  end
44
49
  end
data/lib/tribe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tribe
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
data/tribe.gemspec CHANGED
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Tribe::VERSION
17
17
 
18
- gem.add_dependency('workers', '0.0.6')
18
+ gem.add_dependency('workers', '0.0.8')
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.6
21
+ version: 0.0.8
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.6
29
+ version: 0.0.8
30
30
  description: Tribe is a Ruby gem that implements event-driven actors.
31
31
  email:
32
32
  - chad@remesch.com