celluloid 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/celluloid.rb +5 -8
- data/lib/celluloid/actor.rb +9 -6
- data/lib/celluloid/actor_proxy.rb +7 -11
- data/lib/celluloid/events.rb +3 -0
- data/lib/celluloid/mailbox.rb +8 -4
- data/lib/celluloid/pool.rb +3 -1
- data/lib/celluloid/version.rb +1 -1
- metadata +11 -12
data/lib/celluloid.rb
CHANGED
@@ -25,11 +25,8 @@ module Celluloid
|
|
25
25
|
|
26
26
|
# Obtain the currently running actor (if one exists)
|
27
27
|
def current_actor
|
28
|
-
|
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 =
|
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
|
-
|
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
|
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
|
235
|
+
actor.notify_unlink Actor.current
|
239
236
|
notify_unlink actor
|
240
237
|
end
|
241
238
|
|
data/lib/celluloid/actor.rb
CHANGED
@@ -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
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
68
|
-
|
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
|
data/lib/celluloid/events.rb
CHANGED
data/lib/celluloid/mailbox.rb
CHANGED
@@ -28,7 +28,8 @@ module Celluloid
|
|
28
28
|
@messages << message
|
29
29
|
@condition.signal
|
30
30
|
nil
|
31
|
-
ensure
|
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
|
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
|
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
|
106
|
+
ensure
|
107
|
+
@mutex.unlock rescue nil
|
104
108
|
end
|
105
109
|
|
106
110
|
messages.each { |msg| msg.cleanup if msg.respond_to? :cleanup }
|
data/lib/celluloid/pool.rb
CHANGED
@@ -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
|
|
data/lib/celluloid/version.rb
CHANGED
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.
|
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-
|
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: &
|
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: *
|
24
|
+
version_requirements: *70363787045800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
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: *
|
35
|
+
version_requirements: *70363787045200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard-rspec
|
38
|
-
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: *
|
46
|
+
version_requirements: *70363787044600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: benchmark_suite
|
49
|
-
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: *
|
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.
|
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:
|