celluloid 0.12.4.pre → 0.12.4.pre2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/celluloid.rb CHANGED
@@ -24,7 +24,7 @@ module Celluloid
24
24
 
25
25
  # Are we currently inside of an actor?
26
26
  def actor?
27
- !!Thread.current[:celluloid_actor]
27
+ !!Thread.current[:actor]
28
28
  end
29
29
 
30
30
  # Generate a Universally Unique Identifier
@@ -256,7 +256,7 @@ module Celluloid
256
256
 
257
257
  # Are we being invoked in a different thread from our owner?
258
258
  def leaked?
259
- @celluloid_owner != Thread.current[:celluloid_actor]
259
+ @celluloid_owner != Thread.current[:actor]
260
260
  end
261
261
 
262
262
  def inspect
@@ -288,7 +288,7 @@ module Celluloid
288
288
 
289
289
  call = AsyncCall.new(:__send__, args, block)
290
290
  begin
291
- Thread.current[:celluloid_actor].mailbox << call
291
+ Thread.current[:actor].mailbox << call
292
292
  rescue MailboxError
293
293
  # Silently swallow asynchronous calls to dead actors. There's no way
294
294
  # to reliably generate DeadActorErrors for async calls, so users of
@@ -320,17 +320,17 @@ module Celluloid
320
320
 
321
321
  # Terminate this actor
322
322
  def terminate
323
- Thread.current[:celluloid_actor].terminate
323
+ Thread.current[:actor].terminate
324
324
  end
325
325
 
326
326
  # Send a signal with the given name to all waiting methods
327
327
  def signal(name, value = nil)
328
- Thread.current[:celluloid_actor].signal name, value
328
+ Thread.current[:actor].signal name, value
329
329
  end
330
330
 
331
331
  # Wait for the given signal
332
332
  def wait(name)
333
- Thread.current[:celluloid_actor].wait name
333
+ Thread.current[:actor].wait name
334
334
  end
335
335
 
336
336
  # Obtain the current_actor
@@ -345,12 +345,12 @@ module Celluloid
345
345
 
346
346
  # Obtain the running tasks for this actor
347
347
  def tasks
348
- Thread.current[:celluloid_actor].tasks.to_a
348
+ Thread.current[:actor].tasks.to_a
349
349
  end
350
350
 
351
351
  # Obtain the Celluloid::Links for this actor
352
352
  def links
353
- Thread.current[:celluloid_actor].links
353
+ Thread.current[:actor].links
354
354
  end
355
355
 
356
356
  # Watch for exit events from another actor
@@ -385,7 +385,7 @@ module Celluloid
385
385
 
386
386
  # Receive an asynchronous message via the actor protocol
387
387
  def receive(timeout = nil, &block)
388
- actor = Thread.current[:celluloid_actor]
388
+ actor = Thread.current[:actor]
389
389
  if actor
390
390
  actor.receive(timeout, &block)
391
391
  else
@@ -395,7 +395,7 @@ module Celluloid
395
395
 
396
396
  # Sleep letting the actor continue processing messages
397
397
  def sleep(interval)
398
- actor = Thread.current[:celluloid_actor]
398
+ actor = Thread.current[:actor]
399
399
  if actor
400
400
  actor.sleep(interval)
401
401
  else
@@ -406,23 +406,23 @@ module Celluloid
406
406
  # Run given block in an exclusive mode: all synchronous calls block the whole
407
407
  # actor, not only current message processing.
408
408
  def exclusive(&block)
409
- Thread.current[:celluloid_actor].exclusive(&block)
409
+ Thread.current[:actor].exclusive(&block)
410
410
  end
411
411
 
412
412
  # Are we currently exclusive
413
413
  def exclusive?
414
- actor = Thread.current[:celluloid_actor]
414
+ actor = Thread.current[:actor]
415
415
  actor && actor.exclusive?
416
416
  end
417
417
 
