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.rev210813.NbiNotificationsListener;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.opendaylight.yangtools.concepts.ObjectRegistration;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class NbiNotificationsProvider {
32 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
33 private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
34 private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
35 private final RpcProviderService rpcService;
36 private final NotificationService notificationService;
37 private final JsonStringConverter<NotificationProcessService> converterService;
38 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
39 private final String subscriberServer;
40 private ObjectRegistration<NbiNotificationsService> rpcRegistration;
41 private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
44 public NbiNotificationsProvider(List<String> publishersService, List<String> publishersAlarm,
45 String subscriberServer, String publisherServer,
46 RpcProviderService rpcProviderService, NotificationService notificationService,
47 BindingDOMCodecServices bindingDOMCodecServices) {
48 this.rpcService = rpcProviderService;
49 this.notificationService = notificationService;
50 converterService = new JsonStringConverter<>(bindingDOMCodecServices);
51 for (String publisherService: publishersService) {
52 LOG.info("Creating publisher for the following class {}", publisherService);
53 publishersServiceMap.put(publisherService, new Publisher<>(publisherService, publisherServer,
54 converterService, NotificationServiceSerializer.class));
56 converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
57 for (String publisherAlarm: publishersAlarm) {
58 LOG.info("Creating publisher for the following class {}", publisherAlarm);
59 publishersAlarmMap.put(publisherAlarm, new Publisher<>(publisherAlarm, publisherServer,
60 converterAlarmService, NotificationAlarmServiceSerializer.class));
62 this.subscriberServer = subscriberServer;
66 * Method called when the blueprint container is created.
69 LOG.info("NbiNotificationsProvider Session Initiated");
70 rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class,
71 new NbiNotificationsImpl(converterService, converterAlarmService, subscriberServer));
72 listenerRegistration = notificationService.registerNotificationListener(
73 new NbiNotificationsListenerImpl(publishersServiceMap, publishersAlarmMap));
77 * Method called when the blueprint container is destroyed.
80 for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
83 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
84 publisherAlarm.close();
86 rpcRegistration.close();
87 listenerRegistration.close();
88 LOG.info("NbiNotificationsProvider Closed");