Class: StompMessage::StompStatisticsServer
- Inherits:
-
StompServer
- Object
- StompServer
- StompMessage::StompStatisticsServer
- Defined in:
- lib/stomp_message/stomp_statistics_server.rb
Overview
statistics listening class. Updates the statistics at every message/event
Instance Attribute Summary collapse
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#tags ⇒ Object
Returns the value of attribute tags.
Attributes inherited from StompServer
#conn, #exception_count, #host, #login, #msg_count, #mythreads, #password, #port, #queue, #thread_count, #topic
Instance Method Summary collapse
- #handle_message(msg) ⇒ Object
-
#increment_stats(tag, element) ⇒ Object
update the statistics by tag value (eg hour).
-
#initialize(options = {}) ⇒ StompStatisticsServer
constructor
A new instance of StompStatisticsServer.
-
#reset_element(tag, element) ⇒ Object
reset element to zero (eg reset hour to zero).
- #setup_var ⇒ Object
- #stomp_PING(msg, stomp_msg) ⇒ Object
-
#stomp_REPORT(msg, stomp_msg) ⇒ Object
} }.
- #stomp_RESET(msg, stomp_msg) ⇒ Object
-
#tag_increment(element) ⇒ Object
increment all the tags with a new element value .
Methods inherited from StompServer
#close_topic, #connect_connection, #connect_topic, #disconnect_stomp, #method_missing, #monitor_queue_status, #run, #send_reply, #setup_auto_close, #stomp_DEBUG
Constructor Details
#initialize(options = {}) ⇒ StompStatisticsServer
Returns a new instance of StompStatisticsServer.
14 15 16 17 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 14 def initialize(={}) super() setup_var end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class StompMessage::StompServer
Instance Attribute Details
#statistics ⇒ Object
Returns the value of attribute statistics.
7 8 9 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 7 def statistics @statistics end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 7 def end |
Instance Method Details
#handle_message(msg) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 33 def (msg) puts "in handle message stomp stat server" if @debug m=StompMessage::Message.load_xml(msg.body) tag_increment(m.command) super(msg) tag_increment('msg_count') tag_increment('exception_count') if @old_exception_count!= self.exception_count @old_exception_count= self.exception_count end |
#increment_stats(tag, element) ⇒ Object
update the statistics by tag value (eg hour)
19 20 21 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 19 def increment_stats(tag, element) self.statistics[tag][element]+=1 end |
#reset_element(tag, element) ⇒ Object
reset element to zero (eg reset hour to zero)
23 24 25 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 23 def reset_element(tag, element) self.statistics[tag][element]=0 end |
#setup_var ⇒ Object
8 9 10 11 12 13 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 8 def setup_var self. = %w(hour day week month) self.statistics = Hash.new self..each { |tagv| statistics[tagv] = Hash.new(0) } @old_exception_count=0 end |
#stomp_PING(msg, stomp_msg) ⇒ Object
43 44 45 46 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 43 def stomp_PING(msg, stomp_msg) puts "stomp PING: #{msg.body}" if @debug #do not reply as statistic servers do no respond to pings. they respond to stomp_REPORT end |
#stomp_REPORT(msg, stomp_msg) ⇒ Object
}
}
end
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 59 def stomp_REPORT(msg, stomp_msg) result= " Stomp Report #{Time.now}\n" result << " Messages processed: #{self.msg_count} \n" flag = self.exception_count!=nil ? '' : 'IMPORTANT' result << "#{flag} Exceptions processed: #{self.exception_count}\n " self..each { |tagv| # run through each tag (hour, day etc) result << "#{tagv} Latests Statistics\n" self.statistics[tagv].each {|k,v| result << " ----- #{k}: #{v}\n"} } puts result if @debug reply_msg = StompMessage::Message.new('stomp_REPLY', "#{result}") send_reply(stomp_msg.headers,reply_msg) if stomp_msg.headers['reply-to']!=nil result end |
#stomp_RESET(msg, stomp_msg) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 74 def stomp_RESET(msg, stomp_msg) puts "stomp reset: #{msg.body}" if @debug reset_tag = msg.body.to_s if self..include?(msg.body.to_s) puts " --- RESET TAG: #{reset_tag}" self.statistics[reset_tag].each { |k,v| self.statistics[reset_tag][k]=0 puts "RESET: tag #{k} value is zero" } if self..include?(msg.body.to_s) end |
#tag_increment(element) ⇒ Object
increment all the tags with a new element value . Hash is zero if not found
27 28 29 30 31 |
# File 'lib/stomp_message/stomp_statistics_server.rb', line 27 def tag_increment(element) self..each {|tagv| puts "incrementing #{tagv} element: #{element}" if @debug increment_stats(tagv,element)} end |