418
418
  # Call a block after a given interval, returning a Celluloid::Timer object
419
419
  def after(interval, &block)
420
- Thread.current[:celluloid_actor].after(interval, &block)
420
+ Thread.current[:actor].after(interval, &block)
421
421
  end
422
422
 
423
423
  # Call a block every given interval, returning a Celluloid::Timer object
424
424
  def every(interval, &block)
425
- Thread.current[:celluloid_actor].every(interval, &block)
425
+ Thread.current[:actor].every(interval, &block)
426
426
  end
427
427
 
428
428
  # Perform a blocking or computationally intensive action inside an
@@ -437,18 +437,18 @@ module Celluloid
437
437
  # Handle async calls within an actor itself
438
438
  def async(meth = nil, *args, &block)
439
439
  if meth
440
- Actor.async Thread.current[:celluloid_actor].mailbox, meth, *args, &block
440
+ Actor.async Thread.current[:actor].mailbox, meth, *args, &block
441
441
  else
442
- Thread.current[:celluloid_actor].proxy.async
442
+ Thread.current[:actor].proxy.async
443
443
  end
444
444
  end
445
445
 
446
446
  # Handle calls to future within an actor itself
447
447
  def future(meth = nil, *args, &block)
448
448
  if meth
449
- Actor.future Thread.current[:celluloid_actor].mailbox, meth, *args, &block
449
+ Actor.future Thread.current[:actor].mailbox, meth, *args, &block
450
450
  else
451
- Thread.current[:celluloid_actor].proxy.future
451
+ Thread.current[:actor].proxy.future
452
452
  end
453
453
  end
454
454
  end
@@ -44,14 +44,14 @@ module Celluloid
44
44
 
45
45
  # Obtain the current actor
46
46
  def current
47
- actor = Thread.current[:celluloid_actor]
47
+ actor = Thread.current[:actor]
48
48
  raise NotActorError, "not in actor scope" unless actor
49
49
  actor.proxy
50
50
  end
51
51
 
52
52
  # Obtain the name of the current actor
53
53
  def name
54
- actor = Thread.current[:celluloid_actor]
54
+ actor = Thread.current[:actor]
55
55
  raise NotActorError, "not in actor scope" unless actor
56
56
  actor.name
57
57
  end
@@ -66,7 +66,7 @@ module Celluloid
66
66
  raise DeadActorError, "attempted to call a dead actor"
67
67
  end
68
68
 
69
- if Thread.current[:celluloid_task] && !Celluloid.exclusive?
69
+ if Thread.current[:task] && !Celluloid.exclusive?
70
70
  Task.suspend(:callwait).value
71
71
  else
72
72
  response = loop do
@@ -74,7 +74,7 @@ module Celluloid
74
74
  msg.respond_to?(:call) and msg.call == call
75
75
  end
76
76
  break message unless message.is_a?(SystemEvent)
77
- Thread.current[:celluloid_actor].handle_system_event(message)
77
+ Thread.current[:actor].handle_system_event(message)
78
78
  end
79
79
 
80
80
  response.value
@@ -104,7 +104,7 @@ module Celluloid
104
104
  def all
105
105
  actors = []
106
106
  Thread.list.each do |t|
107
- actor = t[:celluloid_actor]
107
+ actor = t[:actor]
108
108
  actors << actor.proxy if actor and actor.respond_to?(:proxy)
109
109
  end
110
110
  actors
@@ -113,25 +113,25 @@ module Celluloid
113
113
  # Watch for exit events from another actor
114
114
  def monitor(actor)
115
115
  raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
116
- Thread.current[:celluloid_actor].linking_request(actor, :link)
116
+ Thread.current[:actor].linking_request(actor, :link)
117
117
  end
118
118
 
119
119
  # Stop waiting for exit events from another actor
120
120
  def unmonitor(actor)
121
121
  raise NotActorError, "can't link outside actor context" unless Celluloid.actor?
