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:com.vsct.strowgr.monitoring.aggregator.cassandra.ErrorRecordWriter.java
public void write(ErrorRecord payload) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Record message processing error. Payload=" + payload.getPayload()); BoundStatement bound = writeRawPayloadPeparedStatement.bind(payload.getDate(), payload.getTimestamp(), payload.getReason(), payload.getPayload()); Futures.addCallback(session.executeAsync(bound), new FutureCallback<ResultSet>() { @Override/*from w w w.j a v a2s . c o m*/ public void onSuccess(ResultSet rows) { } @Override public void onFailure(Throwable throwable) { LOGGER.error("Could not send message processing error to cassandra. Everything relies on the log."); } }); }
From source file:io.crate.executor.transport.DelayedTask.java
@Override public void execute(final RowReceiver rowReceiver, final Row parameters) { Futures.addCallback(listenableFuture, new FutureCallback<Object>() { @Override// www . j ava 2 s .c om public void onSuccess(@Nullable Object result) { rootTask.get().execute(rowReceiver, parameters); } @Override public void onFailure(@Nonnull Throwable t) { rowReceiver.fail(t); } }); }
From source file:org.opendaylight.tl1.impl.MDSal.java
public static void initializeDataTree(DataBroker db) { dbroker = db;//from w ww .j a va2 s . co m LOG.info("Preparing to initialize the greeting registry"); WriteTransaction transaction = db.newWriteOnlyTransaction(); InstanceIdentifier<DeviceRegistry> iid = InstanceIdentifier.create(DeviceRegistry.class); DeviceRegistry registry = new DeviceRegistryBuilder().build(); transaction.put(LogicalDatastoreType.OPERATIONAL, iid, registry); CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); Futures.addCallback(future, new LoggingFuturesCallBack<Void>("Failed to write greeting to greeting registry", LOG)); }
From source file:com.microsoft.office.integration.test.FoldersAsyncTestCase.java
public void testRead() { prepareFolder();/*from w ww .j ava2 s . c o 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 { FoldersAsyncTestCase.this.readAndCheck(); FoldersAsyncTestCase.this.removeFolder(); } catch (Throwable t) { reportError(t); } counter.countDown(); } }); try { if (!counter.await(60000, TimeUnit.MILLISECONDS)) { fail("testRead() timed out"); } } catch (InterruptedException e) { fail("testRead() has been interrupted"); } }
From source file:com.kixeye.chassis.transport.http.ListenableFutureReturnValueHandler.java
@Override public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); return;/*from www . java2s.c o m*/ } final DeferredResult<Object> deferredResult = new DeferredResult<>(); Futures.addCallback((ListenableFuture<?>) returnValue, new FutureCallback<Object>() { @Override public void onSuccess(@Nullable Object result) { deferredResult.setResult(result); } @Override public void onFailure(Throwable t) { deferredResult.setErrorResult(t); } }); WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer); }
From source file:org.springframework.cassandra.core.GuavaListenableFutureAdapter.java
private static <T> ListenableFuture<T> adaptListenableFuture( com.google.common.util.concurrent.ListenableFuture<T> guavaFuture, PersistenceExceptionTranslator exceptionTranslator) { SettableListenableFuture<T> settableFuture = new SettableListenableFuture<>(); Futures.addCallback(guavaFuture, new FutureCallback<T>() { @Override/*from www .ja v a 2 s .co m*/ public void onSuccess(T result) { settableFuture.set(result); } @Override public void onFailure(Throwable t) { if (t instanceof RuntimeException) { DataAccessException dataAccessException = exceptionTranslator .translateExceptionIfPossible((RuntimeException) t); if (dataAccessException != null) { settableFuture.setException(dataAccessException); return; } } settableFuture.setException(t); } }); return settableFuture; }
From source file:org.opendaylight.netvirt.elan.utils.ElanClusterUtils.java
public static void runOnlyInLeaderNode(EntityOwnershipService entityOwnershipService, final String jobKey, final String jobDescription, final Callable<List<ListenableFuture<Void>>> dataStoreJob) { ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner( entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE, HwvtepSouthboundConstants.ELAN_ENTITY_NAME); Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() { @Override/* w w w. j a v a 2 s.c o m*/ public void onSuccess(Boolean isOwner) { if (isOwner) { LOG.trace("scheduling job {} ", jobDescription); DataStoreJobCoordinator.getInstance().enqueueJob(jobKey, dataStoreJob, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries()); } else { LOG.trace("job is not run as i m not cluster owner desc :{} ", jobDescription); } } @Override public void onFailure(Throwable error) { LOG.error("Failed to identity cluster owner for job " + jobDescription, error); } }); }
From source file:org.springframework.data.cassandra.core.cql.GuavaListenableFutureAdapter.java
private static <T> ListenableFuture<T> adaptListenableFuture( com.google.common.util.concurrent.ListenableFuture<T> guavaFuture, PersistenceExceptionTranslator exceptionTranslator) { SettableListenableFuture<T> settableFuture = new SettableListenableFuture<>(); Futures.addCallback(guavaFuture, new FutureCallback<T>() { @Override/*w ww . j av a 2 s. c o m*/ public void onSuccess(@Nullable T result) { settableFuture.set(result); } @Override public void onFailure(Throwable t) { if (t instanceof RuntimeException) { DataAccessException dataAccessException = exceptionTranslator .translateExceptionIfPossible((RuntimeException) t); if (dataAccessException != null) { settableFuture.setException(dataAccessException); return; } } settableFuture.setException(t); } }); return settableFuture; }
From source file:org.opendaylight.vtn.manager.internal.util.rpc.RpcFuture.java
/** * Construct a new future which represents an ongoing RPC request. * * @param f A {@link VTNFuture} associated with the main procedure of * RPC./* ww w. j a v a2s .co m*/ * @param gen RPC output generator. */ public RpcFuture(VTNFuture<I> f, RpcOutputGenerator<I, O> gen) { generator = gen; Futures.addCallback(f, this); }
From source file:com.microsoft.services.odata.ODataMediaEntityFetcher.java
public ListenableFuture<byte[]> getContent() { final SettableFuture<byte[]> result = SettableFuture.create(); Request request = getResolver().createRequest(); request.setVerb(HttpVerb.GET);//from www. java 2 s . c o m ODataURL url = request.getUrl(); url.appendPathComponent("$value"); ListenableFuture<ODataResponse> future = oDataExecute(request); Futures.addCallback(future, new FutureCallback<ODataResponse>() { @Override public void onSuccess(ODataResponse response) { result.set(response.getPayload()); } @Override public void onFailure(Throwable t) { result.setException(t); } }); return result; }