Module: RightScale::Actor::ClassMethods

Defined in:
lib/right_agent/actor.rb

Instance Method Summary collapse

Instance Method Details

#default_prefixObject

Construct default prefix by which actor is identified in requests

Return

prefix(String)

Default prefix



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

def default_prefix
  prefix = to_s.to_const_path
end

#exception_callbackObject

Get exception callback procedure

Return

@exception_callback(Proc)

Callback procedure



120
121
122
# File 'lib/right_agent/actor.rb', line 120

def exception_callback
  @exception_callback
end

#expose(*meths) ⇒ Object

Add methods to list of services supported by actor

Parameters

meths(Array)

Symbol names for methods being exposed as actor services

Return

@exposed(Array)

List of unique methods exposed



69
70
71
72
73
74
75
# File 'lib/right_agent/actor.rb', line 69

def expose(*meths)
  @exposed ||= []
  meths.each do |meth|
    @exposed << meth unless @exposed.include?(meth)
  end
  @exposed
end

#on_exception(proc = nil, &blk) ⇒ Object

Set method called when dispatching to this actor fails

The callback method is required to accept the following parameters:

method(Symbol):: Actor method being dispatched to
deliverable(Packet):: Packet delivered to dispatcher
exception(Exception):: Exception raised

Parameters

proc(Proc|Symbol|String)

Procedure to be called on exception

Block

Block to be executed if no Proc provided

Return

@exception_callback(Proc)

Callback procedure



111
112
113
114
# File 'lib/right_agent/actor.rb', line 111

def on_exception(proc = nil, &blk)
  raise 'No callback provided for on_exception' unless proc || blk
  @exception_callback = proc || blk
end

#provides_for(prefix) ⇒ Object

Get /prefix/method paths that actor responds to

Parameters

prefix(String)

Prefix by which actor is identified in requests

Return

(Array)

/prefix/method strings



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/right_agent/actor.rb', line 84

def provides_for(prefix)
  return [] unless @exposed
  @exposed.select do |meth|
    if instance_methods.include?(meth.to_s) or instance_methods.include?(meth.to_sym)
      true
    else
      Log.warning("Exposing non-existing method #{meth} in actor #{name}")
      false
    end
  end.map {|meth| "/#{prefix}/#{meth}".squeeze('/')}
end