Class: Nanite::Dispatcher

Inherits:
Object show all
Defined in:
lib/nanite/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @amq = amq
  @registry = registry
  @serializer = serializer
  @identity = identity
  @log = log
  @options = options
end

Instance Attribute Details

#amqObject (readonly)

Returns the value of attribute amq.



3
4
5
# File 'lib/nanite/dispatcher.rb', line 3

def amq
  @amq
end

#identityObject (readonly)

Returns the value of attribute identity.



3
4
5
# File 'lib/nanite/dispatcher.rb', line 3

def identity
  @identity
end

#logObject (readonly)

Returns the value of attribute log.



3
4
5
# File 'lib/nanite/dispatcher.rb', line 3

def log
  @log
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/nanite/dispatcher.rb', line 3

def options
  @options
end

#registryObject (readonly)

Returns the value of attribute registry.



3
4
5
# File 'lib/nanite/dispatcher.rb', line 3

def registry
  @registry
end

#serializerObject (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 => options[:secure]).publish(serializer.dump(result))
  end

  result
end