Class: Api::HandlerBase
Direct Known Subclasses
Instance Attribute Summary collapse
-
#handle_duration_max ⇒ Object
readonly
Returns the value of attribute handle_duration_max.
-
#handle_duration_min ⇒ Object
readonly
Returns the value of attribute handle_duration_min.
-
#handle_duration_total ⇒ Object
readonly
Returns the value of attribute handle_duration_total.
-
#requests_count ⇒ Object
readonly
Properties.
Instance Method Summary collapse
- #before_handle ⇒ Object
- #handle_request(session, request) ⇒ Object
-
#initialize(options = nil) ⇒ HandlerBase
constructor
default constructor.
- #post_handle(handle_start_at) ⇒ Object
- #reset_handler_stats ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ HandlerBase
default constructor
18 19 20 21 22 23 24 |
# File 'lib/mrpin/api/base/handler_base.rb', line 18 def initialize( = nil) @stats_locker = Mutex.new reset_handler_stats @logger = AppInfo.instance.logger end |
Instance Attribute Details
#handle_duration_max ⇒ Object (readonly)
Returns the value of attribute handle_duration_max.
10 11 12 |
# File 'lib/mrpin/api/base/handler_base.rb', line 10 def handle_duration_max @handle_duration_max end |
#handle_duration_min ⇒ Object (readonly)
Returns the value of attribute handle_duration_min.
11 12 13 |
# File 'lib/mrpin/api/base/handler_base.rb', line 11 def handle_duration_min @handle_duration_min end |
#handle_duration_total ⇒ Object (readonly)
Returns the value of attribute handle_duration_total.
9 10 11 |
# File 'lib/mrpin/api/base/handler_base.rb', line 9 def handle_duration_total @handle_duration_total end |
#requests_count ⇒ Object (readonly)
Properties
8 9 10 |
# File 'lib/mrpin/api/base/handler_base.rb', line 8 def requests_count @requests_count end |
Instance Method Details
#before_handle ⇒ Object
27 28 |
# File 'lib/mrpin/api/base/handler_base.rb', line 27 def before_handle end |
#handle_request(session, request) ⇒ Object
31 32 |
# File 'lib/mrpin/api/base/handler_base.rb', line 31 def handle_request(session, request) end |
#post_handle(handle_start_at) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mrpin/api/base/handler_base.rb', line 35 def post_handle(handle_start_at) return if handle_start_at.nil? handle_duration = ((Time.now - handle_start_at).to_f * 1000).to_i @stats_locker.synchronize do @requests_count += 1 @handle_duration_total += handle_duration @handle_duration_min = [@handle_duration_min, handle_duration].min @handle_duration_max = [@handle_duration_max, handle_duration].max end end |
#reset_handler_stats ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/mrpin/api/base/handler_base.rb', line 50 def reset_handler_stats @stats_locker.synchronize do @requests_count = 0 @handle_duration_total = 0 @handle_duration_max = 0 @handle_duration_min = 2_147_483_647 end end |