Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / batch / FlatBatchFlowAdapters.java
index 7949cc0094d1c5142bb1287213a8c9df54b520b6..ef734d242f4df4ccb4062c4b41acb9167a2cae07 100644 (file)
@@ -11,12 +11,10 @@ package org.opendaylight.openflowplugin.impl.services.batch;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.Future;
-import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlow;
@@ -45,18 +43,19 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
 /**
- * transform between FlatBatch API and flow batch API
+ * Transform between FlatBatch API and flow batch API.
  */
-public class FlatBatchFlowAdapters {
+public final class FlatBatchFlowAdapters {
 
     private FlatBatchFlowAdapters() {
-        throw new IllegalStateException("This class should not be instantiated.");
     }
 
     /**
+     * Adapt flat batch add flow.
      * @param planStep batch step containing changes of the same type
      * @param node     pointer for RPC routing
-     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService#addFlowsBatch(AddFlowsBatchInput)}
+     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
+     * .opendaylight.flows.service.rev160314.SalFlowsBatchService#addFlowsBatch(AddFlowsBatchInput)}
      */
     public static AddFlowsBatchInput adaptFlatBatchAddFlow(final BatchPlanStep planStep, final NodeRef node) {
         final List<BatchAddFlows> batchFlows = new ArrayList<>();
@@ -75,9 +74,11 @@ public class FlatBatchFlowAdapters {
     }
 
     /**
+     * Adapt flat batch remove flow.
      * @param planStep batch step containing changes of the same type
      * @param node     pointer for RPC routing
-     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService#removeFlowsBatch(RemoveFlowsBatchInput)}
+     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
+     * .opendaylight.flows.service.rev160314.SalFlowsBatchService#removeFlowsBatch(RemoveFlowsBatchInput)}
      */
     public static RemoveFlowsBatchInput adaptFlatBatchRemoveFlow(final BatchPlanStep planStep, final NodeRef node) {
         final List<BatchRemoveFlows> batchFlows = new ArrayList<>();
@@ -96,9 +97,11 @@ public class FlatBatchFlowAdapters {
     }
 
     /**
+     * Adapt flat batch update flow.
      * @param planStep batch step containing changes of the same type
      * @param node     pointer for RPC routing
-     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService#updateFlowsBatch(UpdateFlowsBatchInput)}
+     * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
+     * .opendaylight.flows.service.rev160314.SalFlowsBatchService#updateFlowsBatch(UpdateFlowsBatchInput)}
      */
     public static UpdateFlowsBatchInput adaptFlatBatchUpdateFlow(final BatchPlanStep planStep, final NodeRef node) {
         final List<BatchUpdateFlows> batchFlows = new ArrayList<>();
@@ -116,23 +119,21 @@ public class FlatBatchFlowAdapters {
     }
 
     /**
+     * Convert batch result.
      * @param stepOffset offset of current batch plan step
      * @return converted {@link ProcessFlatBatchOutput} RPC result
      */
     @VisibleForTesting
     static <T extends BatchFlowOutputListGrouping> Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>>
-    convertBatchFlowResult(final int stepOffset) {
-        return new Function<RpcResult<T>, RpcResult<ProcessFlatBatchOutput>>() {
-            @Nullable
-            @Override
-            public RpcResult<ProcessFlatBatchOutput> apply(@Nullable final RpcResult<T> input) {
-                List<BatchFailure> batchFailures = wrapBatchFlowFailuresForFlat(input, stepOffset);
-                ProcessFlatBatchOutputBuilder outputBuilder = new ProcessFlatBatchOutputBuilder().setBatchFailure(batchFailures);
-                return RpcResultBuilder.<ProcessFlatBatchOutput>status(input.isSuccessful())
-                                       .withRpcErrors(input.getErrors())
-                                       .withResult(outputBuilder.build())
-                                       .build();
-            }
+        convertBatchFlowResult(final int stepOffset) {
+        return input -> {
+            List<BatchFailure> batchFailures = wrapBatchFlowFailuresForFlat(input, stepOffset);
+            ProcessFlatBatchOutputBuilder outputBuilder =
+                    new ProcessFlatBatchOutputBuilder().setBatchFailure(batchFailures);
+            return RpcResultBuilder.<ProcessFlatBatchOutput>status(input.isSuccessful())
+                                   .withRpcErrors(input.getErrors())
+                                   .withResult(outputBuilder.build())
+                                   .build();
         };
     }
 
@@ -140,9 +141,9 @@ public class FlatBatchFlowAdapters {
             final RpcResult<T> input, final int stepOffset) {
         final List<BatchFailure> batchFailures = new ArrayList<>();
         if (input.getResult().getBatchFailedFlowsOutput() != null) {
-            for (BatchFailedFlowsOutput stepOutput : input.getResult().getBatchFailedFlowsOutput()) {
+            for (BatchFailedFlowsOutput stepOutput : input.getResult().nonnullBatchFailedFlowsOutput().values()) {
                 final BatchFailure batchFailure = new BatchFailureBuilder()
-                        .setBatchOrder(stepOffset + stepOutput.getBatchOrder())
+                        .setBatchOrder(stepOffset + stepOutput.getBatchOrder().toJava())
                         .setBatchItemIdChoice(new FlatBatchFailureFlowIdCaseBuilder()
                                 .setFlowId(stepOutput.getFlowId())
                                 .build())
@@ -154,7 +155,7 @@ public class FlatBatchFlowAdapters {
     }
 
     /**
-     * shortcut for {@link #convertBatchFlowResult(int)} with conversion {@link ListenableFuture}
+     * Shortcut for {@link #convertBatchFlowResult(int)} with conversion {@link ListenableFuture}.
      *
      * @param <T>                    exact type of batch flow output
      * @param resultUpdateFlowFuture batch flow rpc-result (add/remove/update)
@@ -162,9 +163,9 @@ public class FlatBatchFlowAdapters {
      * @return ListenableFuture with converted result {@link ProcessFlatBatchOutput}
      */
     public static <T extends BatchFlowOutputListGrouping> ListenableFuture<RpcResult<ProcessFlatBatchOutput>>
-    convertFlowBatchFutureForChain(final Future<RpcResult<T>> resultUpdateFlowFuture,
+        convertFlowBatchFutureForChain(final ListenableFuture<RpcResult<T>> resultUpdateFlowFuture,
                                    final int currentOffset) {
-        return Futures.transform(JdkFutureAdapters.listenInPoolThread(resultUpdateFlowFuture),
-                FlatBatchFlowAdapters.<T>convertBatchFlowResult(currentOffset));
+        return Futures.transform(resultUpdateFlowFuture, FlatBatchFlowAdapters.convertBatchFlowResult(currentOffset),
+                MoreExecutors.directExecutor());
     }
 }