LOG.debug("Final phase of DeviceContextLevelUp for Node: {} ", deviceInfo.getNodeId());
DeviceContext deviceContext = Preconditions.checkNotNull(deviceContexts.get(deviceInfo));
deviceContext.onPublished();
+ lifecycleService.registerDeviceRemovedHandler(this);
lifecycleService.registerService(this.singletonServiceProvider);
}
@Override
public ConnectionStatus deviceConnected(@CheckForNull final ConnectionContext connectionContext) throws Exception {
Preconditions.checkArgument(connectionContext != null);
+ final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
- DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
/*
* This part prevent destroy another device context. Throwing here an exception result to propagate close connection
* in {@link org.opendaylight.openflowplugin.impl.connection.org.opendaylight.openflowplugin.impl.connection.HandshakeContextImpl}
connectionContext.getConnectionAdapter().getRemoteAddress(), deviceInfo.getNodeId());
// Add Disconnect handler
- connectionContext.setDeviceDisconnectedHandler(DeviceManagerImpl.this);
+ connectionContext.setDeviceDisconnectedHandler(this);
+
// Cache this for clarity
final ConnectionAdapter connectionAdapter = connectionContext.getConnectionAdapter();
- //FIXME: as soon as auxiliary connection are fully supported then this is needed only before device context published
+ // FIXME: as soon as auxiliary connection are fully supported then this is needed only before device context published
connectionAdapter.setPacketInFiltering(true);
final OutboundQueueProvider outboundQueueProvider = new OutboundQueueProviderImpl(deviceInfo.getVersion());
@Override
public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
-
- LifecycleService lifecycleService = lifecycleServices.remove(deviceInfo);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Lifecycle service removed for node {}", deviceInfo.getLOGValue());
- }
-
updatePacketInRateLimiters();
- if (Objects.nonNull(lifecycleService)) {
- try {
- lifecycleService.close();
- LOG.debug("Lifecycle service successfully closed for node {}", deviceInfo.getLOGValue());
- } catch (Exception e) {
- LOG.warn("Closing lifecycle service for node {} was unsuccessful ", deviceInfo.getLOGValue(), e);
- }
- }
-
- deviceContexts.remove(deviceInfo);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
- }
-
+ Optional.ofNullable(lifecycleServices.get(deviceInfo)).ifPresent(OFPContext::close);
}
@Override
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
final DeviceContext deviceCtx = this.deviceContexts.get(deviceInfo);
- if (null == deviceCtx) {
+ if (Objects.isNull(deviceCtx)) {
LOG.info("DeviceContext for Node {} was not found. Connection is terminated without OFP context suite.", deviceInfo.getLOGValue());
return;
}
return;
}
- deviceCtx.setState(OFPContext.CONTEXT_STATE.TERMINATION);
+ deviceCtx.close();
if (!connectionContext.equals(deviceCtx.getPrimaryConnectionContext())) {
LOG.debug("Node {} disconnected, but not primary connection.", connectionContext.getDeviceInfo().getLOGValue());
- /* Connection is not PrimaryConnection so try to remove from Auxiliary Connections */
+ // Connection is not PrimaryConnection so try to remove from Auxiliary Connections
deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
}
- //TODO: Auxiliary connections supported ?
- /* Device is disconnected and so we need to close TxManager */
+
+ // TODO: Auxiliary connections supported ?
+ // Device is disconnected and so we need to close TxManager
final ListenableFuture<Void> future = deviceCtx.shuttingDownDataStoreTransactions();
Futures.addCallback(future, new FutureCallback<Void>() {
-
@Override
public void onSuccess(final Void result) {
LOG.debug("TxChainManager for device {} is closed successful.", deviceInfo.getLOGValue());
deviceTerminPhaseHandler.onDeviceContextLevelDown(deviceInfo);
}
});
- /* Add timer for Close TxManager because it could fain ind cluster without notification */
+
+ // Add timer for Close TxManager because it could fail in cluster without notification
final TimerTask timerTask = timeout -> {
if (!future.isDone()) {
LOG.warn("Shutting down TxChain for node {} not completed during 10 sec. Continue anyway.", deviceInfo.getLOGValue());
future.cancel(false);
}
};
+
hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
}
}
}
- @VisibleForTesting
- void setDeviceContext(final DeviceInfo deviceInfo, final DeviceContext deviceContext) {
- this.deviceContexts.putIfAbsent(deviceInfo, deviceContext);
- }
+ public void onDeviceRemoved(DeviceInfo deviceInfo) {
+ deviceContexts.remove(deviceInfo);
+ LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
- @VisibleForTesting
- int getDeviceContextCount() {
- return this.deviceContexts.size();
+ lifecycleServices.remove(deviceInfo);
+ LOG.debug("Lifecycle service removed for node {}", deviceInfo.getLOGValue());
}
-
-
}