RpcContext extends RequestContextStack 46/17546/1
authorMartin Bobak <mbobak@cisco.com>
Wed, 1 Apr 2015 12:22:50 +0000 (14:22 +0200)
committerMartin Bobak <mbobak@cisco.com>
Wed, 1 Apr 2015 14:00:00 +0000 (16:00 +0200)
Change-Id: Ifa8ec430bc05ade99d0e88b149040526e06687d7
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/CommonService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/NodeConfigServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/OpendaylightMeterStatisticsServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java

index 2f51384c1307a484e049393ee0e492b0cd871978..7500bf7274b10bce4faf66c86618a7a5fb28eb24 100644 (file)
@@ -7,11 +7,10 @@
  */
 package org.opendaylight.openflowplugin.impl.rpc;
 
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-
 import com.google.common.util.concurrent.SettableFuture;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
@@ -20,18 +19,18 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
  */
 public class RequestContextImpl<T extends DataObject> implements RequestContext<T> {
 
-    private final RpcContext rpcContext;
+    private final RequestContextStack requestContextStack;
     private SettableFuture<RpcResult<T>> rpcResultFuture;
     private long waitTimeout;
     private Xid xid;
 
-    public RequestContextImpl(RpcContext rpcContext) {
-        this.rpcContext = rpcContext;
+    public RequestContextImpl(RequestContextStack requestContextStack) {
+        this.requestContextStack = requestContextStack;
     }
 
     @Override
     public void close() {
-        rpcContext.forgetRequestContext(this);
+        requestContextStack.forgetRequestContext(this);
     }
 
     @Override
index 74bd38d6997481c2552c3b7b76b2b5560685de04..e0cb08e84cf2d4cbee44292c95e85c643fd915f9 100644 (file)
@@ -32,6 +32,6 @@ public class RpcManagerImpl implements RpcManager {
     @Override
     public void deviceConnected(final DeviceContext deviceContext) {
         final RpcContext rpcContext = new RpcContextImpl(providerContext, deviceContext);
-        MdSalRegistratorUtils.registerServices(rpcContext);
+        MdSalRegistratorUtils.registerServices(rpcContext, deviceContext);
     }
 }
index c72a41742e7c886dd0fcd8ab2d5de11f3505dcf6..d945dfc63459c25a14d8f8855a20d0c2654b47ac 100644 (file)
@@ -8,43 +8,43 @@
 package org.opendaylight.openflowplugin.impl.services;
 
 import com.google.common.base.Function;
-import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import com.google.common.util.concurrent.Futures;
-import java.math.BigInteger;
-import java.util.concurrent.Future;
+import com.google.common.util.concurrent.SettableFuture;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
+import java.math.BigInteger;
+import java.util.concurrent.Future;
 
 public abstract class CommonService {
     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(CommonService.class);
     private static final long WAIT_TIME = 2000;
     protected final static Future<RpcResult<Void>> ERROR_RPC_RESULT = Futures.immediateFuture(RpcResultBuilder
-            .<Void> failed().withError(ErrorType.APPLICATION, "", "Request quota exceeded.").build());
+            .<Void>failed().withError(ErrorType.APPLICATION, "", "Request quota exceeded.").build());
     protected static final BigInteger PRIMARY_CONNECTION = new BigInteger("0");
 
     // protected OFRpcTaskContext rpcTaskContext;
     protected short version;
     protected BigInteger datapathId;
-    protected RpcContext rpcContext;
+    protected RequestContextStack requestContextStack;
     protected DeviceContext deviceContext;
     private ConnectionAdapter primaryConnectionAdapter;
 
     public CommonService() {
     }
 
-    public CommonService(final RpcContext rpcContext) {
-        this.rpcContext = rpcContext;
+    public CommonService(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
+        this.requestContextStack = requestContextStack;
 
-        this.deviceContext = rpcContext.getDeviceContext();
+        this.deviceContext = deviceContext;
         final FeaturesReply features = this.deviceContext.getPrimaryConnectionContext().getFeatures();
         this.datapathId = features.getDatapathId();
         this.version = features.getVersion();
@@ -75,12 +75,12 @@ public abstract class CommonService {
     }
 
     <T extends DataObject, F> Future<RpcResult<T>> handleServiceCall(final BigInteger connectionID,
-            final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
+                                                                     final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
         LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
 
-        final RequestContext<T> requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
-        final DataCrate<T> dataCrate = DataCrateBuilder.<T> builder().setiDConnection(connectionID)
+        final RequestContext<T> requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<T>> result = requestContextStack.storeOrFail(requestContext);
+        final DataCrate<T> dataCrate = DataCrateBuilder.<T>builder().setiDConnection(connectionID)
                 .setRequestContext(requestContext).build();
         if (!result.isDone()) {
             final Future<RpcResult<F>> resultFromOFLib = function.apply(dataCrate);
index f066b1d346255e3bdbac65949da686846966ede0..e08087d1d46b1b6b8bec00772de727e34f0e2960 100644 (file)
@@ -28,8 +28,8 @@ public class NodeConfigServiceImpl extends CommonService implements NodeConfigSe
 
     @Override
     public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
-        final RequestContext requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<SetConfigOutput>> result = rpcContext.storeOrFail(requestContext);
+        final RequestContext requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<SetConfigOutput>> result = requestContextStack.storeOrFail(requestContext);
         if (!result.isDone()) {
             SetConfigInputBuilder builder = new SetConfigInputBuilder();
             SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
index e83fd04a015096022b8886d780d2760f27f70125..9ef1a33e581cf8cdfa2a2da7d789b3cde238449e 100644 (file)
@@ -74,8 +74,8 @@ public class OpendaylightMeterStatisticsServiceImpl extends CommonService implem
 
     @Override
     public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
-        final RequestContext<GetAllMeterStatisticsOutput> requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = rpcContext.storeOrFail(requestContext);
+        final RequestContext<GetAllMeterStatisticsOutput> requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = requestContextStack.storeOrFail(requestContext);
 
         if (!result.isDone()) {
 
@@ -108,8 +108,8 @@ public class OpendaylightMeterStatisticsServiceImpl extends CommonService implem
 
     @Override
     public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
-        final RequestContext requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = rpcContext.storeOrFail(requestContext);
+        final RequestContext requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = requestContextStack.storeOrFail(requestContext);
 
         if (!result.isDone()) {
 
@@ -134,8 +134,8 @@ public class OpendaylightMeterStatisticsServiceImpl extends CommonService implem
 
     @Override
     public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
-        final RequestContext requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = rpcContext.storeOrFail(requestContext);
+        final RequestContext requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = requestContextStack.storeOrFail(requestContext);
 
         if (!result.isDone()) {
 
index b9839b18329041ebad6fb927ad43f51bdb3caf4e..c64bd717b9d7bc9a3298b472550683af5be68e5f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -44,16 +46,17 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
 
     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalFlowServiceImpl.class);
 
-    public SalFlowServiceImpl(final RpcContext rpcContext) {
-        super(rpcContext);
+
+    public SalFlowServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext);
     }
 
     <T extends DataObject, F> ListenableFuture<RpcResult<T>> handleServiceCall(final BigInteger connectionID,
             final FlowModInputBuilder flowModInputBuilder, final Function<DataCrate<T>, Future<RpcResult<F>>> function) {
         LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
 
-        final RequestContext<T> requestContext = rpcContext.createRequestContext();
-        final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
+        final RequestContext<T> requestContext = requestContextStack.createRequestContext();
+        final SettableFuture<RpcResult<T>> result = requestContextStack.storeOrFail(requestContext);
         final DataCrate<T> dataCrate = DataCrateBuilder.<T> builder().setiDConnection(connectionID)
                 .setRequestContext(requestContext).setFlowModInputBuilder(flowModInputBuilder).build();
 
index a5b4d9f04f11ec56ac74bd166f6f35b73666b983..aade6cd78b3e2c15ee077026be27dfb85c50e27c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.impl.util;
 
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.impl.services.NodeConfigServiceImpl;
 import org.opendaylight.openflowplugin.impl.services.OpendaylightFlowStatisticsServiceImpl;
@@ -42,8 +43,8 @@ public class MdSalRegistratorUtils {
         throw new IllegalStateException();
     }
 
-    public static void registerServices(final RpcContext rpcContext) {
-        rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext));
+    public static void registerServices(final RpcContext rpcContext, final DeviceContext deviceContext) {
+        rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext, deviceContext));
         rpcContext.registerRpcServiceImplementation(SalMeterService.class, new SalMeterServiceImpl());
         rpcContext.registerRpcServiceImplementation(SalGroupService.class, new SalGroupServiceImpl());
         rpcContext.registerRpcServiceImplementation(SalTableService.class, new SalTableServiceImpl());
index b4acfe13d42f4b47b90307ef10c56a0269584d63..b36070cb613eef64b6f1669fa32318f25e8910a6 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -12,9 +12,6 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.math.BigInteger;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Matchers;
@@ -32,6 +29,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalF
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import java.math.BigInteger;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 public class RpcManagerImplTest {
 
@@ -87,7 +87,7 @@ public class RpcManagerImplTest {
             ExecutionException {
         // TODO: how to invoke service remotely?
         final RpcContextImpl rpcContext = new RpcContextImpl(mockedProviderContext, mockedDeviceContext);
-        when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext));
+        when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext, mockedDeviceContext));
         rpcContext.setRequestContextQuota(capacity);
 
         final SalFlowService salFlowService = mockedProviderContext.getRpcService(SalFlowService.class);