Class: Pione::Notification::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/notification/recipient.rb

Overview

Recipient is a wrapper for notification recipients. This wraps a command and notifies messages to it when a notification listener receives notifications. Recipients should be registerd to listner periodically because the listener forgets recipients after some minites. Note that Recipient instance is registered to a listener after it is created immediately, so the listener is launched up to that time.

Direct Known Subclasses

TaskWorkerBrokerRecipient

Instance Method Summary collapse

Constructor Details

#initialize(front_uri, listener_uri) ⇒ Recipient

Returns a new instance of Recipient.

Parameters:

  • front_uri (URI)

    URI of command front that receives messages

  • listener_uri (URI)

    URI of notification listener



14
15
16
17
18
19
# File 'lib/pione/notification/recipient.rb', line 14

def initialize(front_uri, listener_uri)
  @listener_uri = listener_uri
  @front_uri = front_uri
  @__listener_thread__ = keep_connection
  @__connection__ = false
end

Instance Method Details

#notify(message) ⇒ Object

Notify the message. This is a non-blocking method.



22
23
24
25
26
27
# File 'lib/pione/notification/recipient.rb', line 22

def notify(message)
  name = ("receive_%s" % message.type).downcase
  if respond_to?(name)
    __send__(name, message)
  end
end

#terminateObject



29
30
31
32
# File 'lib/pione/notification/recipient.rb', line 29

def terminate
  @__listerner_thread__.terminate if @__listener_thread__.alive?
  disconnect
end