Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / GetFlowTablesStatisticsImpl.java
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.openflowplugin.impl.statistics.services;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
@@ -20,21 +22,18 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatistics;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
@@ -42,44 +41,35 @@ import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public final class OpendaylightFlowTableStatisticsServiceImpl extends
-        AbstractCompatibleStatService<GetFlowTablesStatisticsInput,
-        GetFlowTablesStatisticsOutput,
-        FlowTableStatisticsUpdate> implements
-        OpendaylightFlowTableStatisticsService {
-
+@Deprecated
+public final class GetFlowTablesStatisticsImpl
+        extends AbstractCompatibleStatService<GetFlowTablesStatisticsInput, GetFlowTablesStatisticsOutput,
+                FlowTableStatisticsUpdate>
+        implements GetFlowTablesStatistics {
     private final NotificationPublishService notificationPublishService;
 
-    public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack,
-                                                      final DeviceContext deviceContext,
-                                                      final AtomicLong compatibilityXidSeed,
-                                                      final NotificationPublishService notificationPublishService) {
+    public GetFlowTablesStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
+            final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService) {
         super(requestContextStack, deviceContext, compatibilityXidSeed);
-        this.notificationPublishService = notificationPublishService;
+        this.notificationPublishService = requireNonNull(notificationPublishService);
     }
 
     @Override
-    public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
-            final GetFlowTablesStatisticsInput input) {
+    public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> invoke(final GetFlowTablesStatisticsInput input) {
         return handleAndNotify(input, notificationPublishService);
     }
 
     @Override
     protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) {
-        // Create multipart request body for fetch all the group stats
-        final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder =
-                new MultipartRequestTableCaseBuilder();
-        final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
-        multipartRequestTableBuilder.setEmpty(Empty.value());
-        multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
-
         // Set request body to main multipart request
-        final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
-                MultipartType.OFPMPTABLE, xid.getValue(), getVersion());
-
-        mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
-
-        return mprInput.build();
+        return RequestInputUtils.createMultipartHeader(MultipartType.OFPMPTABLE, xid.getValue(), getVersion())
+            // Create multipart request body for fetch all the group stats
+            .setMultipartRequestBody(new MultipartRequestTableCaseBuilder()
+                .setMultipartRequestTable(new MultipartRequestTableBuilder()
+                    .setEmpty(Empty.value())
+                    .build())
+                .build())
+            .build();
     }
 
     @Override
@@ -90,24 +80,23 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends
     @Override
     public FlowTableStatisticsUpdate transformToNotification(final List<MultipartReply> mpReplyList,
                                                              final TransactionId emulatedTxId) {
-        FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder();
-        notification.setId(getDeviceInfo().getNodeId());
-        notification.setMoreReplies(Boolean.FALSE);
-        notification.setTransactionId(emulatedTxId);
+        final var notification = new FlowTableStatisticsUpdateBuilder()
+            .setId(getDeviceInfo().getNodeId())
+            .setMoreReplies(Boolean.FALSE)
+            .setTransactionId(emulatedTxId);
 
         final var salFlowStats = BindingMap.<FlowTableAndStatisticsMapKey, FlowTableAndStatisticsMap>orderedBuilder();
-        for (MultipartReply mpReply : mpReplyList) {
-            MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody();
-            MultipartReplyTable replyBody = caseBody.getMultipartReplyTable();
+        for (var mpReply : mpReplyList) {
+            final var caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody();
 
             //TODO: Duplicate code: look at MultiReplyTranslatorUtil method translateTable
-            for (TableStats swTableStats : replyBody.nonnullTableStats()) {
-                FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder();
-                statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount()));
-                statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount()));
-                statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount()));
-                statisticsBuilder.setTableId(new TableId(swTableStats.getTableId()));
-                salFlowStats.add(statisticsBuilder.build());
+            for (var swTableStats : caseBody.getMultipartReplyTable().nonnullTableStats()) {
+                salFlowStats.add(new FlowTableAndStatisticsMapBuilder()
+                    .setActiveFlows(new Counter32(swTableStats.getActiveCount()))
+                    .setPacketsLookedUp(new Counter64(swTableStats.getLookupCount()))
+                    .setPacketsMatched(new Counter64(swTableStats.getMatchedCount()))
+                    .setTableId(new TableId(swTableStats.getTableId()))
+                    .build());
             }
         }