import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
@Override
public synchronized void close() {
if (this.bgpAppPeerSingletonService != null) {
- try {
- this.bgpAppPeerSingletonService.close();
- this.bgpAppPeerSingletonService = null;
- } catch (final Exception e) {
- LOG.warn("Failed to close application peer instance", e);
- }
+ this.bgpAppPeerSingletonService = null;
}
if (this.serviceRegistration != null) {
this.serviceRegistration.unregister();
}
}
+ @Override
+ public synchronized void instantiateServiceInstance() {
+ if (this.bgpAppPeerSingletonService != null) {
+ this.bgpAppPeerSingletonService.instantiateServiceInstance();
+ }
+ }
+
@Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
if (this.bgpAppPeerSingletonService != null) {
this.serviceRegistration = serviceRegistration;
}
- private final class BgpAppPeerSingletonService implements ClusterSingletonService, BGPPeerStateConsumer,
- AutoCloseable {
+ private final class BgpAppPeerSingletonService implements BGPPeerStateConsumer {
private final ApplicationPeer applicationPeer;
private final DOMDataTreeChangeService dataTreeChangeService;
private final ApplicationRibId appRibId;
- private final ServiceGroupIdentifier serviceGroupIdentifier;
- private ClusterSingletonServiceRegistration singletonServiceRegistration;
@GuardedBy("this")
private boolean isServiceInstantiated;
this.applicationPeer = new ApplicationPeer(appRibId, neighborAddress, rib);
this.appRibId = appRibId;
this.dataTreeChangeService = rib.getService();
- this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
- LOG.info("Application Peer Singleton Service {} registered, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
- //this need to be always the last step
- this.singletonServiceRegistration = rib.registerClusterSingletonService(this);
}
- @Override
- public void close() throws Exception {
- if (this.singletonServiceRegistration != null) {
- this.singletonServiceRegistration.close();
- this.singletonServiceRegistration = null;
- }
- }
-
- @Override
public synchronized void instantiateServiceInstance() {
this.isServiceInstantiated = true;
- LOG.info("Application Peer Singleton Service {} instantiated, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
.nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue())
.node(Tables.QNAME).node(Tables.QNAME).build();
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId));
}
- @Override
public synchronized ListenableFuture<Void> closeServiceInstance() {
if (!this.isServiceInstantiated) {
- LOG.trace("Application Peer Singleton Service {} instance already closed, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ LOG.trace("Application peer already closed {}", this.appRibId.getValue());
return Futures.immediateFuture(null);
}
- LOG.info("Application Peer Singleton Service {} instance closed, Application peer {}",
- getIdentifier().getValue(), this.appRibId.getValue());
+ LOG.info("Application peer instance closed {}", this.appRibId.getValue());
this.isServiceInstantiated = false;
return this.applicationPeer.close();
}
- @Override
- public ServiceGroupIdentifier getIdentifier() {
- return this.serviceGroupIdentifier;
- }
-
@Override
public BGPPeerState getPeerState() {
return this.applicationPeer.getPeerState();