celluloid 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,11 +25,8 @@ module Celluloid
25
25
 
26
26
  # Obtain the currently running actor (if one exists)
27
27
  def current_actor
28
- actor = Thread.current[:actor]
29
- raise NotActorError, "not in actor scope" unless actor
30
- actor.proxy
28
+ Actor.current
31
29
  end
32
- alias_method :current, :current_actor
33
30
 
34
31
  # Receive an asynchronous message
35
32
  def receive(timeout = nil, &block)
@@ -111,7 +108,7 @@ module Celluloid
111
108
 
112
109
  # Create a new actor and link to the current one
113
110
  def new_link(*args, &block)
114
- current_actor = Celluloid.current_actor
111
+ current_actor = Actor.current
115
112
  raise NotActorError, "can't link outside actor context" unless current_actor
116
113
 
117
114
  proxy = Actor.new(allocate).proxy
@@ -207,7 +204,7 @@ module Celluloid
207
204
 
208
205
  # Obtain the current_actor
209
206
  def current_actor
210
- Celluloid.current_actor
207
+ Actor.current
211
208
  end
212
209
 
213
210
  # Obtain the running tasks for this actor
@@ -229,13 +226,13 @@ module Celluloid
229
226
 
230
227
  # Link this actor to another, allowing it to crash or react to errors
231
228
  def link(actor)
232
- actor.notify_link current_actor
229
+ actor.notify_link Actor.current
233
230
  notify_link actor
234
231
  end
235
232
 
236
233
  # Remove links to another actor
237
234
  def unlink(actor)
238
- actor.notify_unlink current_actor
235
+ actor.notify_unlink Actor.current
239
236
  notify_unlink actor
240
237
  end
241
238
 
@@ -23,6 +23,13 @@ module Celluloid
23
23
  attr_reader :proxy, :tasks, :links, :mailbox
24
24
 
25
25
  class << self
26
+ # Obtain the current actor
27
+ def current
28
+ actor = Thread.current[:actor]
29
+ raise NotActorError, "not in actor scope" unless actor
30
+ actor.proxy
31
+ end
32
+
26
33
  # Invoke a method on the given actor via its mailbox
27
34
  def call(mailbox, meth, *args, &block)
28
35
  call = SyncCall.new(Thread.mailbox, meth, args, block)
@@ -96,11 +103,6 @@ module Celluloid
96
103
  end
97
104
  end
98
105
 
99
- # Is this actor alive?
100
- def alive?
101
- @running
102
- end
103
-
104
106
  # Is this actor running in exclusive mode?
105
107
  def exclusive?
106
108
  @exclusive
@@ -117,7 +119,6 @@ module Celluloid
117
119
  # Terminate this actor
118
120
  def terminate
119
121
  @running = false
120
- nil
121
122
  end
122
123
 
123
124
  # Send a signal with the given name to all waiting methods
@@ -144,6 +145,8 @@ module Celluloid
144
145
  rescue ExitEvent => exit_event
145
146
  Task.new(:exit_handler) { handle_exit_event exit_event }.resume
146
147
  retry
148
+ rescue TerminationRequest
149
+ break
147
150
  end
148
151
 
149
152
  if message
@@ -54,18 +54,14 @@ module Celluloid
54
54
 
55
55
  # Terminate the associated actor
56
56
  def terminate
57
- raise DeadActorError, "actor already terminated" unless alive?
58
-
59
- begin
60
- _send_ :terminate
61
- rescue DeadActorError
62
- # In certain cases this is thrown during termination. This is likely
63
- # a bug in Celluloid's internals, but it shouldn't affect the caller.
64
- # FIXME: track this down and fix it, or at the very least log it
65
- end
57
+ terminate!
58
+ Thread.pass while alive?
59
+ end
66
60
 
