Bump versions to 2.0.0-SNAPSHOT
[netconf.git] / netconf / messagebus-netconf / src / main / java / org / opendaylight / netconf / messagebus / eventsources / netconf / NotificationTopicRegistration.java
index 07e2d3b564a56aa88776a800153b916c5b48b283..286ac1db35c35a2dddb4d01d19ce2d8b59fe562f 100644 (file)
@@ -7,7 +7,11 @@
  */
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
-import java.util.ArrayList;
+import java.time.Instant;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
@@ -16,13 +20,14 @@ import org.slf4j.LoggerFactory;
 /**
  * Notification topic registration.
  */
-public abstract class NotificationTopicRegistration implements AutoCloseable {
+@Deprecated(forRemoval = true)
+abstract class NotificationTopicRegistration implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(NotificationTopicRegistration.class);
 
     public enum NotificationSourceType {
         NetconfDeviceStream,
-        ConnectionStatusChange;
+        ConnectionStatusChange
     }
 
     private boolean active;
@@ -30,9 +35,11 @@ public abstract class NotificationTopicRegistration implements AutoCloseable {
     private final String sourceName;
     private final String notificationUrnPrefix;
     private boolean replaySupported;
+    private Instant lastEventTime;
+    protected final ConcurrentHashMap<SchemaPath, Set<TopicId>> notificationTopicMap = new ConcurrentHashMap<>();
 
-    protected NotificationTopicRegistration(NotificationSourceType notificationSourceType, String sourceName,
-        String notificationUrnPrefix) {
+    protected NotificationTopicRegistration(final NotificationSourceType notificationSourceType,
+            final String sourceName, final String notificationUrnPrefix) {
         this.notificationSourceType = notificationSourceType;
         this.sourceName = sourceName;
         this.notificationUrnPrefix = notificationUrnPrefix;
@@ -44,7 +51,7 @@ public abstract class NotificationTopicRegistration implements AutoCloseable {
         return active;
     }
 
-    protected void setActive(boolean active) {
+    protected void setActive(final boolean active) {
         this.active = active;
     }
 
@@ -60,21 +67,41 @@ public abstract class NotificationTopicRegistration implements AutoCloseable {
         return notificationUrnPrefix;
     }
 
+    /**
+     * Returns registered topics for given notification path.
+     *
+     * @param notificationPath path
+     * @return topicIds
+     */
+    Set<TopicId> getTopicsForNotification(final SchemaPath notificationPath) {
+        final Set<TopicId> topicIds = notificationTopicMap.get(notificationPath);
+        return topicIds != null ? topicIds : new HashSet<>();
+    }
+
     /**
      * Checks, if notification is from namespace belonging to this registration.
+     *
      * @param notificationPath path
      * @return true, if notification belongs to registration namespace
      */
-    public boolean checkNotificationPath(SchemaPath notificationPath) {
+    boolean checkNotificationPath(final SchemaPath notificationPath) {
         if (notificationPath == null) {
             return false;
         }
         String nameSpace = notificationPath.getLastComponent().getNamespace().toString();
         LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace,
-            getNotificationUrnPrefix());
+                getNotificationUrnPrefix());
         return nameSpace.startsWith(getNotificationUrnPrefix());
     }
 
+    Optional<Instant> getLastEventTime() {
+        return Optional.ofNullable(lastEventTime);
+    }
+
+    void setLastEventTime(final Instant lastEventTime) {
+        this.lastEventTime = lastEventTime;
+    }
+
     abstract void activateNotificationSource();
 
     abstract void deActivateNotificationSource();
@@ -83,31 +110,25 @@ public abstract class NotificationTopicRegistration implements AutoCloseable {
 
     /**
      * Registers associated event source notification to topic.
+     *
      * @param notificationPath notification path
-     * @param topicId topic id
+     * @param topicId          topic id
      * @return true, if successful
      */
     abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId);
 
     /**
      * Registers associated event source notification to topic.
+     *
      * @param topicId topic id
-     * @return true, if successful
      */
     abstract void unRegisterNotificationTopic(TopicId topicId);
 
-    /**
-     * Returns registered topics for given path.
-     * @param notificationPath path
-     * @return topicIds
-     */
-    abstract ArrayList<TopicId> getNotificationTopicIds(SchemaPath notificationPath);
-
     public boolean isReplaySupported() {
         return replaySupported;
     }
 
-    protected void setReplaySupported(boolean replaySupported) {
+    protected void setReplaySupported(final boolean replaySupported) {
         this.replaySupported = replaySupported;
     }