Class: Celluloid::ActorProxy

Inherits:
AbstractProxy show all
Defined in:
lib/celluloid/proxies/actor_proxy.rb

Overview

A proxy which controls the Actor lifecycle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread, mailbox) ⇒ ActorProxy

Returns a new instance of ActorProxy.


9
10
11
12
# File 'lib/celluloid/proxies/actor_proxy.rb', line 9

def initialize(thread, mailbox)
  @thread = thread
  @mailbox = mailbox
end

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox


4
5
6
# File 'lib/celluloid/proxies/actor_proxy.rb', line 4

def mailbox
  @mailbox
end

#threadObject (readonly)

Returns the value of attribute thread


4
5
6
# File 'lib/celluloid/proxies/actor_proxy.rb', line 4

def thread
  @thread
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves


7
# File 'lib/celluloid/proxies/actor_proxy.rb', line 7

def __class__; ActorProxy; end

#alive?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/celluloid/proxies/actor_proxy.rb', line 21

def alive?
  @mailbox.alive?
end

#inspectObject


14
15
16
17
18
19
# File 'lib/celluloid/proxies/actor_proxy.rb', line 14

def inspect  # TODO: use a system event to fetch actor state: tasks?

  "#<Celluloid::ActorProxy(#{@mailbox.address}) alive>"
rescue DeadActorError
  "#<Celluloid::ActorProxy(#{@mailbox.address}) dead>"
end

#terminateObject

Terminate the associated actor


26
27
28
29
30
# File 'lib/celluloid/proxies/actor_proxy.rb', line 26

def terminate
  terminate!
  Actor.join(self)
  nil
end

#terminate!Object

Terminate the associated actor asynchronously


33
34
35
36
# File 'lib/celluloid/proxies/actor_proxy.rb', line 33

def terminate!
  ::Kernel.raise DeadActorError, "actor already terminated" unless alive?
  @mailbox << TerminationRequest.new
end