Bump MRI upstreams
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / strategy / FlowForwarder.java
index 2609d576f7c62b2ff0e72cdded3b5617307cbf9c..f4c54b4def892f5e7864e29946fe131823594c8e 100644 (file)
@@ -8,8 +8,9 @@
 
 package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
 
-import com.google.common.base.Preconditions;
-import java.util.concurrent.Future;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesCommitter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -29,7 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRe
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
@@ -38,7 +39,8 @@ import org.slf4j.LoggerFactory;
 /**
  * Implements {@link ForwardingRulesCommitter} methods for processing add, update and remove of {@link Flow}.
  */
-public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutput, RemoveFlowOutput, UpdateFlowOutput> {
+public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutput, RemoveFlowOutput,
+        UpdateFlowOutput> {
 
     private static final Logger LOG = LoggerFactory.getLogger(FlowForwarder.class);
     private static final String TABLE_ID_MISMATCH = "tableId mismatch";
@@ -49,13 +51,13 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
     }
 
     @Override
-    public Future<RpcResult<RemoveFlowOutput>> remove(final InstanceIdentifier<Flow> identifier,
+    public ListenableFuture<RpcResult<RemoveFlowOutput>> remove(final InstanceIdentifier<Flow> identifier,
                                                       final Flow removeDataObj,
                                                       final InstanceIdentifier<FlowCapableNode> nodeIdent) {
         LOG.trace("Forwarding Flow REMOVE request Tbl id, node Id {} {}",
                 identifier, nodeIdent);
 
-        final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
+        final TableKey tableKey = identifier.firstKeyOf(Table.class);
         if (tableIdValidationPrecondition(tableKey, removeDataObj)) {
             final RemoveFlowInputBuilder builder = new RemoveFlowInputBuilder(removeDataObj);
             builder.setFlowRef(new FlowRef(identifier));
@@ -68,19 +70,19 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             return salFlowService.removeFlow(builder.build());
         } else {
             return RpcResultBuilder.<RemoveFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
+                    .withError(ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
     }
 
     @Override
-    public Future<RpcResult<UpdateFlowOutput>> update(final InstanceIdentifier<Flow> identifier,
+    public ListenableFuture<RpcResult<UpdateFlowOutput>> update(final InstanceIdentifier<Flow> identifier,
                                                       final Flow original, final Flow update,
                                                       final InstanceIdentifier<FlowCapableNode> nodeIdent) {
         LOG.trace("Forwarding Flow UPDATE request [Tbl id, node Id {} {} {}",
                 identifier, nodeIdent, update);
 
-        final Future<RpcResult<UpdateFlowOutput>> output;
-        final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
+        final ListenableFuture<RpcResult<UpdateFlowOutput>> output;
+        final TableKey tableKey = identifier.firstKeyOf(Table.class);
         if (tableIdValidationPrecondition(tableKey, update)) {
             final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
 
@@ -89,27 +91,27 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
 
             // always needs to set strict flag into update-flow input so that
             // only a flow entry associated with a given flow object is updated.
-            builder.setUpdatedFlow((new UpdatedFlowBuilder(update)).setStrict(Boolean.TRUE).build());
-            builder.setOriginalFlow((new OriginalFlowBuilder(original)).setStrict(Boolean.TRUE).build());
+            builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build());
+            builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build());
 
             output = salFlowService.updateFlow(builder.build());
         } else {
             output = RpcResultBuilder.<UpdateFlowOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
+                    .withError(ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
         }
 
         return output;
     }
 
     @Override
-    public Future<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier,
+    public ListenableFuture<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier,
                                                 final Flow addDataObj,
                                                 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
         LOG.trace("Forwarding the Flow ADD request [Tbl id, node Id {} {} {}",
                 identifier, nodeIdent, addDataObj);
 
-        final Future<RpcResult<AddFlowOutput>> output;
-        final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
+        final ListenableFuture<RpcResult<AddFlowOutput>> output;
+        final TableKey tableKey = identifier.firstKeyOf(Table.class);
         if (tableIdValidationPrecondition(tableKey, addDataObj)) {
             final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj);
 
@@ -118,14 +120,15 @@ public class FlowForwarder implements ForwardingRulesCommitter<Flow, AddFlowOutp
             builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
             output = salFlowService.addFlow(builder.build());
         } else {
-            output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
+            output = RpcResultBuilder.<AddFlowOutput>failed().withError(ErrorType.APPLICATION, TABLE_ID_MISMATCH)
+                .buildFuture();
         }
         return output;
     }
 
     private static boolean tableIdValidationPrecondition(final TableKey tableKey, final Flow flow) {
-        Preconditions.checkNotNull(tableKey, "TableKey can not be null or empty!");
-        Preconditions.checkNotNull(flow, "Flow can not be null or empty!");
+        requireNonNull(tableKey, "TableKey can not be null or empty!");
+        requireNonNull(flow, "Flow can not be null or empty!");
         if (!tableKey.getId().equals(flow.getTableId())) {
             LOG.warn("TableID in URI tableId={} and in payload tableId={} is not same.",
                     flow.getTableId(), tableKey.getId());