07e2d3b564a56aa88776a800153b916c5b48b283
[netconf.git] /
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.messagebus.eventsources.netconf;
9
10 import java.util.ArrayList;
11 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
12 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * Notification topic registration.
18  */
19 public abstract class NotificationTopicRegistration implements AutoCloseable {
20
21     private static final Logger LOG = LoggerFactory.getLogger(NotificationTopicRegistration.class);
22
23     public enum NotificationSourceType {
24         NetconfDeviceStream,
25         ConnectionStatusChange;
26     }
27
28     private boolean active;
29     private final NotificationSourceType notificationSourceType;
30     private final String sourceName;
31     private final String notificationUrnPrefix;
32     private boolean replaySupported;
33
34     protected NotificationTopicRegistration(NotificationSourceType notificationSourceType, String sourceName,
35         String notificationUrnPrefix) {
36         this.notificationSourceType = notificationSourceType;
37         this.sourceName = sourceName;
38         this.notificationUrnPrefix = notificationUrnPrefix;
39         this.active = false;
40         this.setReplaySupported(false);
41     }
42
43     public boolean isActive() {
44         return active;
45     }
46
47     protected void setActive(boolean active) {
48         this.active = active;
49     }
50
51     public NotificationSourceType getNotificationSourceType() {
52         return notificationSourceType;
53     }
54
55     public String getSourceName() {
56         return sourceName;
57     }
58
59     public String getNotificationUrnPrefix() {
60         return notificationUrnPrefix;
61     }
62
63     /**
64      * Checks, if notification is from namespace belonging to this registration.
65      * @param notificationPath path
66      * @return true, if notification belongs to registration namespace
67      */
68     public boolean checkNotificationPath(SchemaPath notificationPath) {
69         if (notificationPath == null) {
70             return false;
71         }
72         String nameSpace = notificationPath.getLastComponent().getNamespace().toString();
73         LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace,
74             getNotificationUrnPrefix());
75         return nameSpace.startsWith(getNotificationUrnPrefix());
76     }
77
78     abstract void activateNotificationSource();
79
80     abstract void deActivateNotificationSource();
81
82     abstract void reActivateNotificationSource();
83
84     /**
85      * Registers associated event source notification to topic.
86      * @param notificationPath notification path
87      * @param topicId topic id
88      * @return true, if successful
89      */
90     abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId);
91
92     /**
93      * Registers associated event source notification to topic.
94      * @param topicId topic id
95      * @return true, if successful
96      */
97     abstract void unRegisterNotificationTopic(TopicId topicId);
98
99     /**
100      * Returns registered topics for given path.
101      * @param notificationPath path
102      * @return topicIds
103      */
104     abstract ArrayList<TopicId> getNotificationTopicIds(SchemaPath notificationPath);
105
106     public boolean isReplaySupported() {
107         return replaySupported;
108     }
109
110     protected void setReplaySupported(boolean replaySupported) {
111         this.replaySupported = replaySupported;
112     }
113
114 }