2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.messagebus.eventsources.netconf;
10 import java.time.Instant;
11 import java.util.HashSet;
12 import java.util.Optional;
14 import java.util.concurrent.ConcurrentHashMap;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Notification topic registration.
23 @Deprecated(forRemoval = true)
24 abstract class NotificationTopicRegistration implements AutoCloseable {
26 private static final Logger LOG = LoggerFactory.getLogger(NotificationTopicRegistration.class);
28 public enum NotificationSourceType {
30 ConnectionStatusChange
33 private boolean active;
34 private final NotificationSourceType notificationSourceType;
35 private final String sourceName;
36 private final String notificationUrnPrefix;
37 private boolean replaySupported;
38 private Instant lastEventTime;
39 protected final ConcurrentHashMap<SchemaPath, Set<TopicId>> notificationTopicMap = new ConcurrentHashMap<>();
41 protected NotificationTopicRegistration(final NotificationSourceType notificationSourceType,
42 final String sourceName, final String notificationUrnPrefix) {
43 this.notificationSourceType = notificationSourceType;
44 this.sourceName = sourceName;
45 this.notificationUrnPrefix = notificationUrnPrefix;
47 this.setReplaySupported(false);
50 public boolean isActive() {
54 protected void setActive(final boolean active) {
58 public NotificationSourceType getNotificationSourceType() {
59 return notificationSourceType;
62 public String getSourceName() {
66 public String getNotificationUrnPrefix() {
67 return notificationUrnPrefix;
71 * Returns registered topics for given notification path.
73 * @param notificationPath path
76 Set<TopicId> getTopicsForNotification(final SchemaPath notificationPath) {
77 final Set<TopicId> topicIds = notificationTopicMap.get(notificationPath);
78 return topicIds != null ? topicIds : new HashSet<>();
82 * Checks, if notification is from namespace belonging to this registration.
84 * @param notificationPath path
85 * @return true, if notification belongs to registration namespace
87 boolean checkNotificationPath(final SchemaPath notificationPath) {
88 if (notificationPath == null) {
91 String nameSpace = notificationPath.getLastComponent().getNamespace().toString();
92 LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace,
93 getNotificationUrnPrefix());
94 return nameSpace.startsWith(getNotificationUrnPrefix());
97 Optional<Instant> getLastEventTime() {
98 return Optional.ofNullable(lastEventTime);
101 void setLastEventTime(final Instant lastEventTime) {
102 this.lastEventTime = lastEventTime;
105 abstract void activateNotificationSource();
107 abstract void deActivateNotificationSource();
109 abstract void reActivateNotificationSource();
112 * Registers associated event source notification to topic.
114 * @param notificationPath notification path
115 * @param topicId topic id
116 * @return true, if successful
118 abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId);
121 * Registers associated event source notification to topic.
123 * @param topicId topic id
125 abstract void unRegisterNotificationTopic(TopicId topicId);
127 public boolean isReplaySupported() {
128 return replaySupported;
131 protected void setReplaySupported(final boolean replaySupported) {
132 this.replaySupported = replaySupported;