import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.concurrent.Future;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
}
}
+ @Override
+ public ListenableFuture<Void> closeServiceInstance() {
+ if (this.bgpPeerSingletonService != null) {
+ return this.bgpPeerSingletonService.closeServiceInstance();
+ }
+ return Futures.immediateFuture(null);
+ }
+
private void closeSingletonService() {
try {
this.bgpPeerSingletonService.close();
private final IpAddress neighborAddress;
private final BGPSessionPreferences prefs;
private Future<Void> connection;
+ @GuardedBy("this")
+ private boolean isServiceInstantiated;
private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService,
final WriteConfiguration configurationWriter) {
mappingService.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor), BgpPeer.this.rpcRegistry);
final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, mappingService);
final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
- this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(), getPeerAs(neighbor, rib),
- bgpParameters, getPassword(keyMapping));
+ this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(),
+ getPeerAs(neighbor, rib), bgpParameters, getPassword(keyMapping));
this.activeConnection = OpenConfigMappingUtil.isActive(neighbor);
this.dispatcher = rib.getDispatcher();
this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, OpenConfigMappingUtil.getPort(neighbor));
this.key = Optional.fromNullable(keyMapping);
this.configurationWriter = configurationWriter;
this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
- LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier);
+ LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier.getValue());
//this need to be always the last step
this.registration = rib.registerClusterSingletonService(this);
}
}
@Override
- public void instantiateServiceInstance() {
+ public synchronized void instantiateServiceInstance() {
+ this.isServiceInstantiated = true;
if(this.configurationWriter != null) {
this.configurationWriter.apply();
}
- LOG.info("Peer Singleton Service {} instantiated", getIdentifier());
+ LOG.info("Peer Singleton Service {} instantiated, Peer {}", getIdentifier().getValue(), this.neighborAddress);
this.bgpPeer.instantiateServiceInstance();
BgpPeer.this.peerRegistry.addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
if (this.activeConnection) {
}
@Override
- public ListenableFuture<Void> closeServiceInstance() {
- LOG.info("Close Peer Singleton Service {}", getIdentifier());
+ public synchronized ListenableFuture<Void> closeServiceInstance() {
+ if(!this.isServiceInstantiated) {
+ LOG.info("Peer Singleton Service {} already closed, Peer {}", getIdentifier().getValue(),
+ this.neighborAddress);
+ return Futures.immediateFuture(null);
+ }
+ LOG.info("Close Peer Singleton Service {}, Peer {}", getIdentifier().getValue(), this.neighborAddress);
+ this.isServiceInstantiated = false;
if (this.connection != null) {
this.connection.cancel(true);
this.connection = null;