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