67
- # Always return nil until a dependable exit value can be obtained
68
- nil
61
+ # Terminate the associated actor asynchronously
62
+ def terminate!
63
+ raise DeadActorError, "actor already terminated" unless alive?
64
+ @mailbox.system_event TerminationRequest.new
69
65
  end
70
66
 
71
67
  # method_missing black magic to call bang predicate methods asynchronously
@@ -11,4 +11,7 @@ module Celluloid
11
11
  super reason.to_s
12
12
  end
13
13
  end
14
+
15
+ # Request for an actor to terminate
16
+ class TerminationRequest < SystemEvent; end
14
17
  end
@@ -28,7 +28,8 @@ module Celluloid
28
28
  @messages << message
29
29
  @condition.signal
30
30
  nil
31
- ensure @mutex.unlock
31
+ ensure
32
+ @mutex.unlock rescue nil
32
33
  end
33
34
  end
34
35
 
@@ -41,7 +42,8 @@ module Celluloid
41
42
  @condition.signal
42
43
  end
43
44
  nil
44
- ensure @mutex.unlock
45
+ ensure
46
+ @mutex.unlock rescue nil
45
47
  end
46
48
  end
47
49
 
@@ -71,7 +73,8 @@ module Celluloid
71
73
  end until message
72
74
 
73
75
  message
74
- ensure @mutex.unlock
76
+ ensure
77
+ @mutex.unlock rescue nil
75
78
  end
76
79
  end
77
80
 
@@ -100,7 +103,8 @@ module Celluloid
100
103
  messages = @messages
101
104
  @messages = []
102
105
  @dead = true
103
- ensure @mutex.unlock
106
+ ensure
107
+ @mutex.unlock rescue nil
104
108
  end
105
109
 
106
110
  messages.each { |msg| msg.cleanup if msg.respond_to? :cleanup }
@@ -3,6 +3,7 @@ module Celluloid
3
3
  class Pool
4
4
  include Celluloid
5
5
  trap_exit :crash_handler
6
+ attr_reader :max_actors
6
7
 
7
8
  # Takes a class of actor to pool and a hash of options:
8
9
  #
@@ -10,9 +11,10 @@ module Celluloid
10
11
  # * max_size: maximum number of actors (default one actor per CPU core)
11
12
  # * args: an array of arguments to pass to the actor's initialize
12
13
  def initialize(klass, options = {})
14
+ raise ArgumentError, "A Pool has a minimum size of 2" if options[:max_size] && options[:max_size] < 2
13
15
  opts = {
14
16
  :initial_size => 1,
15
- :max_size => Celluloid.cores,
17
+ :max_size => [Celluloid.cores, 2].max,
16
18
  :args => []
17
19
  }.merge(options)
18
20
 
@@ -1,4 +1,4 @@
1
1
  module Celluloid
2
- VERSION = '0.9.1'
2
+ VERSION = '0.10.0'
3
3
  def self.version; VERSION; end
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70275106519080 !ruby/object:Gem::Requirement
16
+ requirement: &70363787045800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70275106519080
24
+ version_requirements: *70363787045800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70275106518620 !ruby/object:Gem::Requirement
27
+ requirement: &70363787045200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70275106518620
35
+ version_requirements: *70363787045200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard-rspec
38
- requirement: &70275106518200 !ruby/object:Gem::Requirement
38
+ requirement: &70363787044600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70275106518200
46
+ version_requirements: *70363787044600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: benchmark_suite
49
- requirement: &70275106517780 !ruby/object:Gem::Requirement
49
+ requirement: &70363787044060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70275106517780
57
+ version_requirements: *70363787044060
58
58
  description: Celluloid enables people to build concurrent programs out of concurrent
59
59
  objects just as easily as they build sequential programs out of sequential objects
60
60
  email:
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: 1.3.6
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 1.8.10
116
+ rubygems_version: 1.8.17
117
117
  signing_key:
118
118
  specification_version: 3
119
119
  summary: Actor-based concurrent object framework for Ruby
120
120
  test_files: []
121
- has_rdoc: