public synchronized ListenableFuture<Void> closeServiceInstance() {
this.scheduleTask.cancel(true);
final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
- this.instanceIdentifiersCache.keySet().forEach(ribId -> removeStoredOperationalState(ribId, wTx));
- final CheckedFuture<Void, TransactionCommitFailedException> futureDelete = wTx.submit();
+ this.instanceIdentifiersCache.keySet().iterator()
+ .forEachRemaining(ribId -> removeStoredOperationalState(ribId, wTx));
+ final ListenableFuture<Void> futureDelete = wTx.submit();
this.transactionChain.close();
return futureDelete;
}
public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
private static final Logger LOG = LoggerFactory.getLogger(AppPeer.class);
private static final QName APP_ID_QNAME = QName.create(ApplicationRib.QNAME, "id").intern();
+ @GuardedBy("this")
private Neighbor currentConfiguration;
+ @GuardedBy("this")
private BgpAppPeerSingletonService bgpAppPeerSingletonService;
+ @GuardedBy("this")
private ServiceRegistration<?> serviceRegistration;
@Override
- public void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
+ public synchronized void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
final WriteConfiguration configurationWriter) {
Preconditions.checkState(this.bgpAppPeerSingletonService == null, "Previous peer instance was not closed.");
this.currentConfiguration = neighbor;
}
@Override
- public void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ public synchronized void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.currentConfiguration != null);
start(rib, this.currentConfiguration, tableTypeRegistry, null);
}
@Override
- public void close() {
- try {
- this.bgpAppPeerSingletonService.close();
- this.bgpAppPeerSingletonService = null;
- } catch (final Exception e) {
- LOG.warn("Failed to close application peer instance", e);
+ 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);
+ }
}
if (this.serviceRegistration != null) {
this.serviceRegistration.unregister();
}
@Override
- public ListenableFuture<Void> closeServiceInstance() {
+ public synchronized ListenableFuture<Void> closeServiceInstance() {
if (this.bgpAppPeerSingletonService != null) {
return this.bgpAppPeerSingletonService.closeServiceInstance();
}
return this.bgpAppPeerSingletonService.getPeerState();
}
- void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
+ synchronized void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
this.serviceRegistration = serviceRegistration;
}
return this.applicationPeer.getPeerState();
}
}
-}
\ No newline at end of file
+}
private static final Logger LOG = LoggerFactory.getLogger(BgpPeer.class);
private final RpcProviderRegistry rpcRegistry;
+ @GuardedBy("this")
private ServiceRegistration<?> serviceRegistration;
+ @GuardedBy("this")
private Neighbor currentConfiguration;
+ @GuardedBy("this")
private BgpPeerSingletonService bgpPeerSingletonService;
public BgpPeer(final RpcProviderRegistry rpcRegistry) {
}
@Override
- public void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
+ public synchronized void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
final WriteConfiguration configurationWriter) {
Preconditions.checkState(this.bgpPeerSingletonService == null, "Previous peer instance was not closed.");
this.bgpPeerSingletonService = new BgpPeerSingletonService(rib, neighbor, tableTypeRegistry, configurationWriter);
}
@Override
- public void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ public synchronized void restart(final RIB rib, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
Preconditions.checkState(this.currentConfiguration != null);
start(rib, this.currentConfiguration, tableTypeRegistry, null);
}
@Override
- public void close() {
+ public synchronized void close() {
closeSingletonService();
if (this.serviceRegistration != null) {
this.serviceRegistration.unregister();
}
@Override
- public ListenableFuture<Void> closeServiceInstance() {
+ public synchronized ListenableFuture<Void> closeServiceInstance() {
if (this.bgpPeerSingletonService != null) {
return this.bgpPeerSingletonService.closeServiceInstance();
}
}
private void closeSingletonService() {
- try {
- this.bgpPeerSingletonService.close();
- this.bgpPeerSingletonService = null;
- } catch (final Exception e) {
- LOG.warn("Failed to close peer instance", e);
+ if (this.bgpPeerSingletonService != null) {
+ try {
+ this.bgpPeerSingletonService.close();
+ this.bgpPeerSingletonService = null;
+ } catch (final Exception e) {
+ LOG.warn("Failed to close peer instance", e);
+ }
}
}
return this.bgpPeerSingletonService.getPeerState();
}
- void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
+ synchronized void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
this.serviceRegistration = serviceRegistration;
}