Class: Pione::Agent::NotificationListener
- Inherits:
-
BasicAgent
- Object
- PioneObject
- BasicAgent
- Pione::Agent::NotificationListener
- Defined in:
- lib/pione/agent/notification-listener.rb
Instance Attribute Summary collapse
-
#notification_handlers ⇒ Object
readonly
notification handler threads.
Attributes inherited from BasicAgent
Instance Method Summary collapse
-
#initialize(model, uri) ⇒ NotificationListener
constructor
A new instance of NotificationListener.
-
#transit_to_init ⇒ Object
Initialize the agent.
-
#transit_to_receive ⇒ Object
Receive notification messages and make a message handler thread.
-
#transit_to_terminate ⇒ Object
Close receiver socket.
Methods inherited from BasicAgent
agent_type, inherited, set_agent_type, #start, #start!, #states, #terminate, #terminated?, #transit, #wait_until, #wait_until_after, #wait_until_before, #wait_until_terminated
Methods included from StateTransitionSingletonMethod
#chain, #define_exception_handler, #define_transition, #exception_handler, #start, #transition_chain
Constructor Details
#initialize(model, uri) ⇒ NotificationListener
Returns a new instance of NotificationListener.
15 16 17 18 19 20 21 |
# File 'lib/pione/agent/notification-listener.rb', line 15 def initialize(model, uri) super() @uri = uri @model = model @notification_handlers = ThreadGroup.new @lock = Mutex.new end |
Instance Attribute Details
#notification_handlers ⇒ Object (readonly)
notification handler threads
9 10 11 |
# File 'lib/pione/agent/notification-listener.rb', line 9 def notification_handlers @notification_handlers end |
Instance Method Details
#transit_to_init ⇒ Object
Initialize the agent.
37 38 39 40 |
# File 'lib/pione/agent/notification-listener.rb', line 37 def transit_to_init Log::SystemLog.info('Notification listener starts listening notification messages on "%s".' % @uri) @receiver = Notification::Receiver.new(@uri) end |
#transit_to_receive ⇒ Object
Receive notification messages and make a message handler thread.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pione/agent/notification-listener.rb', line 43 def transit_to_receive # receive a notification transmitter_host, = @receiver.receive # handle the notification in new thread thread = Util::FreeThreadGenerator.generate do handle_notification(transmitter_host, ) end @notification_handlers.add(thread) rescue StandardError => e Log::Debug.notification("Receiver agent has received bad data from %s, so it ignored and reopen socket." % ip_address) @receiver.reopen end |
#transit_to_terminate ⇒ Object
Close receiver socket.
58 59 60 61 62 63 |
# File 'lib/pione/agent/notification-listener.rb', line 58 def transit_to_terminate # kill threads of notification handler @notification_handlers.list.each {|thread| thread.kill.join} # close socket @receiver.close unless @receiver.closed? end |