Class: Dramatis::Actor::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/dramatis/actor/interface.rb

Overview

This object should only be accessed from the actor it represents.

Instance Method Summary collapse

Instance Method Details

#accept(*args) ⇒ Object

call-seq:

accept pattern_args -> nil

Enables the actor to run tasks that match pattern_args. Note that subsequent gate calls may override this behavior.



47
48
49
# File 'lib/dramatis/actor/interface.rb', line 47

def accept *args
  @actor.gate.accept( :object, *args )
end

#always(args, value) ⇒ Object

call-seq:

always( pattern_args, value ) -> nil

Causes tasks matching pattern_args to always be accepted if value is true or reject if value is false. always takes precendence over refuse/accept so a task that matches both a refuse pattern and an always( …, true ) pattern will be allowed. always also overrides the implict gating in rpc method calls.



71
72
73
# File 'lib/dramatis/actor/interface.rb', line 71

def always args, value
  @actor.gate.always( ( [ :object ] + Array( args ) ), value )
end

#default(*args) ⇒ Object

call-seq:

default pattern_args -> nil

Reverts the behavior of the actor to tasks matching pattern_args to the default. It un-does the affect of a call to refuse or accept with the same arguments.



58
59
60
# File 'lib/dramatis/actor/interface.rb', line 58

def default *args
  @actor.gate.default( [ :object ] + args )
end

#enable_call_threadingObject

call-seq: enable_call_threading -> nil

Enables call threading for actor method calls made by this actor. When call threading is enabled, method gating is modified such that recursive and co-recursive calls are allowed. Normally blocking calls made by an actor on itself, e.g.,

actor.name.some_method

would cause a deadlock. When call threading is enabled, recursion, both self-recursion and co-recursion (actor A does an rpc on actor B which does an rpc on actor A), is allowed.



86
87
88
89
# File 'lib/dramatis/actor/interface.rb', line 86

def enable_call_threading
  @actor.enable_call_threading
  nil
end

#nameObject

call-seq:

name -> actor_name_of_actor

Returns the actor name for the object.



96
97
98
# File 'lib/dramatis/actor/interface.rb', line 96

def name
  @actor.name
end

#refuse(*args) ⇒ Object

call-seq:

refuse pattern_args -> nil

Blocks the actor from running any tasks that match pattern_args. Note that subsequent gate calls may override this behavior.



37
38
39
# File 'lib/dramatis/actor/interface.rb', line 37

def refuse *args
  @actor.gate.refuse( :object, *args )
end

#timeout(value, *args) ⇒ Object

:nodoc: not ready



115
116
117
# File 'lib/dramatis/actor/interface.rb', line 115

def timeout value, *args #:nodoc: not ready
  @actor.timeout value, *args
end

#yieldObject

call-seq:

yield -> nil

Yields the actor to allow other tasks to be executed. Currently, messages are handled FIFO so the yield will return when all the messages received up to the point of the yield are executed. This could be modified if non-FIFO queue processing is added



109
110
111
112
113
# File 'lib/dramatis/actor/interface.rb', line 109

def yield
  @actor.actor_send [ :yield ], :continuation => :rpc,
                                :nonblocking => true
  nil
end