use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.
the class BgpTopologyDeployerImpl method registerService.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public AbstractRegistration registerService(final TopologyReferenceSingletonService topologyProviderService) {
final Dictionary<String, String> properties = new Hashtable<>();
properties.put("topology-id", topologyProviderService.getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
final ServiceRegistration<?> registerService = this.context.registerService(new String[] { TopologyReference.class.getName() }, topologyProviderService, properties);
final ClusterSingletonServiceRegistration registerClusterSingletonService = registerSingletonService(topologyProviderService);
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
try {
registerClusterSingletonService.close();
} catch (final Exception e) {
LOG.warn("Failed to close ClusterSingletonServiceRegistration {} for TopologyBuilder {}", registerClusterSingletonService, topologyProviderService.getInstanceIdentifier(), e);
} finally {
registerService.unregister();
}
}
};
}
use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.
the class ClusterSingletonServiceRegistrationHelperTest method testRegisterSingletonServiceSuccessfulRetry.
@Test
public void testRegisterSingletonServiceSuccessfulRetry() {
final ClusterSingletonServiceRegistration registerSingletonService = registerSingletonService(this.singletonProvider, this.clusterSingletonService, 1, 1);
assertEquals(this.serviceRegistration, registerSingletonService);
// first reg. attempt failed, second succeeded
verify(this.singletonProvider, Mockito.times(2)).registerClusterSingletonService(any());
}
use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration in project bgpcep by opendaylight.
the class BgpDeployerImplTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
doReturn("mapping").when(this.tableTypeRegistry).toString();
doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
doNothing().when(this.registration).unregister();
doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any(), any(Dictionary.class));
doNothing().when(this.dataTreeRegistration).close();
doReturn("bgpPeer").when(this.modification).toString();
final RIBExtensionConsumerContext extension = mock(RIBExtensionConsumerContext.class);
doReturn(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()).when(extension).getClassLoadingStrategy();
final ClusterSingletonServiceRegistration serviceRegistration = mock(ClusterSingletonServiceRegistration.class);
doReturn(serviceRegistration).when(this.singletonServiceProvider).registerClusterSingletonService(any());
doNothing().when(serviceRegistration).close();
final DOMSchemaService schemaService = mock(DOMSchemaService.class);
doNothing().when(this.dataTreeRegistration).close();
doReturn(this.dataTreeRegistration).when(schemaService).registerSchemaContextListener(any());
final RibImpl ribImpl = new RibImpl(extension, mock(BGPDispatcher.class), this.policyProvider, mock(BindingCodecTreeFactory.class), getDomBroker(), getDataBroker(), schemaService);
doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
doReturn(new BgpPeer(mock(RpcProviderRegistry.class))).when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
this.deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider, this.blueprintContainer, this.bundleContext, getDataBroker(), this.tableTypeRegistry);
}
Aggregations