Search in sources :

Example 1 with FlowCapableTransactionService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService in project openflowplugin by opendaylight.

the class BarrierUtil method chainBarrier.

/**
 * 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 composite transform
 * @return future holding both results (input and of the barrier)
 */
public static <T> ListenableFuture<RpcResult<T>> chainBarrier(final ListenableFuture<RpcResult<T>> input, final NodeRef nodeRef, final FlowCapableTransactionService transactionService, final Function<Pair<RpcResult<T>, RpcResult<Void>>, RpcResult<T>> compositeTransform) {
    final MutablePair<RpcResult<T>, RpcResult<Void>> resultPair = new MutablePair<>();
    // store input result and append barrier
    final ListenableFuture<RpcResult<Void>> barrierResult = Futures.transformAsync(input, 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>>>() {

        @Nullable
        @Override
        public Pair<RpcResult<T>, RpcResult<Void>> apply(@Nullable final RpcResult<Void> input) {
            resultPair.setRight(input);
            return resultPair;
        }
    }, MoreExecutors.directExecutor());
    // append assembling transform to barrier result
    return Futures.transform(compositeResult, compositeTransform, MoreExecutors.directExecutor());
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MutablePair(org.apache.commons.lang3.tuple.MutablePair) SendBarrierInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput) Nullable(javax.annotation.Nullable) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Nullable (javax.annotation.Nullable)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 SendBarrierInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1