List of usage examples for com.google.common.util.concurrent FutureCallback FutureCallback
FutureCallback
From source file:org.opendaylight.groupbasedpolicy.renderer.iovisor.sf.ActionDefinitionListener.java
private FutureCallback<Void> logDebugResult(final SupportedActionDefinitionKey supportedActionDefinitionKey, final String putOrDeleted) { return new FutureCallback<Void>() { @Override/* www .java2s .c o m*/ public void onSuccess(Void result) { LOG.debug("Capability of renerer {} was {}: {}", IovisorRenderer.RENDERER_NAME.getValue(), putOrDeleted, supportedActionDefinitionKey.getActionDefinitionId().getValue()); } @Override public void onFailure(Throwable t) { LOG.error("Capability of renderer {} was NOT {}: {}", IovisorRenderer.RENDERER_NAME.getValue(), putOrDeleted, supportedActionDefinitionKey.getActionDefinitionId().getValue(), t); } }; }
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 ww w . j a v a 2 s. c o 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.opendaylight.dsbenchmark.txchain.TxchainBaWrite.java
@Override public void executeList() { int txSubmitted = 0; int writeCnt = 0; BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this); WriteTransaction tx = chain.newWriteOnlyTransaction(); LogicalDatastoreType dsType = getDataStoreType(); for (OuterList element : this.list) { InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, element.getKey());/*ww w .j a v a2s .c o m*/ if (oper == StartTestInput.Operation.PUT) { tx.put(dsType, iid, element); } else { tx.merge(dsType, iid, element); } writeCnt++; if (writeCnt == writesPerTx) { txSubmitted++; Futures.addCallback(tx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { txOk++; } @Override public void onFailure(final Throwable t) { LOG.error("Transaction failed, {}", t); txError++; } }); tx = chain.newWriteOnlyTransaction(); dsType = getDataStoreType(); writeCnt = 0; } } // *** Clean up and close the transaction chain *** // Submit the outstanding transaction even if it's empty and wait for it to finish // We need to empty the transaction chain before closing it try { txSubmitted++; tx.submit().checkedGet(); txOk++; } catch (TransactionCommitFailedException e) { LOG.error("Transaction failed", e); txError++; } try { chain.close(); } catch (IllegalStateException e) { LOG.error("Transaction close failed,", e); } LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); }
From source file:org.opendaylight.tl1.impl.MDSal.java
public static List<String> getAllDevices() { InstanceIdentifier<DeviceRegistry> identifier = InstanceIdentifier.create(DeviceRegistry.class); ReadOnlyTransaction transaction = dbroker.newReadOnlyTransaction(); ReadOnlyTransaction readTx = dbroker.newReadOnlyTransaction(); ListenableFuture<Optional<DeviceRegistry>> dataFuture = readTx.read(LogicalDatastoreType.OPERATIONAL, identifier);/*from w ww . j a va 2 s . c o m*/ Futures.addCallback(dataFuture, new FutureCallback<Optional<DeviceRegistry>>() { @Override public void onSuccess(final Optional<DeviceRegistry> result) { if (result.isPresent()) { // data are present in data store. allDevices = ExtractIps(result.get().getDeviceRegistryEntry()); //doSomething(result.get()); } else { // data are not present in data store. allDevices = null; } } @Override public void onFailure(final Throwable t) { // Error during read } }); return allDevices; }
From source file:org.robotninjas.barge.state.Candidate.java
@Override public void init(@Nonnull final RaftStateContext ctx) { log.currentTerm(log.currentTerm() + 1); log.lastVotedFor(Optional.of(log.self())); LOGGER.debug("Election starting for term {}", log.currentTerm()); List<ListenableFuture<RequestVoteResponse>> responses = sendRequests(ctx); electionResult = majorityResponse(responses, voteGranted()); long timeout = electionTimeout + (RAND.nextLong() % electionTimeout); electionTimer = DeadlineTimer.start(scheduler, new Runnable() { @Override//from w w w. ja v a 2s. c o m public void run() { LOGGER.debug("Election timeout"); transition(ctx, CANDIDATE); } }, timeout); addCallback(electionResult, new FutureCallback<Boolean>() { @Override public void onSuccess(@Nullable Boolean elected) { checkNotNull(elected); //noinspection ConstantConditions if (elected) { transition(ctx, LEADER); } } @Override public void onFailure(Throwable t) { if (!electionResult.isCancelled()) { LOGGER.debug("Election failed with exception:", t); } } }); }
From source file:com.metamx.druid.indexing.coordinator.ThreadPoolTaskRunner.java
@Override public ListenableFuture<TaskStatus> run(final Task task) { final TaskToolbox toolbox = toolboxFactory.build(task); final ListenableFuture<TaskStatus> statusFuture = exec .submit(new ExecutorServiceTaskRunnerCallable(task, toolbox)); final TaskRunnerWorkItem taskRunnerWorkItem = new TaskRunnerWorkItem(task, statusFuture); runningItems.add(taskRunnerWorkItem); Futures.addCallback(statusFuture, new FutureCallback<TaskStatus>() { @Override//from w w w. j ava2 s . c om public void onSuccess(TaskStatus result) { runningItems.remove(taskRunnerWorkItem); } @Override public void onFailure(Throwable t) { runningItems.remove(taskRunnerWorkItem); } }); return statusFuture; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.log.DaylightLogger.java
private static void uploadBlob(List<TestCase> tests, String blobAccessToken) { String urlBlob = "https://daylight.blob.core.windows.net/attachments"; for (TestCase test : tests) { String blobName = test.getFileName(); String body = test.getLog(); URI requestUrl = null;// w w w.j av a2 s .co m try { requestUrl = new URI(urlBlob + "/" + blobName + "?" + blobAccessToken); } catch (URISyntaxException e) { } test.setFileName(blobName); HttpPut request = new HttpPut(requestUrl); request.addHeader("x-ms-blob-type", "BlockBlob"); try { request.setEntity(new StringEntity(body, "UTF-8")); } catch (UnsupportedEncodingException uee) { } final SettableFuture<Void> externalFuture = SettableFuture.create(); ListenableFuture<HttpURLConnection> internalFuture = execute(request); Futures.addCallback(internalFuture, new FutureCallback<HttpURLConnection>() { @Override public void onFailure(Throwable throwable) { externalFuture.setException(throwable); } @Override public void onSuccess(HttpURLConnection connection) { try { connection.getInputStream(); externalFuture.set(null); } catch (Throwable throwable) { externalFuture.setException(throwable); } } }); try { externalFuture.get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } }
From source file:org.opendaylight.dsbenchmark.txchain.TxchainBaDelete.java
@Override public void executeList() { int txSubmitted = 0; int writeCnt = 0; BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this); WriteTransaction tx = chain.newWriteOnlyTransaction(); for (long l = 0; l < outerListElem; l++) { InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey((int) l)); tx.delete(LogicalDatastoreType.CONFIGURATION, iid); writeCnt++;// w ww . j a v a 2 s . c o m if (writeCnt == writesPerTx) { txSubmitted++; Futures.addCallback(tx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { txOk++; } @Override public void onFailure(final Throwable t) { LOG.error("Transaction failed, {}", t); txError++; } }); tx = chain.newWriteOnlyTransaction(); writeCnt = 0; } } // Submit the outstanding transaction even if it's empty and wait for it to finish // We need to empty the chain before closing it try { if (writeCnt > 0) { txSubmitted++; } tx.submit().checkedGet(); } catch (TransactionCommitFailedException e) { LOG.error("Transaction failed", e); } try { chain.close(); } catch (IllegalStateException e) { LOG.error("Transaction close failed,", e); } LOG.info("Transactions: submitted {}, completed {}", txSubmitted, (txOk + txError)); }
From source file:org.apache.tez.dag.app.TezTestServiceCommunicator.java
public void submitWork(SubmitWorkRequestProto request, String host, int port, final ExecuteRequestCallback<SubmitWorkResponseProto> callback) { ListenableFuture<SubmitWorkResponseProto> future = executor .submit(new SubmitWorkCallable(request, host, port)); Futures.addCallback(future, new FutureCallback<SubmitWorkResponseProto>() { @Override/*w w w.j a v a 2 s . c om*/ public void onSuccess(SubmitWorkResponseProto result) { callback.setResponse(result); } @Override public void onFailure(Throwable t) { callback.indicateError(t); } }); }
From source file:org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.didm.vendor.extreme.rev150211.ExtremeModule.java
protected static InstanceIdentifier<DeviceTypeInfo> registerDeviceTypeInfo(DataBroker dataBroker) { LOG.debug("registerDeviceTypeInfo -> " + dataBroker); InstanceIdentifier<DeviceTypeInfo> path = createKeyedDeviceTypeInfoPath(DEVICE_TYPE); WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, path, DEVICE_TYPE_INFO, true); CheckedFuture<Void, TransactionCommitFailedException> future = writeTx.submit(); Futures.addCallback(future, new FutureCallback<Void>() { public void onSuccess(Void result) { LOG.info("registerDeviceTypeInfo onSuccess"); }// w w w . j av a 2s . c o m public void onFailure(Throwable t) { LOG.error("registerDeviceTypeInfo onFailure -> " + t); } }); return path; }