/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- * <p/>
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.openflowplugin.impl.connection;
import java.math.BigInteger;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
public class ConnectionContextImpl implements ConnectionContext {
private final ConnectionAdapter connectionAdapter;
- private CONNECTION_STATE connectionState;
+ private volatile CONNECTION_STATE connectionState;
private FeaturesReply featuresReply;
private NodeId nodeId;
private DeviceDisconnectedHandler deviceDisconnectedHandler;
private static final Logger LOG = LoggerFactory.getLogger(ConnectionContextImpl.class);
private OutboundQueueProvider outboundQueueProvider;
private OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration;
+ private HandshakeContext handshakeContext;
/**
* @param connectionAdapter
connectionState = ConnectionContext.CONNECTION_STATE.RIP;
unregisterOutboundQueue();
+ closeHandshakeContext();
+
if (getConnectionAdapter().isAlive()) {
getConnectionAdapter().disconnect();
}
}
}
+ private void closeHandshakeContext() {
+ if (handshakeContext != null) {
+ try {
+ handshakeContext.close();
+ } catch (Exception e) {
+ LOG.info("handshake context closing failed: ", e);
+ } finally {
+ handshakeContext = null;
+ }
+ }
+ }
+
@Override
public void onConnectionClosed() {
if (null == nodeId){
getConnectionState());
unregisterOutboundQueue();
-
+ closeHandshakeContext();
propagateDeviceDisconnectedEvent();
}
}
@Override
- public void changeStateToHandshaking() {
+ public synchronized void changeStateToHandshaking() {
connectionState = CONNECTION_STATE.HANDSHAKING;
}
@Override
- public void changeStateToTimeouting() {
+ public synchronized void changeStateToTimeouting() {
connectionState = CONNECTION_STATE.TIMEOUTING;
}
@Override
- public void changeStateToWorking() {
+ public synchronized void changeStateToWorking() {
connectionState = CONNECTION_STATE.WORKING;
}
+
+ @Override
+ public void setHandshakeContext(HandshakeContext handshakeContext) {
+ this.handshakeContext = handshakeContext;
+ }
}