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

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

Introduction

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

Prototype

public static <V> SettableFuture<V> create() 

Source Link

Document

Creates a new SettableFuture that can be completed or cancelled by a later method call.

Usage

From source file:io.prestosql.execution.FutureStateChange.java

public ListenableFuture<T> createNewListener() {
    SettableFuture<T> listener = SettableFuture.create();
    synchronized (listeners) {
        listeners.add(listener);/*from   www  .ja  v  a2 s . c  o m*/
    }

    // remove the listener when the future completes
    listener.addListener(() -> {
        synchronized (listeners) {
            listeners.remove(listener);
        }
    }, directExecutor());

    return listener;
}

From source file:com.linkedin.pinot.core.query.scheduler.SchedulerQueryContext.java

public SchedulerQueryContext(@Nonnull ServerQueryRequest queryRequest) {
    Preconditions.checkNotNull(queryRequest);

    this.queryRequest = queryRequest;
    this.resultFuture = SettableFuture.create();
}

From source file:webchat.client.http.HttpChannelFactory.java

@Override
public ChatFuture<MessageChannel> open(ChatHandler ioh) throws IOException {
    logger.info("Opening Http MessageChannel");
    SettableFuture<MessageChannel> futureChan = SettableFuture.create();
    Runnable r = () -> {// w  w w .  j  a va 2s . c  o  m
        HttpClientContext httpContext = HttpClientContext.create();
        httpContext.setCookieStore(new BasicCookieStore());
        HttpMessageSender sender = new HttpMessageSender(httpContext, commandUrl, formatter);
        HttpMessageReceiver receiver = new HttpMessageReceiver(httpContext, streamUrl, formatter);
        HttpMessageChannel chatSess = new HttpMessageChannel(sender, receiver, ioh);
        chatSess.start();
        ioh.onChannelOpened(chatSess);
        futureChan.set(chatSess);
    };
    new Thread(r).start();
    return new FutureAdapter(futureChan);
}

From source file:org.apache.twill.internal.ZKMessages.java

/**
 * Creates a message node in zookeeper. The message node created is a PERSISTENT_SEQUENTIAL node.
 *
 * @param zkClient The ZooKeeper client for interacting with ZooKeeper.
 * @param messagePathPrefix ZooKeeper path prefix for the message node.
 * @param message The {@link Message} object for the content of the message node.
 * @param completionResult Object to set to the result future when the message is processed.
 * @param <V> Type of the completion result.
 * @return A {@link ListenableFuture} that will be completed when the message is consumed, which indicated
 *         by deletion of the node. If there is exception during the process, it will be reflected
 *         to the future returned./*from  w  w w. j  a  v a  2  s.  c o m*/
 */
public static <V> ListenableFuture<V> sendMessage(final ZKClient zkClient, String messagePathPrefix,
        Message message, final V completionResult) {
    SettableFuture<V> result = SettableFuture.create();
    sendMessage(zkClient, messagePathPrefix, message, result, completionResult);
    return result;
}

From source file:c5db.client.scanner.ClientScannerManager.java

public ClientScanner createAndGet(Channel channel, long scannerId, long commandId) throws IOException {
    if (hasScanner(scannerId)) {
        throw new IOException("Scanner already created");
    }/*from ww  w  .j a  v a  2 s. c om*/

    final ClientScanner scanner = new ClientScanner(channel, scannerId, commandId);
    SettableFuture<ClientScanner> clientScannerSettableFuture = SettableFuture.create();
    clientScannerSettableFuture.set(scanner);
    scannerMap.put(scannerId, clientScannerSettableFuture);
    return scanner;
}

From source file:com.android.tools.idea.run.EmulatorConnectionListener.java

public static ListenableFuture<IDevice> getDeviceForEmulator(@NotNull Project project, @NotNull String avdName,
        @Nullable ProcessHandler emulatorProcessHandler, long timeout, @NotNull TimeUnit units) {
    if (emulatorProcessHandler == null) {
        return Futures
                .immediateFailedFuture(new RuntimeException("Emulator process for AVD " + avdName + " died."));
    }//from w  ww .ja  va 2  s . c om

    final SettableFuture<IDevice> future = SettableFuture.create();
    WaitForEmulatorTask task = new WaitForEmulatorTask(project, future, avdName, emulatorProcessHandler,
            timeout, units);
    ApplicationManager.getApplication().executeOnPooledThread(task);
    return future;
}

From source file:com.microsoftopentechnologies.intellij.serviceexplorer.NodeActionListenerAsync.java

public ListenableFuture<Void> actionPerformedAsync(final NodeActionEvent actionEvent) {
    final SettableFuture<Void> future = SettableFuture.create();
    ProgressManager.getInstance()/*from   ww  w  .  j a  v a 2  s .  c  om*/
            .run(new Task.Backgroundable(actionEvent.getAction().getNode().getProject(), progressMessage) {
                @Override
                public void run(@NotNull ProgressIndicator progressIndicator) {
                    try {
                        runInBackground(actionEvent);
                        future.set(null);
                    } catch (AzureCmdException e) {
                        future.setException(e);
                    }
                }
            });

    return future;
}

From source file:io.airlift.drift.integration.guice.ThrowingServiceHandler.java

@Override
public synchronized ListenableFuture<String> await() {
    if (awaitFuture == null) {
        awaitFuture = SettableFuture.create();
    }/*from   w  ww  .  j av  a  2  s .  c  om*/
    return awaitFuture;
}

From source file:c5db.ConcurrencyTestUtil.java

private static ListenableFuture<Boolean> runAndReturnCompletionFuture(ExecutorService executor,
        IndexedExceptionThrowingRunnable runnable, int invocationIndex) {
    final SettableFuture<Boolean> setWhenFinished = SettableFuture.create();

    executor.execute(() -> {/*from www  .  java 2  s  .  co  m*/
        try {
            runnable.run(invocationIndex);
            setWhenFinished.set(true);
        } catch (Throwable t) {
            setWhenFinished.setException(t);
        }
    });
    return setWhenFinished;
}

From source file:org.opendaylight.mdsal.dom.broker.PingPongTransaction.java

PingPongTransaction(final DOMDataReadWriteTransaction delegate) {
    this.delegate = Preconditions.checkNotNull(delegate);
    future = SettableFuture.create();
    submitFuture = new PingPongFuture(future);
}