Example usage for com.google.common.util.concurrent Futures immediateFuture

List of usage examples for com.google.common.util.concurrent Futures immediateFuture

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures immediateFuture.

Prototype

@CheckReturnValue
public static <V> ListenableFuture<V> immediateFuture(@Nullable V value) 

Source Link

Document

Creates a ListenableFuture which has its value set immediately upon construction.

Usage

From source file:org.opendaylight.bgpcep.pcep.topology.provider.TopologyProgramming.java

@Override
public ListenableFuture<RpcResult<SubmitRemoveLspOutput>> submitRemoveLsp(final SubmitRemoveLspInput input) {
    Preconditions.checkArgument(input.getNode() != null);
    Preconditions.checkArgument(input.getName() != null);

    final SubmitRemoveLspOutputBuilder b = new SubmitRemoveLspOutputBuilder();
    b.setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
        @Override//w w w .  j av a 2  s. c o m
        protected ListenableFuture<OperationResult> invokeOperation() {
            return TopologyProgramming.this.manager.removeLsp(input);
        }
    }));

    final RpcResult<SubmitRemoveLspOutput> res = SuccessfulRpcResult.create(b.build());
    return Futures.immediateFuture(res);
}

From source file:org.opendaylight.controller.clustering.it.provider.impl.SingletonGetConstantService.java

@Override
public ListenableFuture<Void> closeServiceInstance() {
    LOG.debug("Closing get-singleton-constant instance");
    rpcRegistration.close();/* w w w  .j  a v  a2s  .co m*/
    return Futures.immediateFuture(null);
}

From source file:com.android.camera.captureintent.CaptureIntentSession.java

@Override
public synchronized ListenableFuture<Optional<Uri>> saveAndFinish(byte[] data, int width, int height,
        int orientation, ExifInterface exif) {
    mSessionNotifier.notifySessionPictureDataAvailable(data, orientation);
    return Futures.immediateFuture(Optional.<Uri>absent());
}

From source file:org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx.java

@Override
public synchronized ListenableFuture<RpcResult<TransactionStatus>> performCommit() {
    unlock();//from  w w w .  jav  a  2  s .co m
    return Futures.immediateFuture(RpcResultBuilder.success(TransactionStatus.COMMITED).build());
}

From source file:io.v.v23.VFutures.java

/**
 * Returns a new {@link ListenableFuture} whose result is the same as the result of the
 * given {@code future} and is executed on an {@link Executor} specified in the given
 * {@code context}./*from w w w . j  a v  a 2 s .c o m*/
 * <p>
 * If no executor is specified in the context, the future may be executed on an arbitrary
 * thread.
 */
public static <T> ListenableFuture<T> onExecutor(final VContext context, final ListenableFuture<T> future) {
    Executor executor = V.getExecutor(context);
    if (executor == null) {
        return future;
    }
    return Futures.transform(future, new AsyncFunction<T, T>() {
        @Override
        public ListenableFuture<T> apply(T input) throws Exception {
            return Futures.immediateFuture(input);
        }
    }, executor);
}

From source file:org.opendaylight.lockmanager.LockManager.java

@Override
public Future<RpcResult<Void>> unlock(UnlockInput input) {
    String lockName = input.getLockName();
    LOG.info("Unlocking {}", lockName);
    InstanceIdentifier<Lock> lockInstanceIdentifier = LockManagerUtils.getLockInstanceIdentifier(lockName);
    unlock(lockName, lockInstanceIdentifier);
    RpcResultBuilder<Void> lockRpcBuilder = RpcResultBuilder.success();
    return Futures.immediateFuture(lockRpcBuilder.build());
}

From source file:org.opendaylight.toaster.impl.ToasterServiceImpl.java

