Class: Celluloid::SyncProxy

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

Overview

A proxy which sends synchronous calls to an actor

Direct Known Subclasses

CellProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, klass) ⇒ SyncProxy

Returns a new instance of SyncProxy.


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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/celluloid/proxies/sync_proxy.rb', line 21

def method_missing(meth, *args, &block)
  unless @mailbox.alive?
    raise DeadActorError, "attempted to call a dead actor"
  end

  if @mailbox == ::Thread.current[:celluloid_mailbox]
    args.unshift meth
    meth = :__send__
  end

  call = SyncCall.new(::Celluloid.mailbox, meth, args, block)
  @mailbox << call
  call.value
end

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox


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

def mailbox
  @mailbox
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves


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

def __class__; SyncProxy; end

#inspectObject


13
14
15
# File 'lib/celluloid/proxies/sync_proxy.rb', line 13

def inspect
  "#<Celluloid::SyncProxy(#{@klass})>"
end

#respond_to?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/celluloid/proxies/sync_proxy.rb', line 17

def respond_to?(meth, include_private = false)
  __class__.instance_methods.include?(meth) || method_missing(:respond_to?, meth, include_private)
end