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:org.anhonesteffort.chnlbrkr.stream.ChannelStreamerFactory.java
public ListenableFuture<ChannelStreamer> create(IdleChnlzrConnection connection, WriteQueuingContext client, ChannelRequest.Reader request) { MessageBuilder capabilities = CapnpUtil.builder(connection.getCapabilitiesMessage()); SettableFuture<ChannelRequestHandler> requestFuture = SettableFuture.create(); SettableFuture<ChannelStreamer> streamFuture = SettableFuture.create(); ChannelRequestHandler requestHandler = new ChannelRequestHandler(requestFuture, request, connection.getId(), config.chnlzrRequestAnswerTimeoutMs()); connection.getContext().pipeline().replace(connection, "request", requestHandler); Futures.addCallback(requestFuture, new ChannelRequestCallback(streamFuture, client, capabilities)); return streamFuture; }
From source file:com.microsoft.assetmanagement.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_preferences: { startActivity(new Intent(this, AppSettingsActivity.class)); return true; }//from w w w. j a va 2 s . com case R.id.menu_show_cars: { boolean hasConfig = mApplication.hasConfigurationSettings() && mApplication.hasDefaultList(); if (hasConfig) { try { ListenableFuture<Credentials> future = mApplication.authenticate(this); Futures.addCallback(future, new FutureCallback<Credentials>() { @Override public void onFailure(Throwable t) { Log.e("Asset", t.getMessage()); } @Override public void onSuccess(Credentials credentials) { startActivity(new Intent(MainActivity.this, CarListActivity.class)); } }); } catch (Throwable t) { Log.e("Asset", t.getMessage()); } } else { checkPreferences(); } return true; } default: return true; } }
From source file:us.physion.ovation.ui.editor.NewProjectAction.java
@Override public void actionPerformed(final ActionEvent e) { DataContext ctx = Lookup.getDefault().lookup(ConnectionProvider.class).getDefaultContext(); final Project p = ctx.insertProject(Bundle.CTL_Default_Project_Name(), "", new DateTime()); ListenableFuture<Void> reset = BrowserUtilities.reloadView(BrowserUtilities.PROJECT_BROWSER_ID); Futures.addCallback(reset, new FutureCallback<Void>() { @Override/* ww w. ja va2 s. co m*/ public void onSuccess(Void result) { selectNode(p, BrowserUtilities.PROJECT_BROWSER_ID); } @Override public void onFailure(Throwable t) { LoggerFactory.getLogger(NewProjectAction.class).error("Unable to reset view", t); } }); }
From source file:org.opendaylight.controller.cluster.schema.provider.impl.RemoteYangTextSourceProviderImpl.java
@Override public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(SourceIdentifier identifier) { LOG.trace("Sending yang schema source for {}", identifier); final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise(); CheckedFuture<YangTextSchemaSource, ?> future = repository.getSchemaSource(identifier, YangTextSchemaSource.class); Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() { @Override//ww w. j a v a2 s . c om public void onSuccess(YangTextSchemaSource result) { try { promise.success(new YangTextSchemaSourceSerializationProxy(result)); } catch (IOException e) { LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e); promise.failure(e); } } @Override public void onFailure(Throwable t) { LOG.warn("Unable to retrieve schema source from provider", t); promise.failure(t); } }); return promise.future(); }
From source file:com.lithium.flow.util.LogExecutorService.java
@Nonnull public <T> ListenableFuture<T> submit(@Nonnull String name, @Nonnull Callable<T> callable) { checkNotNull(name);//from w w w . j ava2 s . com checkNotNull(callable); queued.incrementAndGet(); ListenableFuture<T> future = service.submit(callable); Futures.addCallback(future, new FutureCallback<T>() { @Override public void onSuccess(T object) { queued.decrementAndGet(); log.debug("execution finished: {}", name); } @Override public void onFailure(@Nonnull Throwable throwable) { queued.decrementAndGet(); log.warn("execution failed: {}", name, throwable); } }); return future; }
From source file:com.hortonworks.registries.cache.view.io.loader.CacheLoaderAsync.java
public void loadAll(final Collection<? extends K> keys, CacheLoaderCallback<K, V> callback) { try {//from ww w .java 2 s .co m ListenableFuture myCall = executorService.submit(new DataStoreCallable(keys)); Futures.addCallback(myCall, new CacheLoaderAsyncFutureCallback(keys, callback)); } catch (Exception e) { handleException(keys, callback, e, LOG); } }
From source file:io.v.mojo.discovery.UpdateImpl.java
@Override public void getAttachment(String name, GetAttachmentResponse callback) { Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> handles = mCore.createDataPipe(null); callback.call(handles.second);//from ww w. j av a2 s . c om final DataPipe.ProducerHandle producer = handles.first; try { Futures.addCallback(mUpdate.getAttachment(mContext, name), new FutureCallback<byte[]>() { @Override public void onSuccess(byte[] attachment) { try { ByteBuffer buf = ByteBuffer.allocateDirect(attachment.length); buf.put(attachment); producer.writeData(buf, WRITE_FLAG); } catch (MojoException e) { Log.e(DiscoveryApp.TAG, e.toString()); } finally { producer.close(); } } @Override public void onFailure(Throwable t) { // TODO(jhahn): Any way to notify an error to the requester? Log.e(DiscoveryApp.TAG, t.toString()); producer.close(); } }); } catch (VException e) { Log.e(DiscoveryApp.TAG, e.toString()); producer.close(); } }
From source file:dao.ClientCassandra.java
public static void saveNewEvent(Event evento) { PreparedStatement ps = session.prepare(insertEvent); BatchStatement batch = new BatchStatement(); batch.add(ps.bind(evento.getTimestamp().getTime(), evento.getQuery_timestamp().getTime(), evento.getClient_addr(), evento.getServer_addr(), evento.getTcp_seq_number(), //evento.getColumns(), evento.getConnection_start_timestamp().getTime(), //evento.getConnection_web_id(), evento.getDb_id(), evento.getDb_user_name(), //evento.getEnd_limit_timestamp().getTime(), //evento.getEvent_type(), evento.getQuery_text(), evento.getQuery_type(), evento.getTables())); Futures.addCallback(session.executeAsync(batch), callback()); }
From source file:com.microsoft.tooling.msservices.serviceexplorer.NodeAction.java
public void fireNodeActionEvent() { if (!listeners.isEmpty()) { final NodeActionEvent event = new NodeActionEvent(this); for (final NodeActionListener listener : listeners) { listener.beforeActionPerformed(event); Futures.addCallback(listener.actionPerformedAsync(event), new FutureCallback<Void>() { @Override// w w w . ja va 2 s . c om public void onSuccess(Void aVoid) { listener.afterActionPerformed(event); } @Override public void onFailure(Throwable throwable) { listener.afterActionPerformed(event); } }); } } }
From source file:io.crate.executor.transport.task.AbstractChainedTask.java
@Override public void start() { if (!this.upstreamResult.isEmpty()) { Futures.addCallback(Futures.allAsList(this.upstreamResult), new FutureCallback<List<TaskResult>>() { @Override//w w w . j av a 2 s. c om public void onSuccess(@Nullable List<TaskResult> result) { doStart(result); } @Override public void onFailure(@Nonnull Throwable t) { throw new TaskExecutionException(AbstractChainedTask.this, t); } }); } else { doStart(ImmutableList.<TaskResult>of()); } }