device context holds OQHandler registration 37/20837/3
authorMartin Bobak <mbobak@cisco.com>
Wed, 20 May 2015 15:56:23 +0000 (17:56 +0200)
committerMartin Bobak <mbobak@cisco.com>
Thu, 21 May 2015 10:31:23 +0000 (12:31 +0200)
Handler registration is closed when device context is closed.

Change-Id: Ib4a58c943789c5505542858767e5b6311bea3f3b
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java

index 4ef9946a94d86854601ddaf7b8b299c9007db835..de5669500b410af82038d45793aa07b6212c123b 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
@@ -172,5 +173,12 @@ public interface DeviceContext extends AutoCloseable,
      */
     void onPublished();
 
+
+    /**
+     * Method registers outbound queue handler that should be invalidated when device context is closed.s
+     * @param outboundQueueHandlerRegistration
+     */
+    void registerOutboundQueueHandler(OutboundQueueHandlerRegistration outboundQueueHandlerRegistration);
+
 }
 
index e09a5c6e048e99c4daee9eee1262cacdfdd3acbd..de860f7e18dacd5a24627275a40153d86ed9e16e 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
@@ -107,6 +108,7 @@ public class DeviceContextImpl implements DeviceContext {
     private volatile boolean filteringPacketIn = false;
     private final Object throttlingLock = new Object();
     private int filteringHighWaterMark = 0;
+    private OutboundQueueHandlerRegistration outboundQueueHandlerRegistration;
 
     @Override
     public MultiMsgCollector getMultiMsgCollector() {
@@ -348,6 +350,8 @@ public class DeviceContextImpl implements DeviceContext {
     public void close() {
         deviceState.setValid(false);
 
+        outboundQueueHandlerRegistration.close();
+
         LOG.trace("Removing node {} from operational DS.", getDeviceState().getNodeId());
         addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, getDeviceState().getNodeInstanceIdentifier());
 
@@ -438,4 +442,9 @@ public class DeviceContextImpl implements DeviceContext {
             switchAuxConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
         }
     }
+
+    @Override
+    public void registerOutboundQueueHandler(final OutboundQueueHandlerRegistration outboundQueueHandlerRegistration) {
+        this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration;
+    }
 }
index da40934d3d76c9e3deab6057a4bfb76957ffcf15..358473e3283db983221723db30616f74dae1bf01 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 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.ConnectionException;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
@@ -167,14 +168,13 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
         final Short version = connectionContext.getFeatures().getVersion();
         OutboundQueueProvider outboundQueueProvider = new OutboundQueueProviderImpl(version);
 
-        // FIXME: we are losing registration, we should be registering in the connection context
-        connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos);
+        final OutboundQueueHandlerRegistration outboundQueueHandlerRegistration = connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos);
         connectionContext.setOutboundQueueProvider(outboundQueueProvider);
 
         final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId());
 
         final DeviceContext deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, hashedWheelTimer, messageIntelligenceAgency);
-
+        deviceContext.registerOutboundQueueHandler(outboundQueueHandlerRegistration);
         deviceContext.setNotificationService(notificationService);
         deviceContext.setNotificationPublishService(notificationPublishService);
         NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceState.getNodeId()).setNodeConnector(Collections.<NodeConnector>emptyList());
@@ -264,7 +264,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
 
 
     private static ListenableFuture<List<RpcResult<List<MultipartReply>>>> createDeviceFeaturesForOF10(final DeviceContext deviceContext,
-                                                                                                final DeviceState deviceState) {
+                                                                                                       final DeviceState deviceState) {
         final ListenableFuture<RpcResult<List<MultipartReply>>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC,
                 deviceContext,
                 deviceState.getNodeInstanceIdentifier(),
@@ -274,7 +274,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
     }
 
     private static ListenableFuture<List<RpcResult<List<MultipartReply>>>> createDeviceFeaturesForOF13(final DeviceContext deviceContext,
-                                                                                                final DeviceState deviceState) {
+                                                                                                       final DeviceState deviceState) {
 
         final ListenableFuture<RpcResult<List<MultipartReply>>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC,
                 deviceContext,