Example usage for com.google.common.util.concurrent SettableFuture set

List of usage examples for com.google.common.util.concurrent SettableFuture set

Introduction

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

Prototype

@Override
    public boolean set(@Nullable V value) 

Source Link

Usage

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> tables(@Nullable String catalog, @Nullable String schemaPattern,
        String tableNamePattern, @Nullable List<String> tableTypes) {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("tables_stmt").iterator(),
            statementsToMetadata.get("tables_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "tables_stmt", statementsToMetadata,
            statementsToResults);//from  w ww  . j  a v a  2s . com
}

From source file:com.twitter.heron.statemgr.localfs.LocalFileSystemStateManager.java

@Override
public ListenableFuture<Boolean> isTopologyRunning(String topologyName) {
    SettableFuture<Boolean> future = SettableFuture.create();
    boolean ret = FileUtils.isFileExists(getTopologyPath(topologyName));
    future.set(ret);

    return future;
}

From source file:com.groupon.mesos.executor.ExecutorDriverContext.java

synchronized ListenableFuture<Status> waitForStateChange(final Status expectedStatus) {
    final SettableFuture<Status> future = SettableFuture.create();
    if (!isStateMachine(expectedStatus)) {
        // Current status is not the expected status. Return
        // it immediately.
        future.set(stateMachine.get());
    } else {//from ww  w . j  av  a 2  s  .  c  o  m
        // Current status is expected status: Queue up for a status change.
        stateMachineFutures.add(future);
    }
    return future;
}

From source file:co.cask.tigon.internal.app.runtime.distributed.AbstractServiceTwillRunnable.java

private Service.Listener createServiceListener(final SettableFuture<Service.State> completion) {
    return new ServiceListenerAdapter() {
        @Override/* ww  w.  j  a  v  a 2  s .  co  m*/
        public void terminated(Service.State from) {
            completion.set(from);
        }

        @Override
        public void failed(Service.State from, Throwable failure) {
            completion.setException(failure);
        }
    };
}

From source file:org.pentaho.osgi.bridge.KarafCapabilityProvider.java

@Override
public void featureEvent(FeatureEvent featureEvent) {
    String feature = featureEvent.getFeature().getId();
    InstallFuture installFutureWrapper = futures.getIfPresent(feature);
    if (installFutureWrapper == null) {
        return;//from   w  w w  .ja  v a  2 s  . c  om
    }
    switch (featureEvent.getType()) {
    case FeatureInstalled:
        SettableFuture<Boolean> future = installFutureWrapper.future;
        if (future != null) {
            futures.invalidate(feature);
            future.set(installFutureWrapper.install);
        }
        break;
    case FeatureUninstalled:
        future = installFutureWrapper.future;
        if (future != null) {
            futures.invalidate(feature);
            future.set(!installFutureWrapper.install);
        }
        break;
    }

}

From source file:org.opendaylight.lispflowmapping.netconf.impl.LispDeviceNetconfConnector.java

private boolean verifyRemoveInput(final RemoveConnectorInput conn,
        SettableFuture<RpcResult<Void>> futureResult) {
    if (conn.getInstance() == null) {
        LOG.error("Instance name not initialized");
        futureResult.set(RpcResultBuilder.<Void>failed()
                .withError(ErrorType.APPLICATION, "exception", "Instance name not initialized").build());
        return false;
    }/*from w w  w .j  a v  a2 s  .c o m*/

    return true;
}

From source file:org.usrz.libs.utils.concurrent.SimpleExecutor.java

public <T> NotifyingFuture<T> call(Callable<T> callable) {
    final SettableFuture<T> settableFuture = SettableFuture.create();

    final Future<T> executingFuture = executor.submit(() -> {
        try {/*from   w w w.  j a va  2s.co  m*/
            final T result = callable.call();
            settableFuture.set(result);
            return result;
        } catch (Throwable throwable) {
            settableFuture.setException(throwable);
            throw new Exception(throwable);
        }
    });

    return new NotifyingFuture<T>() {

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            if (executingFuture.cancel(mayInterruptIfRunning)) {
                settableFuture.cancel(mayInterruptIfRunning);
                return true;
            } else {
                return false;
            }
        }

        @Override
        public boolean isCancelled() {
            return settableFuture.isCancelled();
        }

        @Override
        public boolean isDone() {
            return settableFuture.isCancelled();
        }

        @Override
        public T get() throws InterruptedException, ExecutionException {
            return settableFuture.get();
        }

        @Override
        public T get(long timeout, TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            return settableFuture.get(timeout, unit);
        }

        @Override
        public NotifyingFuture<T> withConsumer(Consumer<Future<T>> consumer) {
            settableFuture.addListener(() -> consumer.accept(settableFuture), notifier);
            return this;
        }

    };
}

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

@Override
public Future<RpcResult<Void>> buyCar(BuyCarInput input) {
    log.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
    SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
    CarBoughtBuilder carBoughtBuilder = new CarBoughtBuilder();
    carBoughtBuilder.setCarId(input.getCarId());
    carBoughtBuilder.setPersonId(input.getPersonId());
    notificationProvider.publish(carBoughtBuilder.build());
    futureResult.set(RpcResultBuilder.<Void>success().build());
    return futureResult;
}

From source file:eu.esdihumboldt.hale.ui.util.source.CompilingSourceViewer.java

/**
 * Get the compilation result./* w  ww.ja v  a 2s .c  o m*/
 * 
 * @return a future reference to the compilation result, the actual
 *         compilation result may be <code>null</code> if the compilation
 *         failed
 */
public ListenableFuture<C> getCompiled() {
    SettableFuture<C> result = SettableFuture.create();
    if (!compilationEnabled) {
        result.set(null);
        return result;
    }

    changeLock.lock();
    try {
        if (changed) {
            // compilation result is not up-to-date
            toUpdate.add(result);
        } else {
            result.set(compiled);
        }
    } finally {
        changeLock.unlock();
    }

    return result;
}

From source file:org.glassfish.jersey.examples.rx.agent.ListenableFutureAgentResource.java

private ListenableFuture<AgentResponse> visited(final AgentResponse response) {
    final ListenableFuture<List<Destination>> visited = RxListenableFuture.from(destination).path("visited")
            .request()/* w ww.  j av  a 2 s.  c  o m*/
            // Identify the user.
            .header("Rx-User", "Guava")
            // Reactive invoker.
            .rx()
            // Return a list of destinations.
            .get(new GenericType<List<Destination>>() {
            });
    return Futures.transform(visited, new AsyncFunction<List<Destination>, AgentResponse>() {
        @Override
        public ListenableFuture<AgentResponse> apply(final List<Destination> input) throws Exception {
            final SettableFuture<AgentResponse> future = SettableFuture.create();

            response.setVisited(input);
            future.set(response);

            return future;
        }
    });
}