2 * Copyright © 2021 Nokia, 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.transportpce.nbinotifications.utils;
10 import java.util.HashMap;
12 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
13 import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler;
14 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
15 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer;
16 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer;
17 import org.opendaylight.transportpce.nbinotifications.serialization.TapiNotificationSerializer;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public final class TopicManager {
26 private static final Logger LOG = LoggerFactory.getLogger(TopicManager.class);
27 private static TopicManager instance = new TopicManager();
29 private Map<String, Publisher<NotificationTapiService>> tapiPublisherMap = new HashMap<>();
30 private String publisherServer;
31 private JsonStringConverter<NotificationTapiService> tapiConverter;
32 private NbiNotificationsHandler nbiNotificationsListener;
33 private Map<String, Publisher<NotificationAlarmService>> alarmPublisherMap = new HashMap<>();
34 private Map<String, Publisher<NotificationProcessService>> processPublisherMap = new HashMap<>();
35 private JsonStringConverter<NotificationProcessService> processConverter;
36 private JsonStringConverter<NotificationAlarmService> alarmConverter;
38 private TopicManager() {
41 public static TopicManager getInstance() {
45 public void setNbiNotificationsListener(NbiNotificationsHandler nbiNotificationsListener) {
46 this.nbiNotificationsListener = nbiNotificationsListener;
49 public void setProcessConverter(JsonStringConverter<NotificationProcessService> processConverter) {
50 this.processConverter = processConverter;
53 public void setAlarmConverter(JsonStringConverter<NotificationAlarmService> alarmConverter) {
54 this.alarmConverter = alarmConverter;
57 public void setTapiConverter(JsonStringConverter<NotificationTapiService> tapiConverter) {
58 this.tapiConverter = tapiConverter;
61 public void setPublisherServer(String publisherServer) {
62 this.publisherServer = publisherServer;
65 public void addProcessTopic(String topic) {
66 LOG.info("Adding process topic: {}", topic);
67 processPublisherMap.put(topic, new Publisher<>(topic, publisherServer, processConverter,
68 NotificationServiceSerializer.class));
69 if (this.nbiNotificationsListener != null) {
70 this.nbiNotificationsListener.setPublishersServiceMap(processPublisherMap);
74 public void addAlarmTopic(String topic) {
75 LOG.info("Adding alarm topic: {}", topic);
76 alarmPublisherMap.put(topic, new Publisher<>(topic, publisherServer, alarmConverter,
77 NotificationAlarmServiceSerializer.class));
78 if (this.nbiNotificationsListener != null) {
79 this.nbiNotificationsListener.setPublishersAlarmMap(alarmPublisherMap);
83 public void addTapiTopic(String topic) {
84 if (tapiPublisherMap.containsKey(topic)) {
85 LOG.info("Tapi topic: {} already exists", topic);
88 LOG.info("Adding new tapi topic: {}", topic);
89 tapiPublisherMap.put(topic, new Publisher<>(topic, publisherServer, tapiConverter,
90 TapiNotificationSerializer.class));
91 if (this.nbiNotificationsListener != null) {
92 this.nbiNotificationsListener.setTapiPublishersMap(tapiPublisherMap);
96 public void deleteTapiTopic(String topic) {
97 if (!tapiPublisherMap.containsKey(topic)) {
98 LOG.info("Tapi topic: {} doesnt exist", topic);
101 LOG.info("Deleting tapi topic: {}", topic);
102 tapiPublisherMap.remove(topic);
103 if (this.nbiNotificationsListener != null) {
104 this.nbiNotificationsListener.setTapiPublishersMap(tapiPublisherMap);
108 public Map<String, Publisher<NotificationTapiService>> getTapiTopicMap() {
109 return this.tapiPublisherMap;
112 public Map<String, Publisher<NotificationAlarmService>> getAlarmTopicMap() {
113 return this.alarmPublisherMap;
116 public Map<String, Publisher<NotificationProcessService>> getProcessTopicMap() {
117 return this.processPublisherMap;