Merge "Activate Swagger for Lighty"
[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.rev211013.NbiNotificationsListener;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.osgi.service.component.annotations.Activate;
15 import org.osgi.service.component.annotations.Component;
16 import org.osgi.service.component.annotations.Reference;
17 import org.osgi.service.metatype.annotations.AttributeDefinition;
18 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 @Component(configurationPid = "org.opendaylight.transportpce.dmaap")
23 public class DmaapClientProvider {
24
25     @ObjectClassDefinition
26     public @interface Configuration {
27         @AttributeDefinition
28         String dmaapBaseUrl() default "http://localhost:8080";
29         @AttributeDefinition
30         String dmaapUsername() default "";
31         @AttributeDefinition
32         String dmaapPassword() default "";
33     }
34
35     private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
36     private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
37
38     @Activate
39     public DmaapClientProvider(@Reference NotificationService notificationService, Configuration config) {
40         this(notificationService, config.dmaapBaseUrl(), config.dmaapUsername(), config.dmaapPassword());
41     }
42
43     public DmaapClientProvider(NotificationService notificationService, String baseUrl,
44             String username, String password) {
45         listenerRegistration = notificationService.registerNotificationListener(
46                 new NbiNotificationsListenerImpl(baseUrl, username, password));
47         LOG.info("DmaapClientProvider Session Initiated");
48     }
49
50     /**
51      * Method called when the blueprint container is destroyed.
52      */
53     public void close() {
54         listenerRegistration.close();
55         LOG.info("DmaapClientProvider Closed");
56     }
57 }