Class: NewRelic::Agent::EventListener
- Inherits:
-
Object
- Object
- NewRelic::Agent::EventListener
- Defined in:
- lib/new_relic/agent/event_listener.rb
Overview
Basic mechanism for the agent instance to provide agent-wide eventing. It is intended to keep different pieces of the app decoupled from each other.
While an EventListener could be used elsewhere, it’s strongly expected your eventing needs should be met by the agent’s instance.
Instance Attribute Summary collapse
-
#runaway_threshold ⇒ Object
Returns the value of attribute runaway_threshold.
Instance Method Summary collapse
- #check_for_runaway_subscriptions(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.
14 15 16 17 |
# File 'lib/new_relic/agent/event_listener.rb', line 14 def initialize @events = {} @runaway_threshold = 100 end |
Instance Attribute Details
#runaway_threshold ⇒ Object
Returns the value of attribute runaway_threshold.
12 13 14 |
# File 'lib/new_relic/agent/event_listener.rb', line 12 def runaway_threshold @runaway_threshold end |
Instance Method Details
#check_for_runaway_subscriptions(event) ⇒ Object
25 26 27 28 |
# File 'lib/new_relic/agent/event_listener.rb', line 25 def check_for_runaway_subscriptions(event) count = @events[event].size NewRelic::Agent.logger.debug("Run-away event subscription on #{event}? Subscribed #{count}") if count > @runaway_threshold end |
#clear ⇒ Object
30 31 32 |
# File 'lib/new_relic/agent/event_listener.rb', line 30 def clear @events.clear end |
#notify(event, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/new_relic/agent/event_listener.rb', line 34 def notify(event, *args) return unless @events.has_key?(event) @events[event].each do |handler| begin handler.call(*args) rescue => err NewRelic::Agent.logger.debug("Failure during notify for #{event}", err) end end end |
#subscribe(event, &handler) ⇒ Object
19 20 21 22 23 |
# File 'lib/new_relic/agent/event_listener.rb', line 19 def subscribe(event, &handler) @events[event] ||= [] @events[event] << handler check_for_runaway_subscriptions(event) end |