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.NbiNotificationsListenerImpl;
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.rev211013.NotificationAlarmService;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.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 NbiNotificationsListenerImpl 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;
37 private int calledSetConverter = 0;
39 private TopicManager() {
42 public static TopicManager getInstance() {
46 public void setNbiNotificationsListener(NbiNotificationsListenerImpl nbiNotificationsListener) {
47 this.nbiNotificationsListener = nbiNotificationsListener;
50 public void setProcessConverter(JsonStringConverter<NotificationProcessService> processConverter) {
51 this.processConverter = processConverter;
54 public void setAlarmConverter(JsonStringConverter<NotificationAlarmService> alarmConverter) {
55 this.alarmConverter = alarmConverter;
58 public void setTapiConverter(JsonStringConverter<NotificationTapiService> tapiConverter) {
59 this.tapiConverter = tapiConverter;
60 this.calledSetConverter++;
63 public void setPublisherServer(String publisherServer) {
64 this.publisherServer = publisherServer;
67 public void addProcessTopic(String topic) {
68 LOG.info("Adding process topic: {}", topic);
69 processPublisherMap.put(topic, new Publisher<>(topic, publisherServer, processConverter,
70 NotificationServiceSerializer.class));
71 if (this.nbiNotificationsListener != null) {
72 this.nbiNotificationsListener.setPublishersServiceMap(processPublisherMap);
76 public void addAlarmTopic(String topic) {
77 LOG.info("Adding alarm topic: {}", topic);
78 alarmPublisherMap.put(topic, new Publisher<>(topic, publisherServer, alarmConverter,
79 NotificationAlarmServiceSerializer.class));
80 if (this.nbiNotificationsListener != null) {
81 this.nbiNotificationsListener.setPublishersAlarmMap(alarmPublisherMap);
85 public void addTapiTopic(String topic) {
86 if (tapiPublisherMap.containsKey(topic)) {
87 LOG.info("Tapi topic: {} already exists", topic);
90 LOG.info("Adding new tapi topic: {}", topic);
91 tapiPublisherMap.put(topic, new Publisher<>(topic, publisherServer, tapiConverter,
92 TapiNotificationSerializer.class));
93 if (this.nbiNotificationsListener != null) {
94 this.nbiNotificationsListener.setTapiPublishersMap(tapiPublisherMap);
98 public void deleteTapiTopic(String topic) {
99 if (!tapiPublisherMap.containsKey(topic)) {
100 LOG.info("Tapi topic: {} doesnt exist", topic);
103 LOG.info("Deleting tapi topic: {}", topic);
104 tapiPublisherMap.remove(topic);
105 if (this.nbiNotificationsListener != null) {
106 this.nbiNotificationsListener.setTapiPublishersMap(tapiPublisherMap);
110 public Map<String, Publisher<NotificationTapiService>> getTapiTopicMap() {
111 return this.tapiPublisherMap;
114 public Map<String, Publisher<NotificationAlarmService>> getAlarmTopicMap() {
115 return this.alarmPublisherMap;
118 public Map<String, Publisher<NotificationProcessService>> getProcessTopicMap() {
119 return this.processPublisherMap;