122
- Thread.current[:celluloid_actor].linking_request(actor, :unlink)
122
+ Thread.current[:actor].linking_request(actor, :unlink)
123
123
  end
124
124
 
125
125
  # Link to another actor
126
126
  def link(actor)
127
127
  monitor actor
128
- Thread.current[:celluloid_actor].links << actor
128
+ Thread.current[:actor].links << actor
129
129
  end
130
130
 
131
131
  # Unlink from another actor
132
132
  def unlink(actor)
133
133
  unmonitor actor
134
- Thread.current[:celluloid_actor].links.delete actor
134
+ Thread.current[:actor].links.delete actor
135
135
  end
136
136
 
137
137
  # Are we monitoring the given actor?
@@ -141,7 +141,7 @@ module Celluloid
141
141
 
142
142
  # Are we bidirectionally linked to the given actor?
143
143
  def linked_to?(actor)
144
- monitoring?(actor) && Thread.current[:celluloid_actor].links.include?(actor)
144
+ monitoring?(actor) && Thread.current[:actor].links.include?(actor)
145
145
  end
146
146
 
147
147
  # Forcibly kill a given actor
@@ -179,8 +179,8 @@ module Celluloid
179
179
  @name = nil
180
180
 
181
181
  @thread = ThreadHandle.new do
182
- Thread.current[:celluloid_actor] = self
183
- Thread.current[:celluloid_mailbox] = @mailbox
182
+ Thread.current[:actor] = self
183
+ Thread.current[:mailbox] = @mailbox
184
184
  run
185
185
  end
186
186
 
@@ -309,7 +309,7 @@ module Celluloid
309
309
 
310
310
  # Sleep for the given amount of time
311
311
  def sleep(interval)
312
- task = Thread.current[:celluloid_task]
312
+ task = Thread.current[:task]
313
313
  if task && !Celluloid.exclusive?
314
314
  @timers.after(interval) { task.resume }
315
315
  Task.suspend :sleeping
@@ -372,8 +372,8 @@ module Celluloid
372
372
  run_finalizer
373
373
  cleanup exit_event
374
374
  ensure
375
- Thread.current[:celluloid_actor] = nil
376
- Thread.current[:celluloid_mailbox] = nil
375
+ Thread.current[:actor] = nil
376
+ Thread.current[:mailbox] = nil
377
377
  end
378
378
 
379
379
  # Run the user-defined finalizer, if one is set
@@ -13,7 +13,7 @@ module Celluloid
13
13
  class SyncCall < Call
14
14
  attr_reader :caller, :task
15
15
 
16
- def initialize(caller, method, arguments = [], block = nil, task = Thread.current[:celluloid_task])
16
+ def initialize(caller, method, arguments = [], block = nil, task = Thread.current[:task])
17
17
  super(method, arguments, block)
18
18
  @caller = caller
19
19
  @task = task
@@ -6,7 +6,7 @@ class Thread
6
6
 
7
7
  # Retrieve the mailbox for the current thread or lazily initialize it
8
8
  def self.mailbox
9
- current[:celluloid_mailbox] ||= Celluloid::Mailbox.new
9
+ current[:mailbox] ||= Celluloid::Mailbox.new
10
10
  end
11
11
 
12
12
  # Receive a message either as an actor or through the local mailbox
@@ -23,7 +23,7 @@ module Celluloid
23
23
  end
24
24
  end until thread.status # handle crashed threads
25
25
 
26
- thread[:celluloid_queue] << block
26
+ thread[:queue] << block
27
27
  thread
28
28
  end
29
29
  end
@@ -32,7 +32,7 @@ module Celluloid
32
32
  def put(thread)
33
33
  @mutex.synchronize do
34
34
  if @pool.size >= @max_idle
35
- thread[:celluloid_queue] << nil
35
+ thread[:queue] << nil
36
36
  else
