X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fstreams%2Flisteners%2FNotificator.java;h=17565a6b8c082d314f5b4e90715be18ca3536a8c;hb=75495f26e7718da7d6f9e0ad06af1caa2e3ebf08;hp=166c473b9c77d118b14c822bc177a1320b77e0fe;hpb=79202e1fd05d2606b35e163f608fad9cce84b5d4;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java index 166c473b9c..17565a6b8c 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java @@ -12,15 +12,15 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; /** - * {@link Notificator} is responsible to create, remove and find {@link ListenerAdapter} listener. + * {@link Notificator} is responsible to create, remove and find + * {@link ListenerAdapter} listener. */ public class Notificator { private static Map listenersByStreamName = new ConcurrentHashMap<>(); - private static Map listenersByInstanceIdentifier = new ConcurrentHashMap<>(); private static final Lock lock = new ReentrantLock(); private Notificator() { @@ -45,41 +45,28 @@ public class Notificator { } /** - * Gets {@link ListenerAdapter} listener specified by {@link InstanceIdentifier} path. + * Checks if the listener specified by {@link YangInstanceIdentifier} path exist. * - * @param path - * Path to data in data repository. - * @return ListenerAdapter - */ - public static ListenerAdapter getListenerFor(InstanceIdentifier path) { - return listenersByInstanceIdentifier.get(path); - } - - /** - * Checks if the listener specified by {@link InstanceIdentifier} path exist. - * - * @param path - * Path to data in data repository. + * @param streamName * @return True if the listener exist, false otherwise. */ - public static boolean existListenerFor(InstanceIdentifier path) { - return listenersByInstanceIdentifier.containsKey(path); + public static boolean existListenerFor(String streamName) { + return listenersByStreamName.containsKey(streamName); } /** - * Creates new {@link ListenerAdapter} listener from {@link InstanceIdentifier} path and stream name. + * Creates new {@link ListenerAdapter} listener from {@link YangInstanceIdentifier} path and stream name. * * @param path * Path to data in data repository. * @param streamName * The name of the stream. - * @return New {@link ListenerAdapter} listener from {@link InstanceIdentifier} path and stream name. + * @return New {@link ListenerAdapter} listener from {@link YangInstanceIdentifier} path and stream name. */ - public static ListenerAdapter createListener(InstanceIdentifier path, String streamName) { + public static ListenerAdapter createListener(YangInstanceIdentifier path, String streamName) { ListenerAdapter listener = new ListenerAdapter(path, streamName); try { lock.lock(); - listenersByInstanceIdentifier.put(path, listener); listenersByStreamName.put(streamName, listener); } finally { lock.unlock(); @@ -88,17 +75,7 @@ public class Notificator { } /** - * Looks for listener determined by {@link InstanceIdentifier} path and removes it. - * - * @param path - * InstanceIdentifier - */ - public static void removeListener(InstanceIdentifier path) { - ListenerAdapter listener = listenersByInstanceIdentifier.get(path); - deleteListener(listener); - } - - /** + * Looks for listener determined by {@link YangInstanceIdentifier} path and removes it. * Creates String representation of stream name from URI. Removes slash from URI in start and end position. * * @param uri @@ -114,7 +91,7 @@ public class Notificator { result = result.substring(1); } if (result.endsWith("/")) { - result = result.substring(0, result.length()); + result = result.substring(0, result.length()-1); } return result; } @@ -123,7 +100,7 @@ public class Notificator { * Removes all listeners. */ public static void removeAllListeners() { - for (ListenerAdapter listener : listenersByInstanceIdentifier.values()) { + for (ListenerAdapter listener : listenersByStreamName.values()) { try { listener.close(); } catch (Exception e) { @@ -132,7 +109,6 @@ public class Notificator { try { lock.lock(); listenersByStreamName = new ConcurrentHashMap<>(); - listenersByInstanceIdentifier = new ConcurrentHashMap<>(); } finally { lock.unlock(); } @@ -164,7 +140,6 @@ public class Notificator { } try { lock.lock(); - listenersByInstanceIdentifier.remove(listener.getPath()); listenersByStreamName.remove(listener.getStreamName()); } finally { lock.unlock();