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:com.microsoftopentechnologies.intellij.helpers.azure.sdk.AzureSDKManagerImpl.java

@NotNull
private static ListenableFuture<DeploymentGetResponse> getDeploymentAsync(
        @NotNull final ComputeManagementClient client, @NotNull final String serviceName,
        @NotNull final DeploymentSlot slot) {
    final SettableFuture<DeploymentGetResponse> future = SettableFuture.create();

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override//from   w w w  .jav a 2s .c o  m
        public void run() {
            try {
                future.set(getDeployment(client, serviceName, slot));
            } catch (Exception e) {
                future.setException(e);
            }
        }
    });

    return future;
}

From source file:io.crate.action.sql.DDLAnalysisDispatcher.java

private ListenableFuture<Long> wrapRowCountFuture(ListenableFuture<?> wrappedFuture, final Long rowCount) {
    final SettableFuture<Long> wrappingFuture = SettableFuture.create();
    Futures.addCallback(wrappedFuture, new FutureCallback<Object>() {
        @Override//from   www .jav  a 2  s.co  m
        public void onSuccess(@Nullable Object result) {
            wrappingFuture.set(rowCount);
        }

        @Override
        public void onFailure(Throwable t) {
            wrappingFuture.setException(t);
        }
    });
    return wrappingFuture;
}

From source file:com.microsoftopentechnologies.intellij.helpers.azure.sdk.AzureSDKManagerImpl.java

@NotNull
private static ListenableFuture<List<VirtualMachineImage>> getOSImagesAsync(
        @NotNull final ComputeManagementClient client) {
    final SettableFuture<List<VirtualMachineImage>> future = SettableFuture.create();

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override// w  w w.  jav  a  2 s.com
        public void run() {
            try {
                future.set(getOSImages(client));
            } catch (Exception e) {
                future.setException(e);
            }
        }
    });

    return future;
}

From source file:com.microsoftopentechnologies.intellij.helpers.azure.sdk.AzureSDKManagerImpl.java

@NotNull
private static ListenableFuture<List<VirtualMachineImage>> getVMImagesAsync(
        @NotNull final ComputeManagementClient client) {
    final SettableFuture<List<VirtualMachineImage>> future = SettableFuture.create();

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override//w ww.jav  a2s .  c  om
        public void run() {
            try {
                future.set(getVMImages(client));
            } catch (Exception e) {
                future.setException(e);
            }
        }
    });

    return future;
}

From source file:org.opendaylight.netconf.topology.impl.OnlySuccessStateAggregator.java

@Override
public ListenableFuture<Node> combineUpdateAttempts(List<ListenableFuture<Node>> stateFutures) {
    final SettableFuture<Node> future = SettableFuture.create();
    final ListenableFuture<List<Node>> allAsList = Futures.allAsList(stateFutures);
    Futures.addCallback(allAsList, new FutureCallback<List<Node>>() {
        @Override//w  w w  .  j  a  v a 2  s .  c o  m
        public void onSuccess(List<Node> result) {
            for (int i = 0; i < result.size() - 1; i++) {
                if (!result.get(i).equals(result.get(i + 1))) {
                    future.setException(new IllegalStateException("Update futures have different result"));
                }
            }
            future.set(result.get(0));
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.error("One of the combined update attempts failed {}", t);
            future.setException(t);
        }
    });
    return future;
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterStackImpl.java

/**
 * @return rpc future result/* w  ww.  j a v  a 2s  . c om*/
 */
private synchronized SettableFuture<RpcResult<Void>> createOneWayRpcResult() {
    SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    List<RpcError> errors = Collections.emptyList();
    result.set(Rpcs.getRpcResult(true, (Void) null, errors));
    return result;
}

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

@Override
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
        final YangInstanceIdentifier path) {
    final SettableFuture<Optional<NormalizedNode<?, ?>>> readResult = SettableFuture.create();

    Futures.addCallback(previousWriteTxFuture, new FutureCallback<Void>() {
        @Override//from w w  w  .j  a  v  a2  s .  c  o m
        public void onSuccess(@Nullable final Void result) {
            Futures.addCallback(delegateReadTx.read(store, path),
                    new FutureCallback<Optional<NormalizedNode<?, ?>>>() {

                        @Override
                        public void onSuccess(@Nullable final Optional<NormalizedNode<?, ?>> result) {
                            readResult.set(result);
                        }

                        @Override
                        public void onFailure(final Throwable throwable) {
                            txChain.transactionFailed(TransactionChainReadTransaction.this, throwable);
                            readResult.setException(throwable);
                        }
                    });
        }

        @Override
        public void onFailure(final Throwable throwable) {
            // we don't have to notify txchain about this failure
            // failed write transaction should do this
            readResult.setException(throwable);
        }
    });

    return Futures.makeChecked(readResult, ReadFailedException.MAPPER);
}

