Refactor NBINotifications and serviceHandlerImpl
[transportpce.git] / dmaap-client / src / main / java / org / opendaylight / transportpce / dmaap / client / impl / DmaapClientProvider.java
1 /*
2  * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.dmaap.client.impl;
9
10 import org.opendaylight.mdsal.binding.api.NotificationService;
11 import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
12 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsListener;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class DmaapClientProvider {
18     private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
19     private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
20     private NotificationService notificationService;
21     private final String baseUrl;
22     private final String username;
23     private final String password;
24
25     public DmaapClientProvider(NotificationService notificationService, String baseUrl,
26             String username, String password) {
27         this.notificationService = notificationService;
28         this.baseUrl = baseUrl;
29         this.username = username;
30         this.password = password;
31     }
32
33     /**
34      * Method called when the blueprint container is created.
35      */
36     public void init() {
37         LOG.info("DmaapClientProvider Session Initiated");
38         listenerRegistration = notificationService.registerNotificationListener(
39                 new NbiNotificationsListenerImpl(baseUrl, username, password));
40     }
41
42     /**
43      * Method called when the blueprint container is destroyed.
44      */
45     public void close() {
46         listenerRegistration.close();
47         LOG.info("DmaapClientProvider Closed");
48     }
49
50 }