Class: StompServer::QueueMonitor
- Inherits:
-
Object
- Object
- StompServer::QueueMonitor
- Defined in:
- lib/stomp_server_ng/qmonitor.rb
Overview
Queue Monitor
Instance Method Summary collapse
-
#initialize(qstore, queues) ⇒ QueueMonitor
constructor
Initialize the queue monitor.
-
#monitor(count) ⇒ Object
Respond to calls from the timer.
-
#start ⇒ Object
Start monitor timer.
Constructor Details
#initialize(qstore, queues) ⇒ QueueMonitor
Initialize the queue monitor.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stomp_server_ng/qmonitor.rb', line 12 def initialize(qstore,queues) @qstore = qstore @queues = queues @stompid = StompServer::StompId.new # @@log = Logger.new(STDOUT) @@log.level = StompServer::LogHelper.get_loglevel() @@log.debug("QueueMonitor initialize comletes") # end |
Instance Method Details
#monitor(count) ⇒ Object
Respond to calls from the timer. Do nothing if no clients are connected to the ‘/queue/monitor’ destination.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/stomp_server_ng/qmonitor.rb', line 33 def monitor(count) return unless (@qstore.methods.include?(:monitor) | @qstore.methods.include?('monitor')) users = @queues['/queue/monitor'] return if users.size == 0 stats = @qstore.monitor return if stats.size == 0 body = '' # stats.each do |queue,qstats| body << "Queue: #{queue}\n" qstats.each {|stat,value| body << "#{stat}: #{value}\n"} body << "\n" end # headers = { 'message-id' => @stompid[count], 'destination' => '/queue/monitor', 'content-length' => body.size.to_s } # frame = StompServer::StompFrame.new('MESSAGE', headers, body) users.each {|user| user.connection.stomp_send_data(frame)} end |
#start ⇒ Object
Start monitor timer.
25 26 27 28 |
# File 'lib/stomp_server_ng/qmonitor.rb', line 25 def start count =0 EventMachine::add_periodic_timer 5, proc {count+=1; monitor(count) } end |