Fix checkstyle API.
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OFRpcTaskUtil.java
index 58211395291518639a7d9efe428e19e289c83a1f..be7295dbc4761c2342ca2bc0b37e4179146a0a0a 100644 (file)
@@ -7,22 +7,26 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
+import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Future;
-
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer;
-import org.opendaylight.openflowplugin.api.statistics.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.core.MessageFactory;
-import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
-import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.MessageSpy;
 import org.opendaylight.openflowplugin.openflow.md.util.RpcInputOutputTuple;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionAware;
+import org.opendaylight.openflowplugin.openflow.md.util.TaskUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionAware;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -34,15 +38,6 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
  *
  */
@@ -58,12 +53,12 @@ public abstract class OFRpcTaskUtil {
         //hiding implicit constructor
     }
 
-    public static Collection<RpcError> manageBarrier(OFRpcTaskContext taskContext, Boolean isBarrier,
-            SwitchConnectionDistinguisher cookie) {
+    public static Collection<RpcError> manageBarrier(final OFRpcTaskContext taskContext, final Boolean isBarrier,
+            final SwitchConnectionDistinguisher cookie) {
         Collection<RpcError> errors = null;
-        if (Objects.firstNonNull(isBarrier, Boolean.FALSE)) {
+        if (MoreObjects.firstNonNull(isBarrier, Boolean.FALSE)) {
             RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrierRpc =
-                    sendBarrier(taskContext.getSession(), cookie, taskContext.getMessageService());
+                    TaskUtil.sendBarrier(taskContext.getSession(), cookie, taskContext.getMessageService());
             Future<RpcResult<BarrierOutput>> barrierFuture = sendBarrierRpc.getOutput();
             try {
                 RpcResult<BarrierOutput> barrierResult = barrierFuture.get(
@@ -91,37 +86,24 @@ public abstract class OFRpcTaskUtil {
     }
 
     /**
-     * @param session
-     * @param cookie
-     * @param messageService
-     * @return barrier response
-     */
-    protected static RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrier(SessionContext session,
-            SwitchConnectionDistinguisher cookie, IMessageDispatchService messageService) {
-        BarrierInput barrierInput = MessageFactory.createBarrier(
-                session.getFeatures().getVersion(), session.getNextXid());
-        Future<RpcResult<BarrierOutput>> barrierResult = messageService.barrier(barrierInput, cookie);
-        ListenableFuture<RpcResult<BarrierOutput>> output = JdkFutureAdapters.listenInPoolThread(barrierResult);
-
-        return new RpcInputOutputTuple<>(barrierInput, output);
-    }
-
-    /**
-     * @param task of rpc
-     * @param originalResult
-     * @param notificationProviderService
+     * @param task task
+     * @param originalResult original result
+     * @param notificationProviderService notification provider service
      * @param notificationComposer lazy notification composer
+     * @param <I> data container
+     * @param <N> notification
+     * @param <R> R
      */
     public static <R extends RpcResult<? extends TransactionAware>, N extends Notification, I extends DataContainer>
     void hookFutureNotification(
             final OFRpcTask<I, R> task,
-            ListenableFuture<R> originalResult,
+            final ListenableFuture<R> originalResult,
             final NotificationProviderService notificationProviderService,
             final NotificationComposer<N> notificationComposer) {
 
         class FutureCallbackImpl implements FutureCallback<R> {
             @Override
-            public void onSuccess(R result) {
+            public void onSuccess(final R result) {
                 if(null == notificationProviderService) {
                     LOG.warn("onSuccess(): notificationServiceProvider is null, could not publish result {}",result);
                 } else if (notificationComposer == null) {
@@ -135,15 +117,15 @@ public abstract class OFRpcTaskUtil {
                 } else {
                     notificationProviderService.publish(notificationComposer.compose(result.getResult().getTransactionId()));
                     task.getTaskContext().getMessageSpy().spyMessage(
-                            task.getInput(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMITTED_SUCCESS);
+                            task.getInput(), MessageSpy.StatisticsGroup.TO_SWITCH_SUBMITTED_SUCCESS);
                 }
             }
 
             @Override
-            public void onFailure(Throwable t) {
+            public void onFailure(final Throwable t) {
                 //TODO: good place to notify MD-SAL about errors
                 task.getTaskContext().getMessageSpy().spyMessage(
-                        task.getInput(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMITTED_FAILURE);
+                        task.getInput(), MessageSpy.StatisticsGroup.TO_SWITCH_SUBMITTED_FAILURE);
             }
         }
 
@@ -151,10 +133,10 @@ public abstract class OFRpcTaskUtil {
     }
 
     /**
-     * @param task of rpcl
-     * @param originalResult
-     * @param notificationProviderService
-     * @param notificationComposer lazy notification composer
+     * @param task of rpc
+     * @param originalResult original result
+     * @param <T> R
+     * @param <I> I
      * @return chained result with barrier
      */
     public static <T extends TransactionAware, I extends DataContainer>
@@ -163,14 +145,14 @@ public abstract class OFRpcTaskUtil {
             final ListenableFuture<RpcResult<T>> originalResult) {
 
         ListenableFuture<RpcResult<T>> chainResult = originalResult;
-        if (Objects.firstNonNull(task.isBarrier(), Boolean.FALSE)) {
+        if (MoreObjects.firstNonNull(task.isBarrier(), Boolean.FALSE)) {
 
             chainResult = Futures.transform(originalResult, new AsyncFunction<RpcResult<T>, RpcResult<T>>() {
 
                 @Override
                 public ListenableFuture<RpcResult<T>> apply(final RpcResult<T> input) throws Exception {
                     if (input.isSuccessful()) {
-                        RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrierRpc = sendBarrier(
+                        RpcInputOutputTuple<BarrierInput, ListenableFuture<RpcResult<BarrierOutput>>> sendBarrierRpc = TaskUtil.sendBarrier(
                                 task.getSession(), task.getCookie(), task.getMessageService());
                         ListenableFuture<RpcResult<T>> barrierTxResult = Futures.transform(
                                 sendBarrierRpc.getOutput(),
@@ -188,8 +170,10 @@ public abstract class OFRpcTaskUtil {
     }
 
     /**
-     * @param originalInput
-     * @return
+     * @param originalInput original input
+     * @param barrierInput barrier input
+     * @param <T> T
+     * @return result
      */
     protected static <T extends TransactionAware> Function<RpcResult<BarrierOutput>, RpcResult<T>> transformBarrierToTransactionAware(
             final RpcResult<T> originalInput, final BarrierInput barrierInput) {