private static final Logger LOG = LoggerFactory.getLogger(HandshakeListenerImpl.class);
- private ConnectionContext connectionContext;
- private DeviceConnectedHandler deviceConnectedHandler;
+ private final ConnectionContext connectionContext;
+ private final DeviceConnectedHandler deviceConnectedHandler;
private HandshakeContext handshakeContext;
/**
* @param connectionContext
* @param deviceConnectedHandler
*/
- public HandshakeListenerImpl(ConnectionContext connectionContext, DeviceConnectedHandler deviceConnectedHandler) {
+ public HandshakeListenerImpl(final ConnectionContext connectionContext, final DeviceConnectedHandler deviceConnectedHandler) {
this.connectionContext = connectionContext;
this.deviceConnectedHandler = deviceConnectedHandler;
}
@Override
- public void onHandshakeSuccessfull(GetFeaturesOutput featureOutput, Short version) {
+ public void onHandshakeSuccessfull(final GetFeaturesOutput featureOutput, final Short version) {
LOG.debug("handshake succeeded: {}", connectionContext.getConnectionAdapter().getRemoteAddress());
closeHandshakeContext();
connectionContext.changeStateToWorking();
deviceConnectedHandler.deviceConnected(connectionContext);
SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.info("ConnectionContext initial processing failed: {}", e.getMessage());
SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_OFP);
- connectionContext.closeConnection(false);
+ connectionContext.closeConnection(true);
}
}
private void closeHandshakeContext() {
try {
handshakeContext.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Closing handshake context failed: {}", e.getMessage());
LOG.debug("Detail in hanshake context close:", e);
}
}
@Override
- public void setHandshakeContext(HandshakeContext handshakeContext) {
+ public void setHandshakeContext(final HandshakeContext handshakeContext) {
this.handshakeContext = handshakeContext;
}
}
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.FutureFallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.HashedWheelTimer;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.NotificationService;
return Futures.immediateFuture(null);
}
if (OfpRole.BECOMEMASTER.equals(role)) {
+ MdSalRegistratorUtils.registerMasterServices(getRpcContext(), DeviceContextImpl.this, role);
+ getRpcContext().registerStatCompatibilityServices();
if (!deviceState.deviceSynchronized()) {
//TODO: no necessary code for yet - it needs for initialization phase only
LOG.debug("Setup Empty TxManager {} for initialization phase", getDeviceState().getNodeId());
return Futures.immediateCheckedFuture(null);
}
/* Relevant for no initial Slave-to-Master scenario in cluster */
- return asyncClusterRoleChange(role);
+ final ListenableFuture<Void> deviceInitialization = asyncClusterRoleChange();
+ Futures.addCallback(deviceInitialization, new FutureCallback<Void>() {
+
+ @Override
+ public void onSuccess(@Nullable Void aVoid) {
+ //No operation
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOG.debug("Device {} init unexpected fail. Unregister RPCs", getDeviceState().getNodeId());
+ MdSalRegistratorUtils.unregisterServices(getRpcContext());
+ }
+
+ });
+
+ return deviceInitialization;
} else if (OfpRole.BECOMESLAVE.equals(role)) {
if (null != rpcContext) {
* check all NodeInformation for statistics otherwise statistics will not contains
* all possible MultipartTypes for polling in StatTypeList
*/
- private ListenableFuture<Void> asyncClusterRoleChange(final OfpRole role) {
+ private ListenableFuture<Void> asyncClusterRoleChange() {
if (statCtx == null) {
- final String errMsg = String.format("DeviceCtx {} is up but we are missing StatisticsContext", deviceState.getNodeId());
+ final String errMsg = String.format("DeviceCtx %s is up but we are missing StatisticsContext", deviceState.getNodeId());
LOG.warn(errMsg);
return Futures.immediateFailedFuture(new IllegalStateException(errMsg));
}
if (rpcContext == null) {
- final String errMsg = String.format("DeviceCtx {} is up but we are missing RpcContext", deviceState.getNodeId());
+ final String errMsg = String.format("DeviceCtx %s is up but we are missing RpcContext", deviceState.getNodeId());
LOG.warn(errMsg);
return Futures.immediateFailedFuture(new IllegalStateException(errMsg));
}
@Override
public Void apply(final Boolean input) {
if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
- final String errMsg = String.format("We lost connection for Device {}, context has to be closed.",
+ final String errMsg = String.format("We lost connection for Device %s, context has to be closed.",
getDeviceState().getNodeId());
LOG.warn(errMsg);
transactionChainManager.clearUnsubmittedTransaction();
throw new IllegalStateException(errMsg);
}
if (!input.booleanValue()) {
- final String errMsg = String.format("Get Initial Device {} information fails",
+ final String errMsg = String.format("Get Initial Device %s information fails",
getDeviceState().getNodeId());
LOG.warn(errMsg);
transactionChainManager.clearUnsubmittedTransaction();
LOG.debug("Get Initial Device {} information is successful", getDeviceState().getNodeId());
getDeviceState().setDeviceSynchronized(true);
transactionChainManager.activateTransactionManager();
- MdSalRegistratorUtils.registerMasterServices(getRpcContext(), DeviceContextImpl.this, role);
- getRpcContext().registerStatCompatibilityServices();
initialSubmitTransaction();
getDeviceState().setStatisticsPollingEnabledProp(true);
return null;
}
@Override
- public void close() {
+ public synchronized void close() {
LOG.debug("closing deviceContext: {}, nodeId:{}",
getPrimaryConnectionContext().getConnectionAdapter().getRemoteAddress(),
getDeviceState().getNodeId());
- tearDown();
-
- primaryConnectionContext.closeConnection(false);
+ if (deviceState.isValid()) {
+ primaryConnectionContext.closeConnection(false);
+ tearDown();
+ }
}
private synchronized void tearDown() {
}
}
- protected void tearDownClean() {
+ private void tearDownClean() {
LOG.info("Closing transaction chain manager without cleaning inventory operational");
- Preconditions.checkState(!deviceState.isValid());
transactionChainManager.close();
final LinkedList<DeviceContextClosedHandler> reversedCloseHandlers = new LinkedList<>(closeHandlers);