celluloid 0.12.0 → 0.12.1.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,11 @@ require 'set'
6
6
  module Celluloid
7
7
  extend self # expose all instance methods as singleton methods
8
8
 
9
- SHUTDOWN_TIMEOUT = 120 # How long actors have to terminate
9
+ # How long actors have to terminate
10
+ SHUTDOWN_TIMEOUT = 120
11
+
12
+ # Warning message added to Celluloid objects accessed outside their actors
13
+ BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "
10
14
 
11
15
  class << self
12
16
  attr_accessor :logger # Thread-safe logger class
@@ -194,15 +198,24 @@ module Celluloid
194
198
  # These are methods we don't want added to the Celluloid singleton but to be
195
199
  # defined on all classes that use Celluloid
196
200
  module InstanceMethods
197
- # Obtain the Ruby object the actor is wrapping. This should ONLY be used
198
- # for a limited set of use cases like runtime metaprogramming. Interacting
199
- # directly with the wrapped object foregoes any kind of thread safety that
201
+ # Obtain the bare Ruby object the actor is wrapping. This is useful for
202
+ # only a limited set of use cases like runtime metaprogramming. Interacting
203
+ # directly with the bare object foregoes any kind of thread safety that
200
204
  # Celluloid would ordinarily provide you, and the object is guaranteed to
201
205
  # be shared with at least the actor thread. Tread carefully.
202
- def wrapped_object; self; end
206
+ #
207
+ # Bare objects can be identified via #inspect output:
208
+ #
209
+ # >> actor
210
+ # => #<Celluloid::Actor(Foo:0x3fefcb77c194)>
211
+ # >> actor.bare_object
212
+ # => #<WARNING: BARE CELLULOID OBJECT (Foo:0x3fefcb77c194)>
213
+ #
214
+ def bare_object; self; end
215
+ alias_method :wrapped_object, :bare_object
203
216
 
204
217
  def inspect
205
- str = "#<Celluloid::Actor(#{self.class}:0x#{object_id.to_s(16)})"
218
+ str = "#<#{Celluloid::BARE_OBJECT_WARNING_MESSAGE}(#{self.class}:0x#{object_id.to_s(16)})"
206
219
  ivars = instance_variables.map do |ivar|
207
220
  "#{ivar}=#{instance_variable_get(ivar).inspect}"
208
221
  end
@@ -240,11 +253,6 @@ module Celluloid
240
253
  # directly inside of all classes that include Celluloid
241
254
  #
242
255
 
243
- # Is this actor alive?
244
- def alive?
245
- Thread.current[:actor].alive?
246
- end
247
-
248
256
  # Raise an exception in caller context, but stay running
249
257
  def abort(cause)
250
258
  cause = case cause
@@ -76,6 +76,10 @@ module Celluloid
76
76
  _send_ :inspect
77
77
  end
78
78
 
79
+ def size
80
+ @size
81
+ end
82
+
79
83
  # Provision a new worker
80
84
  def __provision_worker
81
85
  while @idle.empty?
@@ -1,7 +1,7 @@
1
1
  module Celluloid
2
2
  # A proxy object returned from Celluloid::Actor.new/new_link which converts
3
3
  # the normal Ruby method protocol into an inter-actor message protocol
4
- class ActorProxy < AbstractProxy
4
+ class ActorProxy
5
5
  attr_reader :mailbox, :thread
6
6
 
7
7
  def initialize(actor)
@@ -20,7 +20,7 @@ module Celluloid
20
20
  end
21
21
 
22
22
  def inspect
23
- Actor.call @mailbox, :inspect
23
+ Actor.call(@mailbox, :inspect).sub(::Celluloid::BARE_OBJECT_WARNING_MESSAGE, "Celluloid::Actor")
24
24
  rescue DeadActorError
25
25
  "#<Celluloid::Actor(#{@klass}) dead>"
26
26
  end
@@ -1,4 +1,4 @@
1
1
  module Celluloid
2
- VERSION = '0.12.0'
2
+ VERSION = '0.12.1.pre'
3
3
  def self.version; VERSION; end
4
4
  end
@@ -207,6 +207,13 @@ shared_context "a Celluloid Actor" do |included_module|
207
207
  actor.wrapped_object.should be_a actor_class
208
208
  end
209
209
 
210
+ it "warns about leaked wrapped objects via #inspect" do
211
+ actor = actor_class.new "Troy McClure"
212
+
213
+ actor.inspect.should_not include Celluloid::BARE_OBJECT_WARNING_MESSAGE
214
+ actor.wrapped_object.inspect.should include Celluloid::BARE_OBJECT_WARNING_MESSAGE
215
+ end
216
+
210
217
  describe 'mocking methods' do
211
218
  let(:actor) { actor_class.new "Troy McClure" }
212
219
 
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
5
- prerelease:
4
+ version: 0.12.1.pre
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tony Arcieri
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-04 00:00:00.000000000 Z
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: timers
16
- requirement: &70127789999080 !ruby/object:Gem::Requirement
16
+ requirement: &70119222902540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70127789999080
24
+ version_requirements: *70119222902540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70127789997960 !ruby/object:Gem::Requirement
27
+ requirement: &70119222902160 !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: *70127789997960
35
+ version_requirements: *70119222902160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70127789997400 !ruby/object:Gem::Requirement
38
+ requirement: &70119222901700 !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: *70127789997400
46
+ version_requirements: *70119222901700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: benchmark_suite
49
- requirement: &70127789996720 !ruby/object:Gem::Requirement
49
+ requirement: &70119222901280 !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: *70127789996720
57
+ version_requirements: *70119222901280
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: