mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Replace the internal list of listeners with a set
Because we sync listeners with emitters when adding or creating hook this could lead to duplicates of listeners, this PR fixes the problem by using a set instead of a list. Making sure we can only have one instance of a specific listener at any time. Fixes #6916
This commit is contained in:
parent
61df938db2
commit
a159ac2db4
2 changed files with 9 additions and 2 deletions
|
@ -1,13 +1,13 @@
|
|||
# encoding: utf-8
|
||||
module LogStash
|
||||
class EventDispatcher
|
||||
java_import "java.util.concurrent.CopyOnWriteArrayList"
|
||||
java_import "java.util.concurrent.CopyOnWriteArraySet"
|
||||
|
||||
attr_reader :emitter
|
||||
|
||||
def initialize(emitter)
|
||||
@emitter = emitter
|
||||
@listeners = CopyOnWriteArrayList.new
|
||||
@listeners = CopyOnWriteArraySet.new
|
||||
end
|
||||
|
||||
# This operation is slow because we use a CopyOnWriteArrayList
|
||||
|
|
|
@ -34,6 +34,13 @@ describe LogStash::EventDispatcher do
|
|||
let(:listener) { CustomSpy }
|
||||
subject(:emitter) { DummyEmitter.new }
|
||||
|
||||
it "ignores duplicate listener" do
|
||||
emitter.dispatcher.add_listener(listener)
|
||||
emitter.dispatcher.add_listener(listener)
|
||||
expect(listener).to receive(:method_exists).with(emitter).once
|
||||
emitter.method_exists
|
||||
end
|
||||
|
||||
describe "Emits events" do
|
||||
before do
|
||||
emitter.dispatcher.add_listener(listener)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue