Speed up packetin throttling
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionContextImpl.java
index a35671c6b477606400b844d89e2e53d27f26af3b..0453c23eef920b9e0ad7f62d2e7a1e12024f2127 100644 (file)
@@ -1,37 +1,42 @@
 /**
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- * 
+ *
  * 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 com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collection;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+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.MultiMsgCollector;
+import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
+import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  */
 public class ConnectionContextImpl implements ConnectionContext {
 
     private final ConnectionAdapter connectionAdapter;
     private CONNECTION_STATE connectionState;
     private FeaturesReply featuresReply;
-    private final MultiMsgCollector multipartCollector;
+    private NodeId nodeId;
+    private DeviceDisconnectedHandler deviceDisconnectedHandler;
+    private static final Logger LOG = LoggerFactory.getLogger(ConnectionContextImpl.class);
+    private OutboundQueueProvider outboundQueueProvider;
+    private OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration;
 
     /**
      * @param connectionAdapter
      */
     public ConnectionContextImpl(final ConnectionAdapter connectionAdapter) {
         this.connectionAdapter = connectionAdapter;
-        multipartCollector = new MultiMsgCollectorImpl();
     }
 
     @Override
@@ -39,6 +44,16 @@ public class ConnectionContextImpl implements ConnectionContext {
         return connectionAdapter;
     }
 
+    @Override
+    public OutboundQueue getOutboundQueueProvider() {
+        return this.outboundQueueProvider;
+    }
+
+    @Override
+    public void setOutboundQueueProvider(final OutboundQueueProvider outboundQueueProvider) {
+        this.outboundQueueProvider = outboundQueueProvider;
+    }
+
     @Override
     public CONNECTION_STATE getConnectionState() {
         return connectionState;
@@ -46,8 +61,12 @@ public class ConnectionContextImpl implements ConnectionContext {
 
     @Override
     public NodeId getNodeId() {
-        // TODO Auto-generated method stub
-        return null;
+        return nodeId;
+    }
+
+    @Override
+    public void setNodeId(final NodeId nodeId) {
+        this.nodeId = nodeId;
     }
 
     @Override
@@ -60,19 +79,38 @@ public class ConnectionContextImpl implements ConnectionContext {
         return featuresReply;
     }
 
+    @Override
+    public void setDeviceDisconnectedHandler(final DeviceDisconnectedHandler deviceDisconnectedHandler) {
+        this.deviceDisconnectedHandler = deviceDisconnectedHandler;
+    }
+
+    @Override
+    public void propagateClosingConnection() {
+        if (null != deviceDisconnectedHandler) {
+            LOG.trace("Populating connection closed event.");
+            this.deviceDisconnectedHandler.onDeviceDisconnected(this);
+        }
+    }
+
     @Override
     public void setFeatures(final FeaturesReply featuresReply) {
         this.featuresReply = featuresReply;
-
     }
 
     @Override
-    public ListenableFuture<Collection<MultipartReply>> registerMultipartMsg(final long xid) {
-        return multipartCollector.registerMultipartMsg(xid);
+    public void close() {
+        if (getConnectionAdapter().isAlive()) {
+            setConnectionState(ConnectionContext.CONNECTION_STATE.RIP);
+            getConnectionAdapter().disconnect();
+        }
+        if (outboundQueueHandlerRegistration != null) {
+            outboundQueueHandlerRegistration.close();
+            outboundQueueHandlerRegistration = null;
+        }
     }
 
     @Override
-    public void addMultipartMsg(final MultipartReply reply) {
-        multipartCollector.addMultipartMsg(reply);
+    public void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration) {
+        this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration;
     }
 }