Class: Celluloid::Proxy::Actor

Inherits:
Abstract
  • Object
show all
Defined in:
lib/celluloid/proxy/actor.rb

Overview

A proxy which controls the Actor lifecycle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, thread) ⇒ Actor

Returns a new instance of Actor.



10
11
12
13
# File 'lib/celluloid/proxy/actor.rb', line 10

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

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox.



3
4
5
# File 'lib/celluloid/proxy/actor.rb', line 3

def mailbox
  @mailbox
end

#threadObject (readonly)

Returns the value of attribute thread.



3
4
5
# File 'lib/celluloid/proxy/actor.rb', line 3

def thread
  @thread
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves



6
7
8
# File 'lib/celluloid/proxy/actor.rb', line 6

def __class__
  ::Celluloid::Proxy::Actor
end

#alive?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/celluloid/proxy/actor.rb', line 22

def alive?
  @mailbox.alive?
end

#dead?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/celluloid/proxy/actor.rb', line 26

def dead?
  !alive?
end

#inspectObject



15
16
17
18
19
20
# File 'lib/celluloid/proxy/actor.rb', line 15

def inspect
  # TODO: use a system event to fetch actor state: tasks?
  "#<Celluloid::Proxy::Actor(#{@mailbox.address}) alive>"
rescue DeadActorError
  "#<Celluloid::Proxy::Actor(#{@mailbox.address}) dead>"
end

#terminateObject

Terminate the associated actor



31
32
33
34
35
# File 'lib/celluloid/proxy/actor.rb', line 31

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

#terminate!Object

Terminate the associated actor asynchronously



38
39
40
41
# File 'lib/celluloid/proxy/actor.rb', line 38

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