From source file:org.opendaylight.netconf.topology.impl.OnlySuccessStateAggregator.java

@Override
public ListenableFuture<Node> combineCreateAttempts(List<ListenableFuture<Node>> stateFutures) {
    final SettableFuture<Node> future = SettableFuture.create();
    final ListenableFuture<List<Node>> allAsList = Futures.allAsList(stateFutures);
    Futures.addCallback(allAsList, new FutureCallback<List<Node>>() {
        @Override/*from   w  w w .  jav a 2  s. c  om*/
        public void onSuccess(List<Node> result) {
            for (int i = 0; i < result.size() - 1; i++) {
                if (!result.get(i).equals(result.get(i + 1))) {
                    future.setException(new IllegalStateException("Create futures have different result"));
                }
            }
            future.set(result.get(0));
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.error("One of the combined create attempts failed {}", t);
            future.setException(t);
        }
    }, TypedActor.context().dispatcher());

    return future;
}

From source file:io.crate.autocomplete.AutoCompleter.java

public ListenableFuture<CompletionResult> complete(String statement) {
    StatementLexer lexer = getLexer(statement);
    final Context ctx = new Context(statement.length());
    List<ListenableFuture<List<String>>> futureCompletions;
    try {//from w  ww  .  j a  v  a2  s. co  m
        futureCompletions = innerComplete(lexer, statement, ctx);
    } catch (ParsingException e) {
        return Futures.immediateFuture(new CompletionResult(0, Collections.<String>emptyList()));
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        return Futures.immediateFuture(new CompletionResult(0, Collections.<String>emptyList()));
    }

    final SettableFuture<CompletionResult> result = SettableFuture.create();
    Futures.addCallback(Futures.allAsList(futureCompletions), new FutureCallback<List<List<String>>>() {
        @Override
        public void onSuccess(@Nullable List<List<String>> completionsList) {
            if (completionsList == null) {
                result.set(new CompletionResult(0, ImmutableList.<String>of()));
                return;
            }
            if (ctx.parts.size() > 1) {
                Set<String> fullyQualifiedCompletions = new TreeSet<>();
                for (List<String> completions : completionsList) {
                    for (String completion : completions) {
                        ctx.parts.set(ctx.parts.size() - 1, completion);
                        fullyQualifiedCompletions.add(dotJoiner.join(ctx.parts));
                    }
                }
                result.set(new CompletionResult(ctx.startIdx, fullyQualifiedCompletions));
            } else {
                Set<String> uniqueSortedCompletions = new TreeSet<>();
                for (List<String> completions : completionsList) {
                    uniqueSortedCompletions.addAll(completions);
                }
                result.set(new CompletionResult(ctx.startIdx, uniqueSortedCompletions));
            }
        }

        @Override
        public void onFailure(@Nonnull Throwable t) {
            result.setException(t);
        }
    });
    return result;
}

From source file:org.apache.bookkeeper.stream.segment.BKSegmentReader.java

private void completeCloseFutures0() {
    SettableFuture<Void> closeFuture;
    while (null != (closeFuture = closeFutures.poll())) {
        closeFuture.set(null);
    }//from   www .j  a v  a2s  .  c  om
}