37
37
  @pool << thread
38
38
  end
@@ -54,7 +54,7 @@ module Celluloid
54
54
  end
55
55
  end
56
56
 
57
- thread[:celluloid_queue] = queue
57
+ thread[:queue] = queue
58
58
  thread
59
59
  end
60
60
  end
@@ -93,7 +93,7 @@ module Celluloid
93
93
  while @idle.empty?
94
94
  # Wait for responses from one of the busy workers
95
95
  response = exclusive { receive { |msg| msg.is_a?(Response) } }
96
- Thread.current[:celluloid_actor].handle_message(response)
96
+ Thread.current[:actor].handle_message(response)
97
97
  end
98
98
 
99
99
  worker = @idle.shift
@@ -14,7 +14,7 @@ module Celluloid
14
14
 
15
15
  # Obtain the current task
16
16
  def self.current
17
- Thread.current[:celluloid_task] or raise NotTaskError, "not within a task context"
17
+ Thread.current[:task] or raise NotTaskError, "not within a task context"
18
18
  end
19
19
 
20
20
  # Suspend the running task, deferring to the scheduler
@@ -10,14 +10,14 @@ module Celluloid
10
10
  @type = type
11
11
  @status = :new
12
12
 
13
- actor, mailbox = Thread.current[:celluloid_actor], Thread.current[:celluloid_mailbox]
13
+ actor, mailbox = Thread.current[:actor], Thread.current[:mailbox]
14
14
  raise NotActorError, "can't create tasks outside of actors" unless actor
15
15
 
16
16
  @fiber = Fiber.new do
17
17
  @status = :running
18
- Thread.current[:celluloid_actor] = actor
19
- Thread.current[:celluloid_mailbox] = mailbox
20
- Thread.current[:celluloid_task] = self
18
+ Thread.current[:actor] = actor
19
+ Thread.current[:mailbox] = mailbox
20
+ Thread.current[:task] = self
21
21
  actor.tasks << self
22
22
 
23
23
  begin
@@ -12,16 +12,16 @@ module Celluloid
12
12
  @yield_mutex = Mutex.new
13
13
  @yield_cond = ConditionVariable.new
14
14
 
15
- actor, mailbox = Thread.current[:celluloid_actor], Thread.current[:celluloid_mailbox]
15
+ actor, mailbox = Thread.current[:actor], Thread.current[:mailbox]
16
16
  raise NotActorError, "can't create tasks outside of actors" unless actor
17
17
 
18
18
  @thread = InternalPool.get do
19
19
  begin
20
20
  unless @resume_queue.pop.is_a?(Task::TerminatedError)
21
21
  @status = :running
22
- Thread.current[:celluloid_actor] = actor
23
- Thread.current[:celluloid_mailbox] = mailbox
24
- Thread.current[:celluloid_task] = self
22
+ Thread.current[:actor] = actor
23
+ Thread.current[:mailbox] = mailbox
24
+ Thread.current[:task] = self
25
25
  actor.tasks << self
26
26
 
27
27
  yield
@@ -1,4 +1,4 @@
1
1
  module Celluloid
2
- VERSION = '0.12.4.pre'
2
+ VERSION = '0.12.4.pre2'
3
3
  def self.version; VERSION; end
4
4
  end
@@ -14,11 +14,11 @@ shared_context "a Celluloid Task" do |task_class|
14
14
  subject { task_class.new(task_type) { Celluloid::Task.suspend(suspend_state) } }
15
15
 
16
16
  before :each do
17
- Thread.current[:celluloid_actor] = actor
17
+ Thread.current[:actor] = actor
18
18
  end
19
19
 
20
20
  after :each do
21
- Thread.current[:celluloid_actor] = nil
21
+ Thread.current[:actor] = nil
22
22
  end
23
23
 
24
24
  it "begins with status :new" do
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.12.4.pre
4
+ version: 0.12.4.pre2
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors: