Replace Empty.getInstance() with Empty.value()
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightFlowTableStatisticsServiceImpl.java
index efc8e6fcb2e61e3c84c7c4373d50bd26c9431ab1..fbd7825ed0dea5f210df69fb757ced9fa0694fbb 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,16 +7,14 @@
  */
 package org.opendaylight.openflowplugin.impl.statistics.services;
 
-import java.util.ArrayList;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
-import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicLong;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 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.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.services.ServiceException;
+import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils;
 import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.AbstractCompatibleStatService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
@@ -28,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev13
 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;
@@ -39,10 +38,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 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;
+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
+        AbstractCompatibleStatService<GetFlowTablesStatisticsInput,
+        GetFlowTablesStatisticsOutput,
+        FlowTableStatisticsUpdate> implements
         OpendaylightFlowTableStatisticsService {
 
     private final NotificationPublishService notificationPublishService;
@@ -56,17 +59,18 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends
     }
 
     @Override
-    public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
+    public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
             final GetFlowTablesStatisticsInput input) {
         return handleAndNotify(input, notificationPublishService);
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) throws ServiceException {
+    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 MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder =
+                new MultipartRequestTableCaseBuilder();
         final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
-        multipartRequestTableBuilder.setEmpty(true);
+        multipartRequestTableBuilder.setEmpty(Empty.value());
         multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
 
         // Set request body to main multipart request
@@ -79,25 +83,25 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends
     }
 
     @Override
-    public GetFlowTablesStatisticsOutput buildTxCapableResult(TransactionId emulatedTxId) {
+    public GetFlowTablesStatisticsOutput buildTxCapableResult(final TransactionId emulatedTxId) {
         return new GetFlowTablesStatisticsOutputBuilder().setTransactionId(emulatedTxId).build();
     }
 
     @Override
-    public FlowTableStatisticsUpdate transformToNotification(List<MultipartReply> mpReplyList, TransactionId emulatedTxId) {
+    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 List<FlowTableAndStatisticsMap> salFlowStats = new ArrayList<>();
-        notification.setFlowTableAndStatisticsMap(salFlowStats);
+        final var salFlowStats = BindingMap.<FlowTableAndStatisticsMapKey, FlowTableAndStatisticsMap>orderedBuilder();
         for (MultipartReply mpReply : mpReplyList) {
             MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody();
             MultipartReplyTable replyBody = caseBody.getMultipartReplyTable();
-            List<TableStats> swTablesStats = replyBody.getTableStats();
 
-            for (TableStats swTableStats : swTablesStats) {
+            //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()));
@@ -107,6 +111,6 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends
             }
         }
 
-        return notification.build();
+        return notification.setFlowTableAndStatisticsMap(salFlowStats.build()).build();
     }
 }