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.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsListener;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsService;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.concepts.ObjectRegistration;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class NbiNotificationsProvider {
28 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
29 private static Map<String, Publisher> publishersMap = new HashMap<>();
31 private final RpcProviderService rpcService;
32 private ObjectRegistration<NbiNotificationsService> rpcRegistration;
33 private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
34 private NotificationService notificationService;
35 private final JsonStringConverter<org.opendaylight.yang.gen.v1
36 .nbi.notifications.rev201130.NotificationService> converter;
37 private final String suscriberServer;
40 public NbiNotificationsProvider(List<String> topics,
41 String suscriberServer, String publisherServer,
42 RpcProviderService rpcProviderService, NotificationService notificationService,
43 BindingDOMCodecServices bindingDOMCodecServices) {
44 this.rpcService = rpcProviderService;
45 this.notificationService = notificationService;
46 converter = new JsonStringConverter<>(bindingDOMCodecServices);
47 for (String topic: topics) {
48 LOG.info("Creating publisher for topic {}", topic);
49 publishersMap.put(topic, new Publisher(topic, publisherServer, converter));
51 this.suscriberServer = suscriberServer;
55 * Method called when the blueprint container is created.
58 LOG.info("NbiNotificationsProvider Session Initiated");
59 rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class,
60 new NbiNotificationsImpl(converter, suscriberServer));
61 listenerRegistration = notificationService.registerNotificationListener(
62 new NbiNotificationsListenerImpl(publishersMap));
66 * Method called when the blueprint container is destroyed.
69 for (Publisher publisher : publishersMap.values()) {
72 rpcRegistration.close();
73 listenerRegistration.close();
74 LOG.info("NbiNotificationsProvider Closed");