Class: LogStash::EventDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/event_dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(emitter) ⇒ EventDispatcher

Returns a new instance of EventDispatcher.



8
9
10
11
# File 'lib/logstash/event_dispatcher.rb', line 8

def initialize(emitter)
  @emitter = emitter
  @listeners = CopyOnWriteArrayList.new
end

Instance Attribute Details

#emitterObject (readonly)

Returns the value of attribute emitter.



6
7
8
# File 'lib/logstash/event_dispatcher.rb', line 6

def emitter
  @emitter
end

Instance Method Details

#add_listener(listener) ⇒ Object

This operation is slow because we use a CopyOnWriteArrayList But the majority of the addition will be done at bootstrap time So add_listener shouldn’t be called often at runtime.

On the other hand the notification could be called really often.



18
19
20
# File 'lib/logstash/event_dispatcher.rb', line 18

def add_listener(listener)
  @listeners.add(listener)
end

#fire(method_name, *arguments) ⇒ Object Also known as: execute



31
32
33
34
35
36
37
# File 'lib/logstash/event_dispatcher.rb', line 31

def fire(method_name, *arguments)
  @listeners.each do |listener|
    if listener.respond_to?(method_name)
      listener.send(method_name, emitter, *arguments)
    end
  end
end

#remove_listener(listener) ⇒ Object

This operation is slow because we use a ‘CopyOnWriteArrayList` as the backend, instead of a ConcurrentHashMap, but since we are mostly adding stuff and iterating the `CopyOnWriteArrayList` should provide a better performance.

See note on add_listener, this method shouldn’t be called really often.



27
28
29
# File 'lib/logstash/event_dispatcher.rb', line 27

def remove_listener(listener)
  @listeners.remove(listener)
end