Class: Celluloid::Proxy::Sync

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

Overview

A proxy which sends synchronous calls to an actor

Direct Known Subclasses

Cell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, klass) ⇒ Sync

Returns a new instance of Sync.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/celluloid/proxy/sync.rb', line 23

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

  if @mailbox == ::Thread.current[:celluloid_mailbox]
    args.unshift meth
    meth = :__send__
    # actor = Thread.current[:celluloid_actor]
    # actor = actor.behavior.subject.bare_object
    # return actor.__send__(*args, &block)
  end

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

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox.



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

def mailbox
  @mailbox
end

Instance Method Details

#__class__Object

Used for reflecting on proxy objects themselves



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

def __class__
  ::Celluloid::Proxy::Sync
end

#inspectObject



15
16
17
# File 'lib/celluloid/proxy/sync.rb', line 15

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

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

Returns:

  • (Boolean)


19
20
21
# File 'lib/celluloid/proxy/sync.rb', line 19

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