Remove unused routedRpcRegistration
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightFlowStatisticsServiceImpl.java
index 15b3f4f60ce51ec5f07eca40e75b2f6838a11f16..f6f9878fae456d9c2236e314ece201d142a7e415 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,22 +7,18 @@
  */
 package org.opendaylight.openflowplugin.impl.statistics.services;
 
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.Futures;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Future;
+import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-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.impl.services.multilayer.MultiLayerAggregateFlowMultipartService;
+import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerAggregateFlowMultipartService;
+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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
@@ -30,69 +26,31 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-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, Delegator<OpendaylightFlowStatisticsService> {
-
-    private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
-
-    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();
-                    final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
-                    if (input.isSuccessful()) {
-                        MultipartReply reply = input.getResult().get(0);
-                        final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
-                        final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
-                        List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
-
-                        for (MultipartReply multipartReply : input.getResult()) {
-                            aggregStats.add(messageTranslator.translate(multipartReply, deviceContext.getDeviceInfo(), null));
-                        }
-
-                        GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
-                                new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
-                        getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
-
-                        rpcResult = RpcResultBuilder
-                                .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
-                                .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
-                                .build();
-
-                    } else {
-                        rpcResult = RpcResultBuilder
-                                .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
-                                .withRpcErrors(input.getErrors())
-                                .build();
-                    }
-                    return rpcResult;
-                }
-    };
+public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService,
+                                                              Delegator<OpendaylightFlowStatisticsService> {
 
-    private final MatchingFlowsInTableService matchingFlowsInTable;
-    private final TranslatorLibrary translatorLibrary;
+    private final SingleLayerAggregateFlowMultipartService singleLayerService;
+    private final MultiLayerAggregateFlowMultipartService multiLayerService;
     private OpendaylightFlowStatisticsService delegate;
 
     public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack,
-                                                              final DeviceContext deviceContext) {
-        return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, deviceContext, deviceContext.oook());
+                                                                       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) {
-        matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
-        this.translatorLibrary = translatorLibrary;
+    public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack,
+                                                 final DeviceContext deviceContext,
+                                                 final TranslatorLibrary translatorLibrary,
+                                                 final ConvertorExecutor convertorExecutor) {
+        singleLayerService = new SingleLayerAggregateFlowMultipartService(requestContextStack, deviceContext);
+        multiLayerService = new MultiLayerAggregateFlowMultipartService(requestContextStack, deviceContext,
+            convertorExecutor, translatorLibrary);
     }
 
     @Override
@@ -101,12 +59,15 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
     }
 
     /**
-     * @deprecated provided for Be-release as backward compatibility relic
+     * Get aggregate statistics.
+     *
+     * @deprecated provided for Be-release as backward compatibility relic.
      */
     @Override
     @Deprecated
-    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
-            final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
+    public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>
+        getAggregateFlowStatisticsFromFlowTableForAllFlows(
+                final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
         if (delegate != null) {
             return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input);
         } else {
@@ -115,17 +76,22 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
     }
 
     @Override
-    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
-            final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
-        return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
+    public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>
+        getAggregateFlowStatisticsFromFlowTableForGivenMatch(
+                final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+        return singleLayerService.canUseSingleLayerSerialization()
+            ? singleLayerService.handleAndReply(input)
+            : multiLayerService.handleAndReply(input);
     }
 
     /**
-     * @deprecated provided for Be-release as backward compatibility relic
+     * Get flow statistics.
+     *
+     * @deprecated provided for Be-release as backward compatibility relic.
      */
     @Override
     @Deprecated
-    public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
+    public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
             final GetAllFlowStatisticsFromFlowTableInput input) {
         if (delegate != null) {
             return delegate.getAllFlowStatisticsFromFlowTable(input);
@@ -135,12 +101,14 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
     }
 
     /**
-     * @deprecated provided for Be-release as backward compatibility relic
+     * Get flow statistics.
+     *
+     * @deprecated provided for Be-release as backward compatibility relic.
      */
     @Override
     @Deprecated
-    public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
-            final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
+    public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>
+        getAllFlowsStatisticsFromAllFlowTables(final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
         if (delegate != null) {
             return delegate.getAllFlowsStatisticsFromAllFlowTables(input);
         } else {
@@ -149,11 +117,13 @@ public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowSt
     }
 
     /**
-     * @deprecated provided for Be-release as backward compatibility relic
+     * Get flow statistics.
+     *
+     * @deprecated provided for Be-release as backward compatibility relic.
      */
     @Override
     @Deprecated
-    public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
+    public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
             final GetFlowStatisticsFromFlowTableInput input) {
         if (delegate != null) {
             return delegate.getFlowStatisticsFromFlowTable(input);