package org.opendaylight.openflowplugin.impl.util;
import com.google.common.base.Function;
-import com.google.common.util.concurrent.AsyncFunction;
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 javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.yangtools.yang.common.RpcResult;
/**
- * provides barrier message chaining and factory methods
+ * Provides barrier message chaining and factory methods.
*/
public final class BarrierUtil {
/**
- * chain a barrier message - regardless of previous result and use given {@link Function} to combine
- * original result and barrier result
+ * Chain a barrier message - regardless of previous result and use given {@link Function} to combine
+ * original result and barrier result.
*
* @param <T> type of input future
* @param input future to chain barrier to
* @param nodeRef target device
* @param transactionService barrier service
- * @param compositeTransform
+ * @param compositeTransform composite transform
* @return future holding both results (input and of the barrier)
*/
public static <T> ListenableFuture<RpcResult<T>> chainBarrier(
// store input result and append barrier
final ListenableFuture<RpcResult<Void>> barrierResult = Futures.transformAsync(input,
- new AsyncFunction<RpcResult<T>, RpcResult<Void>>() {
- @Override
- public ListenableFuture<RpcResult<Void>> apply(@Nullable final RpcResult<T> interInput) throws Exception {
- resultPair.setLeft(interInput);
- final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef);
- return JdkFutureAdapters.listenInPoolThread(transactionService.sendBarrier(barrierInput));
- }
- });
+ interInput -> {
+ resultPair.setLeft(interInput);
+ final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef);
+ return JdkFutureAdapters.listenInPoolThread(transactionService.sendBarrier(barrierInput));
+ }, MoreExecutors.directExecutor());
// store barrier result and return initiated pair
final ListenableFuture<Pair<RpcResult<T>, RpcResult<Void>>> compositeResult = Futures.transform(
barrierResult, new Function<RpcResult<Void>, Pair<RpcResult<T>, RpcResult<Void>>>() {
}
/**
+ * Creates barrier input.
+ *
* @param nodeRef rpc routing context
* @return input for {@link FlowCapableTransactionService#sendBarrier(SendBarrierInput)}
*/