Search in sources :

Example 11 with BarrierInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput 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

Test (org.junit.Test)7 BarrierInput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput)6 BarrierInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder)6 SendBarrierInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput)3 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)3 ByteBuf (io.netty.buffer.ByteBuf)2 BarrierOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput)2 BarrierOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutputBuilder)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Before (org.junit.Before)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 ThreadPoolLoggingExecutor (org.opendaylight.openflowplugin.impl.util.ThreadPoolLoggingExecutor)1 NonZeroUint32Type (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type)1 OpenflowProviderConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder)1