From 2dc02e0f5666582f3e30f4c501c0d7290ab8d523 Mon Sep 17 00:00:00 2001 From: Herwin van Welbergen <hvanwelbergen@TechFak.Uni-Bielefeld.DE> Date: Thu, 20 Dec 2012 11:32:12 +0100 Subject: [PATCH] - made listenerlist threadsafe - fixed typo in ipaaca documentation --- ipaacalib/java/src/ipaaca/util/ComponentNotifier.java | 10 +++++++--- ipaacalib/python/src/ipaaca.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ipaacalib/java/src/ipaaca/util/ComponentNotifier.java b/ipaacalib/java/src/ipaaca/util/ComponentNotifier.java index c3f16a3..52552f5 100644 --- a/ipaacalib/java/src/ipaaca/util/ComponentNotifier.java +++ b/ipaacalib/java/src/ipaaca/util/ComponentNotifier.java @@ -9,6 +9,7 @@ import ipaaca.LocalMessageIU; import ipaaca.OutputBuffer; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; import java.util.List; @@ -39,7 +40,7 @@ public class ComponentNotifier private final ImmutableSet<String> sendCategories; private final ImmutableSet<String> receiveCategories; private final InputBuffer inBuffer; - private List<HandlerFunctor> handlers = new ArrayList<HandlerFunctor>(); + private List<HandlerFunctor> handlers = Collections.synchronizedList(new ArrayList<HandlerFunctor>()); private volatile boolean isInitialized = false; private final BlockingQueue<String> receiverQueue = new LinkedBlockingQueue<>(); @@ -51,9 +52,12 @@ public class ComponentNotifier if(iu.getPayload().get(NAME).equals(componentName))return; //don't re-notify self String receivers[] = iu.getPayload().get(RECEIVE_CATEGORIES).split("\\s*,\\s*"); receiverQueue.addAll(ImmutableSet.copyOf(receivers)); - for (HandlerFunctor h : handlers) + synchronized(handlers) { - h.handle(iu, type, local); + for (HandlerFunctor h : handlers) + { + h.handle(iu, type, local); + } } if (iu.getPayload().get(STATE).equals("new")) { diff --git a/ipaacalib/python/src/ipaaca.py b/ipaacalib/python/src/ipaaca.py index f6f80ad..ff81ea8 100755 --- a/ipaacalib/python/src/ipaaca.py +++ b/ipaacalib/python/src/ipaaca.py @@ -1086,7 +1086,7 @@ class Buffer(object): for_event_types -- a list of event types or None if handler should be called for all event types for_categories -- a list of category names or None if handler should - be called for all categoires + be called for all categories """ handler = IUEventHandler(handler_function=handler_function, for_event_types=for_event_types, for_categories=for_categories) -- GitLab