List of usage examples for com.google.common.util.concurrent Futures addCallback
public static <V> void addCallback(ListenableFuture<V> future, FutureCallback<? super V> callback)
From source file:cryptwallet.SendMoneyController.java
public void send(ActionEvent event) { // Address exception cannot happen as we validated it beforehand. try {/* www . j a v a 2s .c o m*/ Coin amount = Coin.parseCoin(amountEdit.getText()); Address destination = Address.fromBase58(Main.params, address.getText()); SendRequest req; if (amount.equals(Main.bitcoin.wallet().getBalance())) req = SendRequest.emptyWallet(destination); else req = SendRequest.to(destination, amount); req.aesKey = aesKey; sendResult = Main.bitcoin.wallet().sendCoins(req); Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<Transaction>() { @Override public void onSuccess(@Nullable Transaction result) { checkGuiThread(); overlayUI.done(); } @Override public void onFailure(Throwable t) { // We died trying to empty the wallet. crashAlert(t); } }); sendResult.tx.getConfidence().addEventListener((tx, reason) -> { if (reason == TransactionConfidence.Listener.ChangeReason.SEEN_PEERS) updateTitleForBroadcast(); }); sendBtn.setDisable(true); address.setDisable(true); ((HBox) amountEdit.getParent()).getChildren().remove(amountEdit); ((HBox) btcLabel.getParent()).getChildren().remove(btcLabel); updateTitleForBroadcast(); } catch (InsufficientMoneyException e) { informationalAlert("Could not empty the wallet", "You may have too little money left in the wallet to make a transaction."); overlayUI.done(); } catch (ECKey.KeyIsEncryptedException e) { askForPasswordAndRetry(); } }
From source file:org.apache.twill.internal.zookeeper.RewatchOnExpireZKClient.java
@Override public OperationFuture<NodeChildren> getChildren(String path, Watcher watcher) { if (watcher == null) { return super.getChildren(path, null); }/*from ww w.j a v a2 s. c om*/ final RewatchOnExpireWatcher wrappedWatcher = new RewatchOnExpireWatcher(this, ActionType.CHILDREN, path, watcher); OperationFuture<NodeChildren> result = super.getChildren(path, wrappedWatcher); Futures.addCallback(result, new FutureCallback<NodeChildren>() { @Override public void onSuccess(NodeChildren result) { wrappedWatcher.setLastResult(result); } @Override public void onFailure(Throwable t) { // No-op } }); return result; }
From source file:com.microsoft.office.integration.test.FoldersAsyncTestCase.java
public void testUpdate() { prepareFolder();/* w w w. j a v a 2s . co m*/ counter = new CountDownLatch(1); Futures.addCallback(Me.flushAsync(), new FutureCallback<Void>() { public void onFailure(Throwable t) { reportError(t); counter.countDown(); } public void onSuccess(Void result) { try { updateAndCheck(); removeFolder(); } catch (Throwable t) { reportError(t); } counter.countDown(); } }); try { if (!counter.await(60000, TimeUnit.MILLISECONDS)) { fail("testUpdate() timed out"); } } catch (InterruptedException e) { fail("testUpdate() has been interrupted"); } }
From source file:io.github.chenguangqi.toaster.impl.ToasterProvider.java
private void initToasterOperational() { // Build the initial toaster operational data Toaster toaster = new ToasterBuilder().setToasterManufacturer(TOASTER_MANUFACTURER) .setToasterModelNumber(TOASTER_MODEL_NUMBER).setToasterStatus(ToasterStatus.Up).build(); // Put the toaster operational data into the MD-SAL data store. WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.OPERATIONAL, TOASTER_IID, toaster); Futures.addCallback(tx.submit(), new FutureCallback<Void>() { @Override/*w w w . j a v a 2 s. co m*/ public void onSuccess(@Nullable Void aVoid) { LOG.info("initToasterOperational: transaction succeeded"); } @Override public void onFailure(Throwable throwable) { LOG.error("initToasterOperational: transaction failed"); } }); }
From source file:org.opendaylight.controller.config.yang.netconf.mdsal.notification.NotificationToMdsalWriter.java
@Override public void close() { final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Netconf.class)); final CheckedFuture<Void, TransactionCommitFailedException> submit = tx.submit(); Futures.addCallback(submit, new FutureCallback<Void>() { @Override// w ww .j a v a 2 s. c o m public void onSuccess(Void aVoid) { LOG.debug("Streams cleared successfully"); } @Override public void onFailure(Throwable throwable) { LOG.warn("Unable to clear streams", throwable); } }); notificationRegistration.close(); }
From source file:com.microsoft.filediscovery.MainActivity.java
void StartServiceListActivity() { ListenableFuture<Map<String, Credentials>> future = Authentication.authenticate(this, Constants.DISCOVERY_RESOURCE_ID); Futures.addCallback(future, new FutureCallback<Map<String, Credentials>>() { @Override// w w w . j ava 2s . co m public void onFailure(Throwable t) { Log.e("Asset", t.getMessage()); } @Override public void onSuccess(Map<String, Credentials> credentials) { startActivity(new Intent(MainActivity.this, ServiceListActivity.class)); } }); }
From source file:io.crate.executor.task.join.NestedLoopTask.java
@Override public void start() { Futures.addCallback(operation.execute(Optional.<PageInfo>absent()), new ForwardingFutureCallback<>(result)); }
From source file:com.sk89q.worldedit.command.util.AsyncCommandHelper.java
public AsyncCommandHelper thenRespondWith(String success, String failure) { // Send a response message Futures.addCallback(future, new MessageFutureCallback.Builder(sender).exceptionConverter(exceptionConverter) .onSuccess(format(success)).onFailure(format(failure)).build()); return this; }
From source file:org.opendaylight.vtn.manager.internal.flow.reader.ReadSingleFlowFuture.java
/** * Construct a new instance./*from w ww .j a v a 2 s. c o m*/ * * @param ctx A {@link TxContext} instance. * @param txq A {@link TxQueue} instance used to update the MD-SAL * datastore. * @param srs The flow statistics reader service. * @param input Input of the RPC call. * @throws VTNException An error occurred. */ public ReadSingleFlowFuture(TxContext ctx, TxQueue txq, StatsReaderService srs, GetDataFlowInput input) throws VTNException { super(ctx, txq, srs, input); if (!isDone()) { InstanceIdentifier<VtnDataFlow> path = FlowUtils.getIdentifier(input.getTenantName(), input.getFlowId()); LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL; ReadTransaction rtx = ctx.getTransaction(); Futures.addCallback(rtx.read(oper, path), this); } }
From source file:org.opendaylight.controller.clustering.it.listener.PeopleCarListener.java
@Override public void onCarBought(CarBought notification) { final CarPersonBuilder carPersonBuilder = new CarPersonBuilder(); carPersonBuilder.setCarId(notification.getCarId()); carPersonBuilder.setPersonId(notification.getPersonId()); CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId()); carPersonBuilder.setKey(key);// w w w . j a va 2 s.c o m final CarPerson carPerson = carPersonBuilder.build(); log.info("Car bought, adding car-person entry: [{}]", carPerson); InstanceIdentifier<CarPerson> carPersonIId = InstanceIdentifier.<CarPeople>builder(CarPeople.class) .child(CarPerson.class, carPerson.getKey()).build(); WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true); Futures.addCallback(tx.submit(), new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { log.info("Successfully added car-person entry: [{}]", carPerson); } @Override public void onFailure(final Throwable t) { log.error(String.format("Failed to add car-person entry: [%s]", carPerson), t); } }); }