BUG-1120: promote synchronization to all entrypoints 90/7590/1
authorRobert Varga <rovarga@cisco.com>
Mon, 2 Jun 2014 11:35:29 +0000 (13:35 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 2 Jun 2014 11:57:52 +0000 (13:57 +0200)
This is a temporary regression in performance: get rid of the
synchronized map at the cost of explicit synchronized methods.
Subsequent patches will remove the synchronization from the fast paths.

Change-Id: Ibe90e4e7ff99655a69b77c942ad50baec9df1ba2
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationListenerMap.java

index d3039fe..2fab0ab 100644 (file)
@@ -19,11 +19,10 @@ import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
 
 final class NotificationListenerMap {
     private final Multimap<Class<? extends Notification>, NotificationListenerRegistration<?>> listeners =
-            Multimaps.synchronizedSetMultimap(HashMultimap.<Class<? extends Notification>, NotificationListenerRegistration<?>>create());
+            HashMultimap.create();
 
     private static Iterable<Class<?>> getNotificationTypes(final Notification notification) {
         final Class<?>[] ifaces = notification.getClass().getInterfaces();
@@ -38,7 +37,7 @@ final class NotificationListenerMap {
         });
     }
 
-    Iterable<NotificationListenerRegistration<?>> listenersFor(final Notification notification) {
+    synchronized Iterable<NotificationListenerRegistration<?>> listenersFor(final Notification notification) {
         final Set<NotificationListenerRegistration<?>> toNotify = new HashSet<>();
 
         for (final Class<?> type : getNotificationTypes(notification)) {
@@ -51,20 +50,19 @@ final class NotificationListenerMap {
         return toNotify;
     }
 
-    Iterable<Class<? extends Notification>> getKnownTypes() {
+    synchronized Iterable<Class<? extends Notification>> getKnownTypes() {
         return ImmutableList.copyOf(listeners.keySet());
     }
 
-    void addRegistrations(final NotificationListenerRegistration<?>... registrations) {
+    synchronized void addRegistrations(final NotificationListenerRegistration<?>... registrations) {
         for (NotificationListenerRegistration<?> reg : registrations) {
             listeners.put(reg.getType(), reg);
         }
     }
 
-    void removeRegistrations(final NotificationListenerRegistration<?>... registrations) {
+    synchronized void removeRegistrations(final NotificationListenerRegistration<?>... registrations) {
         for (NotificationListenerRegistration<?> reg : registrations) {
             listeners.remove(reg.getType(), reg);
         }
     }
-
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.