Do not keep per-switch state in DeviceManagerImpl 10/20710/1
authorRobert Varga <rovarga@cisco.com>
Tue, 19 May 2015 09:56:41 +0000 (11:56 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 19 May 2015 09:58:31 +0000 (11:58 +0200)
All per-device state is encapsulated in a DeviceContext, keeping a
provider as a field breaks thread-safety, as it is changed on each
request.

Change-Id: I60e818cee662f2f952e5435ff2e9ba9d1c98d053
Signed-off-by: Robert Varga <rovarga@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java

index 8daec910f0a12fc93084cfc8cd779f05bc3f6d2e..c112b0e7393bcccd03267a2572a74ab530dbba26 100644 (file)
@@ -39,7 +39,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
@@ -109,7 +108,6 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
 
     private final DataBroker dataBroker;
     private final HashedWheelTimer hashedWheelTimer;
-    private RequestContextStack emptyRequestContextStack;
     private TranslatorLibrary translatorLibrary;
     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
     private NotificationService notificationService;
@@ -170,18 +168,6 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
         deviceContext.setTranslatorLibrary(translatorLibrary);
         deviceContext.addDeviceContextClosedHandler(this);
 
-        emptyRequestContextStack = new RequestContextStack() {
-            @Override
-            public <T> RequestContext<T> createRequestContext() {
-                return new AbstractRequestContext<T>(deviceContext.getReservedXid()) {
-                    @Override
-                    public void close() {
-                        //NOOP
-                    }
-                };
-            }
-        };
-
         final OpenflowProtocolListenerFullImpl messageListener = new OpenflowProtocolListenerFullImpl(
                 connectionContext.getConnectionAdapter(), deviceContext);
 
@@ -316,15 +302,22 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
         this.translatorLibrary = translatorLibrary;
     }
 
-    private ListenableFuture<RpcResult<List<MultipartReply>>> getNodeStaticInfo(final MultipartType type, final DeviceContext deviceContext,
+    private static ListenableFuture<RpcResult<List<MultipartReply>>> getNodeStaticInfo(final MultipartType type, final DeviceContext deviceContext,
                                                                                 final InstanceIdentifier<Node> nodeII, final short version) {
 
         final OutboundQueue queue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
 
-        final RequestContext<List<MultipartReply>> requestContext = emptyRequestContextStack.createRequestContext();
+        final Long reserved = deviceContext.getReservedXid();
+        final RequestContext<List<MultipartReply>> requestContext = new AbstractRequestContext<List<MultipartReply>>(reserved) {
+            @Override
+            public void close() {
+                //NOOP
+            }
+        };
+
         final Xid xid = requestContext.getXid();
 
-        LOG.trace("Hooking xid {} to device context - precaution.", requestContext.getXid().getValue());
+        LOG.trace("Hooking xid {} to device context - precaution.", reserved);
 
         final ListenableFuture<RpcResult<List<MultipartReply>>> requestContextFuture = requestContext.getFuture();
 
@@ -359,7 +352,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
         return requestContext.getFuture();
     }
 
-    private void createSuccessProcessingCallback(final MultipartType type, final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeII, final ListenableFuture<RpcResult<List<MultipartReply>>> requestContextFuture) {
+    private static void createSuccessProcessingCallback(final MultipartType type, final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeII, final ListenableFuture<RpcResult<List<MultipartReply>>> requestContextFuture) {
         Futures.addCallback(requestContextFuture, new FutureCallback<RpcResult<List<MultipartReply>>>() {
             @Override
             public void onSuccess(final RpcResult<List<MultipartReply>> rpcResult) {
@@ -502,7 +495,6 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
     @Override
     public void onDeviceContextClosed(final DeviceContext deviceContext) {
         deviceContexts.remove(deviceContext);
-        emptyRequestContextStack = null;
     }
 
     @Override