Class: Nanite::Dispatcher
Instance Attribute Summary collapse
-
#amq ⇒ Object
readonly
Returns the value of attribute amq.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
- #dispatch(deliverable) ⇒ Object
-
#initialize(amq, registry, serializer, identity, log, options) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(amq, registry, serializer, identity, log, options) ⇒ Dispatcher
Returns a new instance of Dispatcher.
5 6 7 8 9 10 11 12 |
# File 'lib/nanite/dispatcher.rb', line 5 def initialize(amq, registry, serializer, identity, log, ) @amq = amq @registry = registry @serializer = serializer @identity = identity @log = log @options = end |
Instance Attribute Details
#amq ⇒ Object (readonly)
Returns the value of attribute amq.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def amq @amq end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def identity @identity end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def log @log end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def @options end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def registry @registry end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
3 4 5 |
# File 'lib/nanite/dispatcher.rb', line 3 def serializer @serializer end |
Instance Method Details
#dispatch(deliverable) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nanite/dispatcher.rb', line 14 def dispatch(deliverable) result = begin prefix, meth = deliverable.type.split('/')[1..-1] actor = registry.actor_for(prefix) actor.send(meth, deliverable.payload) rescue Exception => e handle_exception(actor, meth, deliverable, e) end if deliverable.kind_of?(Request) result = Result.new(deliverable.token, deliverable.reply_to, result, identity) amq.queue(deliverable.reply_to, :no_declare => [:secure]).publish(serializer.dump(result)) end result end |