Merge "Improving logging in DeviceContext and MultiMsgCollector."
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionContextImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.connection;
9
10 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
11 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  *
20  */
21 public class ConnectionContextImpl implements ConnectionContext {
22
23     private final ConnectionAdapter connectionAdapter;
24     private CONNECTION_STATE connectionState;
25     private FeaturesReply featuresReply;
26     private NodeId nodeId;
27     private DeviceDisconnectedHandler deviceDisconnectedHandler;
28     private static final Logger LOG = LoggerFactory.getLogger(ConnectionContextImpl.class);
29
30     /**
31      * @param connectionAdapter
32      */
33     public ConnectionContextImpl(final ConnectionAdapter connectionAdapter) {
34         this.connectionAdapter = connectionAdapter;
35     }
36
37     @Override
38     public ConnectionAdapter getConnectionAdapter() {
39         return connectionAdapter;
40     }
41
42     @Override
43     public CONNECTION_STATE getConnectionState() {
44         return connectionState;
45     }
46
47     @Override
48     public NodeId getNodeId() {
49         return nodeId;
50     }
51
52     @Override
53     public void setNodeId(final NodeId nodeId) {
54         this.nodeId = nodeId;
55     }
56
57     @Override
58     public void setConnectionState(final CONNECTION_STATE connectionState) {
59         this.connectionState = connectionState;
60     }
61
62     @Override
63     public FeaturesReply getFeatures() {
64         return featuresReply;
65     }
66
67     @Override
68     public void setDeviceDisconnectedHandler(final DeviceDisconnectedHandler deviceDisconnectedHandler) {
69         this.deviceDisconnectedHandler = deviceDisconnectedHandler;
70     }
71
72     @Override
73     public void propagateClosingConnection() {
74         if (null != deviceDisconnectedHandler) {
75             LOG.trace("Populating connection closed event.");
76             this.deviceDisconnectedHandler.onDeviceDisconnected(this);
77         }
78     }
79
80     @Override
81     public void setFeatures(final FeaturesReply featuresReply) {
82         this.featuresReply = featuresReply;
83     }
84 }