import org.opendaylight.transportpce.dmaap.client.listener.NbiNotificationsListenerImpl;
import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Component(configurationPid = "org.opendaylight.transportpce.dmaap")
public class DmaapClientProvider {
+
+ @ObjectClassDefinition
+ public @interface Configuration {
+ @AttributeDefinition
+ String dmaapBaseUrl() default "http://localhost:8080";
+ @AttributeDefinition
+ String dmaapUsername() default "";
+ @AttributeDefinition
+ String dmaapPassword() default "";
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(DmaapClientProvider.class);
private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
- private NotificationService notificationService;
- private final String baseUrl;
- private final String username;
- private final String password;
- public DmaapClientProvider(NotificationService notificationService, String baseUrl,
- String username, String password) {
- this.notificationService = notificationService;
- this.baseUrl = baseUrl;
- this.username = username;
- this.password = password;
+ @Activate
+ public DmaapClientProvider(@Reference NotificationService notificationService, Configuration config) {
+ this(notificationService, config.dmaapBaseUrl(), config.dmaapUsername(), config.dmaapPassword());
}
- /**
- * Method called when the blueprint container is created.
- */
- public void init() {
- LOG.info("DmaapClientProvider Session Initiated");
+ public DmaapClientProvider(NotificationService notificationService, String baseUrl,
+ String username, String password) {
listenerRegistration = notificationService.registerNotificationListener(
new NbiNotificationsListenerImpl(baseUrl, username, password));
+ LOG.info("DmaapClientProvider Session Initiated");
}
/**
listenerRegistration.close();
LOG.info("DmaapClientProvider Closed");
}
-
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!-- Copyright © 2021 Orange and others. All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
- <cm:property-placeholder persistent-id="org.opendaylight.transportpce.dmaap" update-strategy="reload">
- <cm:default-properties>
- <cm:property name="dmaap.baseUrl" value="http://localhost:8080" />
- <cm:property name="dmaap.username" value="" />
- <cm:property name="dmaap.password" value="" />
- </cm:default-properties>
- </cm:property-placeholder>
- <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
-
- <bean id="provider"
- class="org.opendaylight.transportpce.dmaap.client.impl.DmaapClientProvider"
- init-method="init" destroy-method="close">
- <argument ref="notificationService" />
- <argument value="${dmaap.baseUrl}" />
- <argument value="${dmaap.username}" />
- <argument value="${dmaap.password}" />
- </bean>
-</blueprint>
@Test
void testInitRegisterNbiNotificationsToRpcRegistry() {
- DmaapClientProvider provider =
- new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
- provider.init();
- (verify(notificationService, times(1)))
- .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
+ new DmaapClientProvider(notificationService, "http://localhost", "username", "password");
+ verify(notificationService, times(1))
+ .registerNotificationListener(Mockito.any(NbiNotificationsListenerImpl.class));
}
}