@Override
public Future<RpcResult<java.lang.Void>> cancelToast() {
    LOG.info("cancelToast");
    final InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
    final ReadWriteTransaction tx = broker.newReadWriteTransaction();
    ListenableFuture<Optional<Toaster>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID);

    //Optional<Toaster>ListenableFuture??VoidListenableFuture
    final ListenableFuture<Void> commitFuture = Futures.transform(readFuture,
            new AsyncFunction<Optional<Toaster>, Void>() {

                @Override//w ww  .j  ava 2  s .  co m
                public ListenableFuture<Void> apply(final Optional<Toaster> toasterData) throws Exception {
                    //?toastertasterStatus
                    ToasterStatus toasterStatus = ToasterStatus.Down;
                    if (toasterData.isPresent()) {
                        toasterStatus = toasterData.get().getToasterStatus();
                    }

                    //???Up
                    if (toasterStatus == ToasterStatus.Down) {
                        //Down?
                        LOG.info("the toaster is not running!");
                        return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("",
                                RpcResultBuilder.newWarning(ErrorType.APPLICATION, "not-in-use",
                                        "Toaster is not running", null, null, null)));
                    } else {
                        //up??down?
                        tx.put(LogicalDatastoreType.OPERATIONAL, TOASTER_IID,
                                new ToasterBuilder().setToasterStatus(ToasterStatus.Down).build());
                        return tx.submit();
                    }
                }
            });

    //callback
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {
            // data store?makeToast
            LOG.info("******Task was canceled.******");
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.debug("Failed to commit Toaster status", ex);
        }
    });
    return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}

From source file:org.opendaylight.sfc.pot.provider.SfcPotRpc.java

/**
 * This method triggers disabling of Proof of Transit feature on the
 * selected SFC/RSP.//  w ww . j a v  a 2s .  c o m
 *
 * <p>
 * @param input
 *            RPC input including a Rendered Service Path name
 * @return RPC output including a success or failure code.
 */
@Override
public Future<RpcResult<DisableSfcIoamPotRenderedPathOutput>> disableSfcIoamPotRenderedPath(
        DisableSfcIoamPotRenderedPathInput input) {
    boolean ret;
    RpcResultBuilder<DisableSfcIoamPotRenderedPathOutput> rpcResultBuilder;
    RspName rspName = new RspName(input.getSfcIoamPotRspName());

    /* Disable iOAM Proof of transit for this SFC/RSP */
    ret = SfcPotRspProcessor.disableSfcPot(rspName);
    if (ret) {
        /* success */
        DisableSfcIoamPotRenderedPathOutputBuilder disableSfcIoamPotRenderedPathOutputBuilder = new DisableSfcIoamPotRenderedPathOutputBuilder();
        disableSfcIoamPotRenderedPathOutputBuilder.setResult(true);
        rpcResultBuilder = RpcResultBuilder.success(disableSfcIoamPotRenderedPathOutputBuilder.build());
    } else {
        String message = "Error disabling SFC Proof of Transit for Rendered Service Path: "
                + rspName.getValue();
        rpcResultBuilder = RpcResultBuilder.<DisableSfcIoamPotRenderedPathOutput>failed()
                .withError(ErrorType.APPLICATION, message);
    }

    return Futures.immediateFuture(rpcResultBuilder.build());
}

From source file:org.apache.qpid.server.consumer.AbstractConsumerTarget.java

@Override
public ListenableFuture<Void> consumerRemoved(final MessageInstanceConsumer sub) {
    if (_consumers.contains(sub)) {
        return doOnIoThreadAsync(new Runnable() {
            @Override/*from   ww  w .j  av  a2s .  com*/
            public void run() {
                consumerRemovedInternal(sub);
            }
        });
    } else {
        return Futures.immediateFuture(null);
    }
}

From source file:com.continuuity.weave.internal.AbstractServiceController.java

@Override
public ListenableFuture<State> stop() {
    State oldState = state.getAndSet(State.STOPPING);
    if (oldState == null || oldState == State.STARTING || oldState == State.RUNNING) {
        return Futures.transform(ZKMessages.sendMessage(zkClient, getZKPath("messages/msg"),
                SystemMessages.stopApplication(), State.TERMINATED), new AsyncFunction<State, State>() {
                    @Override// w  w  w  .j  av  a2  s .c  o  m
                    public ListenableFuture<State> apply(State input) throws Exception {
                        // Wait for the instance ephemeral node goes away
                        return Futures.transform(ZKOperations.watchDeleted(zkClient, "/instances/" + runId),
                                new Function<String, State>() {
                                    @Override
                                    public State apply(String input) {
                                        LOG.info("Remote service stopped: " + runId);
                                        state.set(State.TERMINATED);
                                        fireStateChange(new StateNode(State.TERMINATED, null));
                                        return State.TERMINATED;
                                    }
                                });
                    }
                });
    }
    state.set(oldState);
    return Futures.immediateFuture(getState());
}