SONAR TD - StatisticsContextImpl, StatisticsManagerImpl
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightFlowStatisticsServiceImpl.java
index 7879447c15176ee4db8e0164f0a4d56f7d9766ff..4d9a2b3ce16a452923cb6c7e0eca7d29b77265bc 100644 (file)
@@ -13,10 +13,13 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
+import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
@@ -34,22 +37,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * @author joe
  */
-public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService {
-    private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
+public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, Delegator<OpendaylightFlowStatisticsService> {
 
     private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
             new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
                 @Override
                 public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
-                    final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext();
-                    TranslatorLibrary translatorLibrary = deviceContext.oook();
-                    RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
+                    final DeviceInfo deviceInfo = matchingFlowsInTable.getDeviceInfo();
+                    final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
                     if (input.isSuccessful()) {
                         MultipartReply reply = input.getResult().get(0);
                         final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
@@ -57,7 +56,7 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
                         List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
 
                         for (MultipartReply multipartReply : input.getResult()) {
-                            aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
+                            aggregStats.add(messageTranslator.translate(multipartReply, deviceInfo, null));
                         }
 
                         GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
@@ -79,24 +78,38 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
                 }
     };
 
-    private final AggregateFlowsInTableService aggregateFlowsInTable;
     private final MatchingFlowsInTableService matchingFlowsInTable;
-    private final AllFlowsInAllTablesService allFlowsInAllTables;
-    private final AllFlowsInTableService allFlowsInTable;
-    private final FlowsInTableService flowsInTable;
-
-    public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
-        aggregateFlowsInTable = new AggregateFlowsInTableService(requestContextStack, deviceContext);
-        allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, deviceContext);
-        allFlowsInTable = new AllFlowsInTableService(requestContextStack, deviceContext);
-        flowsInTable = new FlowsInTableService(requestContextStack, deviceContext);
-        matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
+    private final TranslatorLibrary translatorLibrary;
+    private OpendaylightFlowStatisticsService delegate;
+
+    public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack,
+                                                              final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
+        return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook(), convertorExecutor);
+    }
+
+    public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
+                                                 final TranslatorLibrary translatorLibrary, final ConvertorExecutor convertorExecutor) {
+        matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext, convertorExecutor);
+        this.translatorLibrary = translatorLibrary;
+    }
+
+    @Override
+    public void setDelegate(OpendaylightFlowStatisticsService delegate) {
+        this.delegate = delegate;
     }
 
+    /**
+     * @deprecated provided for Be-release as backward compatibility relic
+     */
     @Override
+    @Deprecated
     public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
             final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
-        return aggregateFlowsInTable.handleServiceCall(input);
+        if (delegate != null) {
+            return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
+        } else {
+            throw new IllegalAccessError("no delegate available - service is currently out of order");
+        }
     }
 
     @Override
@@ -105,21 +118,45 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
         return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
     }
 
+    /**
+     * @deprecated provided for Be-release as backward compatibility relic
+     */
     @Override
+    @Deprecated
     public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
             final GetAllFlowStatisticsFromFlowTableInput input) {
-        return allFlowsInTable.handleServiceCall(input);
+        if (delegate != null) {
+            return delegate.getAllFlowStatisticsFromFlowTable(input);
+        } else {
+            throw new IllegalAccessError("no delegate available - service is currently out of order");
+        }
     }
 
+    /**
+     * @deprecated provided for Be-release as backward compatibility relic
+     */
     @Override
+    @Deprecated
     public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
             final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
-        return allFlowsInAllTables.handleServiceCall(input);
+        if (delegate != null) {
+            return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
+        } else {
+            throw new IllegalAccessError("no delegate available - service is currently out of order");
+        }
     }
 
+    /**
+     * @deprecated provided for Be-release as backward compatibility relic
+     */
     @Override
+    @Deprecated
     public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
             final GetFlowStatisticsFromFlowTableInput input) {
-        return flowsInTable.handleServiceCall(input);
+        if (delegate != null) {
+            return delegate.getFlowStatisticsFromFlowTable(input);
+        } else {
+            throw new IllegalAccessError("no delegate available - service is currently out of order");
+        }
     }
 }