From f78c825bca62ce6f41967e92a45b004485b404c5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 19 May 2015 11:56:41 +0200 Subject: [PATCH] Do not keep per-switch state in DeviceManagerImpl 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 --- .../impl/device/DeviceManagerImpl.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java index 8daec910f0..c112b0e739 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java @@ -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 RequestContext createRequestContext() { - return new AbstractRequestContext(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>> getNodeStaticInfo(final MultipartType type, final DeviceContext deviceContext, + private static ListenableFuture>> getNodeStaticInfo(final MultipartType type, final DeviceContext deviceContext, final InstanceIdentifier nodeII, final short version) { final OutboundQueue queue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider(); - final RequestContext> requestContext = emptyRequestContextStack.createRequestContext(); + final Long reserved = deviceContext.getReservedXid(); + final RequestContext> requestContext = new AbstractRequestContext>(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>> 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 nodeII, final ListenableFuture>> requestContextFuture) { + private static void createSuccessProcessingCallback(final MultipartType type, final DeviceContext deviceContext, final InstanceIdentifier nodeII, final ListenableFuture>> requestContextFuture) { Futures.addCallback(requestContextFuture, new FutureCallback>>() { @Override public void onSuccess(final RpcResult> rpcResult) { @@ -502,7 +495,6 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable { @Override public void onDeviceContextClosed(final DeviceContext deviceContext) { deviceContexts.remove(deviceContext); - emptyRequestContextStack = null; } @Override -- 2.36.6