Sha256: 3994d67f88925e7e65886ca04d169669ec0228707c24a3c9a5e53f1e4a7722f3

Contents?: true

Size: 893 Bytes

Versions: 39

Compression:

Stored size: 893 Bytes

Contents

# encoding: utf-8

module OneApm::Support
  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::Manager.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::Manager.logger.debug("Failure during notify for #{event}", err)
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
oneapm_rpm-1.2.9.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.8 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.8.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.7 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.7.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.6 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.6.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.5 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.5.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.4 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.4.rc1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.3 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.3.rc2 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.2 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.2.rc lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.1 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.1.rc lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.2.0 lib/one_apm/support/event/event_listener.rb
oneapm_rpm-1.1.3 lib/one_apm/support/event/event_listener.rb