Class: TingYun::Agent::Event::EventListener
- Inherits:
-
Object
- Object
- TingYun::Agent::Event::EventListener
- Defined in:
- lib/ting_yun/agent/event/event_listener.rb
Instance Attribute Summary collapse
-
#allocation ⇒ Object
Returns the value of attribute allocation.
Instance Method Summary collapse
- #check_allocation(event) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ EventListener
constructor
A new instance of EventListener.
- #notify(event, *args) ⇒ Object
- #subscribe(event, &handler) ⇒ Object
Constructor Details
#initialize ⇒ EventListener
Returns a new instance of EventListener.
10 11 12 13 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 10 def initialize @events = {} @allocation = 100 end |
Instance Attribute Details
#allocation ⇒ Object
Returns the value of attribute allocation.
8 9 10 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 8 def allocation @allocation end |
Instance Method Details
#check_allocation(event) ⇒ Object
21 22 23 24 25 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 21 def check_allocation(event) if @events[event].size > @allocation TingYun::Agent.logger.debug("Run-away event subscription on #{event}? Subscribed #{count}") end end |
#clear ⇒ Object
27 28 29 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 27 def clear @events.clear end |
#notify(event, *args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 32 def notify(event, *args) return unless @events.has_key?(event) @events[event].each do |handler| begin handler.call(*args) rescue => err TingYun::Agent.logger.debug("Failure during notify for #{event}", err) end end end |
#subscribe(event, &handler) ⇒ Object
15 16 17 18 19 |
# File 'lib/ting_yun/agent/event/event_listener.rb', line 15 def subscribe(event, &handler) @events[event] ||= [] @events[event] << handler check_allocation(event) end |