Decouple message bus from netconf connector
[controller.git] / opendaylight / netconf / messagebus-netconf / src / main / java / org / opendaylight / controller / messagebus / eventsources / netconf / NotificationTopicRegistration.java
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.controller.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 public abstract class NotificationTopicRegistration implements AutoCloseable {
17
18     private static final Logger LOG = LoggerFactory.getLogger(NotificationTopicRegistration.class);
19
20     public enum NotificationSourceType {
21         NetconfDeviceStream,
22         ConnectionStatusChange;
23     }
24
25     private boolean active;
26     private final NotificationSourceType notificationSourceType;
27     private final String sourceName;
28     private final String notificationUrnPrefix;
29     private boolean replaySupported;
30
31     protected NotificationTopicRegistration(NotificationSourceType notificationSourceType, String sourceName,
32         String notificationUrnPrefix) {
33         this.notificationSourceType = notificationSourceType;
34         this.sourceName = sourceName;
35         this.notificationUrnPrefix = notificationUrnPrefix;
36         this.active = false;
37         this.setReplaySupported(false);
38     }
39
40     public boolean isActive() {
41         return active;
42     }
43
44     protected void setActive(boolean active) {
45         this.active = active;
46     }
47
48     public NotificationSourceType getNotificationSourceType() {
49         return notificationSourceType;
50     }
51
52     public String getSourceName() {
53         return sourceName;
54     }
55
56     public String getNotificationUrnPrefix() {
57         return notificationUrnPrefix;
58     }
59
60     public boolean checkNotificationPath(SchemaPath notificationPath) {
61         if (notificationPath == null) {
62             return false;
63         }
64         String nameSpace = notificationPath.getLastComponent().toString();
65         LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace,
66             getNotificationUrnPrefix());
67         return nameSpace.startsWith(getNotificationUrnPrefix());
68     }
69
70     abstract void activateNotificationSource();
71
72     abstract void deActivateNotificationSource();
73
74     abstract void reActivateNotificationSource();
75
76     abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId);
77
78     abstract void unRegisterNotificationTopic(TopicId topicId);
79
80     abstract ArrayList<TopicId> getNotificationTopicIds(SchemaPath notificationPath);
81
82     public boolean isReplaySupported() {
83         return replaySupported;
84     }
85
86     protected void setReplaySupported(boolean replaySupported) {
87         this.replaySupported = replaySupported;
88     }
89
90 }