Sha256: c428b7d5b60ea7009b3e92d09d7028b92c404ef483cde0add1d6e28415ad6ab0

Contents?: true

Size: 887 Bytes

Versions: 3

Compression:

Stored size: 887 Bytes

Contents

# encoding: utf-8

module OneApm::Agent
  class EventListener

    attr_accessor :runaway_threshold

    def initialize
      @events = {}
      @runaway_threshold = 100
    end

    def subscribe(event, &handler)
      @events[event] ||= []
      @events[event] << handler
      check_for_runaway_subscriptions(event)
    end

    def check_for_runaway_subscriptions(event)
      count = @events[event].size
      OneApm::Agent.logger.debug("Run-away event subscription on #{event}? Subscribed #{count}") if count > @runaway_threshold
    end

    def clear
      @events.clear
    end

    def notify(event, *args)
      return unless @events.has_key?(event)

      @events[event].each do |handler|
        begin
          handler.call(*args)
        rescue => err
          OneApm::Agent.logger.debug("Failure during notify for #{event}", err)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.2 lib/one_apm/agent/event/event_listener.rb
oneapm_rpm-1.1.1 lib/one_apm/agent/event/event_listener.rb
oneapm_rpm-1.1.0 lib/one_apm/agent/event/event_listener.rb