2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.connection;
10 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
11 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
12 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
13 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
14 import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
15 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
24 public class ConnectionContextImpl implements ConnectionContext {
26 private final ConnectionAdapter connectionAdapter;
27 private CONNECTION_STATE connectionState;
28 private FeaturesReply featuresReply;
29 private NodeId nodeId;
30 private DeviceDisconnectedHandler deviceDisconnectedHandler;
31 private static final Logger LOG = LoggerFactory.getLogger(ConnectionContextImpl.class);
32 private OutboundQueueProvider outboundQueueProvider;
33 private OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration;
36 * @param connectionAdapter
38 public ConnectionContextImpl(final ConnectionAdapter connectionAdapter) {
39 this.connectionAdapter = connectionAdapter;
43 public ConnectionAdapter getConnectionAdapter() {
44 return connectionAdapter;
48 public OutboundQueue getOutboundQueueProvider() {
49 return this.outboundQueueProvider;
53 public void setOutboundQueueProvider(final OutboundQueueProvider outboundQueueProvider) {
54 this.outboundQueueProvider = outboundQueueProvider;
58 public CONNECTION_STATE getConnectionState() {
59 return connectionState;
63 public NodeId getNodeId() {
68 public void setNodeId(final NodeId nodeId) {
73 public void setConnectionState(final CONNECTION_STATE connectionState) {
74 this.connectionState = connectionState;
78 public FeaturesReply getFeatures() {
83 public void setDeviceDisconnectedHandler(final DeviceDisconnectedHandler deviceDisconnectedHandler) {
84 this.deviceDisconnectedHandler = deviceDisconnectedHandler;
88 public void propagateClosingConnection() {
89 if (null != deviceDisconnectedHandler) {
90 LOG.trace("Populating connection closed event.");
91 this.deviceDisconnectedHandler.onDeviceDisconnected(this);
96 public void setFeatures(final FeaturesReply featuresReply) {
97 this.featuresReply = featuresReply;
101 public void close() {
102 if (getConnectionAdapter().isAlive()) {
103 setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
104 getConnectionAdapter().disconnect();
106 if (outboundQueueHandlerRegistration != null) {
107 outboundQueueHandlerRegistration.close();
108 outboundQueueHandlerRegistration = null;
113 public void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration) {
114 this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration;