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

Methods inherited from Abstract

#__class__

Constructor Details

#initialize(mailbox, thread) ⇒ Actor

Returns a new instance of Actor.



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

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

#alive?Boolean

Returns:

  • (Boolean)


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

def alive?
  @mailbox.alive?
end

#dead?Boolean

Returns:

  • (Boolean)


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

def dead?
  !alive?
end

#inspectObject



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

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



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

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

#terminate!Object

Terminate the associated actor asynchronously



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

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