Sha256: ac22cb8fe814c60cc9881e7edce2fb87c1d70041fba5c20d27fb4a93c92b2292

Contents?: true

Size: 998 Bytes

Versions: 17

Compression:

Stored size: 998 Bytes

Contents

# encoding: utf-8

module TingYun
  module Agent
    module Event
      class EventListener

        attr_accessor :allocation

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

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

        def check_allocation(event)
          if @events[event].size > @allocation
            TingYun::Agent.logger.debug("Run-away event subscription on #{event}? Subscribed #{count}")
          end
        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
              TingYun::Agent.logger.debug("Failure during notify for #{event}", err)
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
tingyun_rpm-3.2.0 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.6.1 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.5.0 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.4.2 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.4.1 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.3.1 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.3.0 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.2.0 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.4.2 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.4.1 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.4 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.3 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.2 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.1 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.1.0 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.0.7 lib/ting_yun/agent/event/event_listener.rb
tingyun_rpm-1.0.6 lib/ting_yun/agent/event/event_listener.rb