2 * Copyright © 2020 Orange, 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.impl;
10 import java.util.HashMap;
11 import java.util.List;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
16 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
17 import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
18 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
19 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer;
20 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NbiNotificationsListener;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NbiNotificationsService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class NbiNotificationsProvider {
31 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
32 private static Map<String, Publisher<org.opendaylight.yang.gen.v1
33 .nbi.notifications.rev210628.NotificationService>> publishersServiceMap = new HashMap<>();
34 private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
36 private final RpcProviderService rpcService;
37 private ObjectRegistration<NbiNotificationsService> rpcRegistration;
38 private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
39 private NotificationService notificationService;
40 private final JsonStringConverter<org.opendaylight.yang.gen.v1
41 .nbi.notifications.rev210628.NotificationService> converterService;
42 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
43 private final String subscriberServer;
46 public NbiNotificationsProvider(List<String> topicsService, List<String> topicsAlarm,
47 String subscriberServer, String publisherServer,
48 RpcProviderService rpcProviderService, NotificationService notificationService,
49 BindingDOMCodecServices bindingDOMCodecServices) {
50 this.rpcService = rpcProviderService;
51 this.notificationService = notificationService;
52 converterService = new JsonStringConverter<>(bindingDOMCodecServices);
53 for (String topic: topicsService) {
54 LOG.info("Creating publisher for topic {}", topic);
55 publishersServiceMap.put(topic, new Publisher<>(topic, publisherServer, converterService,
56 NotificationServiceSerializer.class));
58 converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
59 for (String topic: topicsAlarm) {
60 LOG.info("Creating publisher for topic {}", topic);
61 publishersAlarmMap.put(topic, new Publisher<>(topic, publisherServer, converterAlarmService,
62 NotificationAlarmServiceSerializer.class));
64 this.subscriberServer = subscriberServer;
68 * Method called when the blueprint container is created.
71 LOG.info("NbiNotificationsProvider Session Initiated");
72 rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class,
73 new NbiNotificationsImpl(converterService, converterAlarmService, subscriberServer));
74 listenerRegistration = notificationService.registerNotificationListener(
75 new NbiNotificationsListenerImpl(publishersServiceMap, publishersAlarmMap));
79 * Method called when the blueprint container is destroyed.
82 for (Publisher<org.opendaylight.yang.gen.v1
83 .nbi.notifications.rev210628.NotificationService> publisher : publishersServiceMap.values()) {
86 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
87 publisherAlarm.close();
89 rpcRegistration.close();
90 listenerRegistration.close();
91 LOG.info("NbiNotificationsProvider Closed");