List of usage examples for com.google.common.util.concurrent Futures immediateFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFuture(@Nullable V value)
From source file:io.joynr.jeeintegration.messaging.JeeServletMessageReceiver.java
@Override public Future<Void> start(MessageArrivedListener messageArrivedListener, ReceiverStatusListener... receiverStatusListeners) { if (messageArrivedListener == null) { throw new IllegalStateException(); }/*from w ww. ja v a 2 s .c om*/ LOG.info("Starting JeeServletMessageReceiver with listener {}", messageArrivedListener); this.messageListener = messageArrivedListener; if (!registered) { registerChannelUrl(); } return Futures.immediateFuture(null); }
From source file:org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal.FlowServiceAdapter.java
@Override public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) { Flow flow = ToSalConversionsUtils.toFlow(input, null); @SuppressWarnings("unchecked") org.opendaylight.controller.sal.core.Node node = InventoryMapping .toAdNode((InstanceIdentifier<Node>) input.getNode().getValue()); Status status = delegate.removeFlowAsync(node, flow); RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder(); builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId()))); RemoveFlowOutput rpcResultType = builder.build(); return Futures.immediateFuture( RpcResultBuilder.<RemoveFlowOutput>status(status.isSuccess()).withResult(rpcResultType).build()); }
From source file:org.opendaylight.controller.sample.kitchen.impl.KitchenServiceImpl.java
@Override public Future<RpcResult<Void>> makeBreakfast(EggsType eggsType, Class<? extends ToastType> toastType, int toastDoneness) { // Call makeToast and use JdkFutureAdapters to convert the Future to a ListenableFuture, // The OpendaylightToaster impl already returns a ListenableFuture so the conversion is // actually a no-op. ListenableFuture<RpcResult<Void>> makeToastFuture = JdkFutureAdapters .listenInPoolThread(makeToast(toastType, toastDoneness), executor); ListenableFuture<RpcResult<Void>> makeEggsFuture = makeEggs(eggsType); // Combine the 2 ListenableFutures into 1 containing a list of RpcResults. ListenableFuture<List<RpcResult<Void>>> combinedFutures = Futures .allAsList(ImmutableList.of(makeToastFuture, makeEggsFuture)); // Then transform the RpcResults into 1. return Futures.transform(combinedFutures, new AsyncFunction<List<RpcResult<Void>>, RpcResult<Void>>() { @Override//from w ww. j ava2 s .co m public ListenableFuture<RpcResult<Void>> apply(List<RpcResult<Void>> results) throws Exception { boolean atLeastOneSucceeded = false; Builder<RpcError> errorList = ImmutableList.builder(); for (RpcResult<Void> result : results) { if (result.isSuccessful()) { atLeastOneSucceeded = true; } if (result.getErrors() != null) { errorList.addAll(result.getErrors()); } } return Futures.immediateFuture(RpcResultBuilder.<Void>status(atLeastOneSucceeded) .withRpcErrors(errorList.build()).build()); } }); }
From source file:com.facebook.buck.remoteexecution.util.MultiThreadedBlobUploader.java
private ListenableFuture<Void> enqueue(ImmutableMap<Digest, UploadDataSupplier> data) { ImmutableList.Builder<ListenableFuture<Void>> futures = ImmutableList.builder(); for (Entry<Digest, UploadDataSupplier> entry : data.entrySet()) { Digest digest = entry.getKey();/*from ww w . j a va 2s . co m*/ ListenableFuture<Void> resultFuture = pendingUploads.computeIfAbsent(digest.getHash(), hash -> { if (containedHashes.contains(hash)) { return Futures.immediateFuture(null); } SettableFuture<Void> future = SettableFuture.create(); waitingMissingCheck.add(new PendingUpload(new UploadData(digest, entry.getValue()), future)); return Futures.transform(future, ignore -> { // If the upload was successful short circuit for future requests. containedHashes.add(digest.getHash()); return null; }, directExecutor()); }); Futures.addCallback(resultFuture, MoreFutures.finallyCallback(() -> { pendingUploads.remove(digest.getHash()); }), directExecutor()); futures.add(resultFuture); uploadService.submit(this::processUploads); } return Futures.whenAllSucceed(futures.build()).call(() -> null, directExecutor()); }
From source file:c5db.log.QuorumDelegatingLog.java
@Override public ListenableFuture<List<OLogEntry>> getLogEntries(long start, long end, String quorumId) { if (end < start) { throw new IllegalArgumentException("getLogEntries: end < start"); } else if (end == start) { return Futures.immediateFuture(new ArrayList<>()); }/*from w ww . ja v a 2s.co m*/ return submitQuorumTask(quorumId, () -> { if (!seqNumPrecedesLog(start, getQuorumStructure(quorumId).currentLogWithHeader())) { return currentLog(quorumId).subSequence(start, end); } else { return multiLogGet(start, end, quorumId); } }); }
From source file:org.opendaylight.lockmanager.LockManager.java
@Override public Future<RpcResult<Void>> tryLock(TryLockInput input) { String lockName = input.getLockName(); LOG.info("Locking {}", lockName); long waitTime = input.getTime() == null ? DEFAULT_WAIT_TIME_IN_MILLIS * DEFAULT_RETRY_COUNT : input.getTime();//from ww w .ja va 2 s. c om TimeUnit timeUnit = input.getTimeUnit() == null ? TimeUnit.MILLISECONDS : LockManagerUtils.convertToTimeUnit(input.getTimeUnit()); waitTime = timeUnit.toMillis(waitTime); long retryCount = waitTime / DEFAULT_WAIT_TIME_IN_MILLIS; InstanceIdentifier<Lock> lockInstanceIdentifier = LockManagerUtils.getLockInstanceIdentifier(lockName); Lock lockData = LockManagerUtils.buildLockData(lockName); RpcResultBuilder<Void> lockRpcBuilder; try { if (getLock(lockInstanceIdentifier, lockData, retryCount)) { lockRpcBuilder = RpcResultBuilder.success(); LOG.info("Acquired lock {}", lockName); } else { lockRpcBuilder = RpcResultBuilder.failed(); LOG.info("Failed to get lock {}", lockName); } } catch (InterruptedException e) { lockRpcBuilder = RpcResultBuilder.failed(); LOG.info("Failed to get lock {}", lockName, e); } return Futures.immediateFuture(lockRpcBuilder.build()); }
From source file:com.proofpoint.testing.SerialScheduledExecutorService.java
@Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables) throws InterruptedException { Preconditions.checkNotNull(callables, "Task object list is null"); ImmutableList.Builder<Future<T>> resultBuilder = ImmutableList.builder(); for (Callable<T> callable : callables) { try {/*from w w w . j a va2s .co m*/ resultBuilder.add(Futures.immediateFuture(callable.call())); } catch (Exception e) { resultBuilder.add(Futures.<T>immediateFailedFuture(e)); } } return resultBuilder.build(); }
From source file:org.apache.shindig.social.websockbackend.spi.WsNativeAppDataSPI.java
@Override public Future<DataCollection> getPersonData(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, SecurityToken token) throws ProtocolException { String group = null;//from ww w . j a v a2 s . c o m if (groupId != null) { // actual group if (groupId.getType() == GroupId.Type.objectId) { group = groupId.getObjectId().toString(); } // group type else { group = '@' + groupId.getType().toString(); } } // create query final WebsockQuery query = new WebsockQuery(EQueryType.PROCEDURE_CALL); query.setPayload(ShindigNativeQueries.GET_APP_DATA_QUERY); // set parameters for method final List<String> idList = new ArrayList<String>(); for (final UserId userId : userIds) { idList.add(userId.getUserId(token)); } query.setParameter(ShindigNativeQueries.USER_ID_LIST, idList); query.setParameter(ShindigNativeQueries.GROUP_ID, group); query.setParameter(ShindigNativeQueries.APP_ID, appId); if (fields != null) { final List<String> fieldList = new ArrayList<String>(fields); query.setParameter(ShindigNativeQueries.FIELD_LIST, fieldList); } // execute and convert result final IQueryCallback callback = this.fQueryHandler.sendQuery(query); SingleResult result = null; try { result = (SingleResult) callback.get(); } catch (final Exception e) { e.printStackTrace(); this.fLogger.log(Level.SEVERE, "server error", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "could not retrieve result", e); } @SuppressWarnings("unchecked") final DataCollection dataColl = new DataCollection((Map<String, Map<String, Object>>) result.getResults()); return Futures.immediateFuture(dataColl); }
From source file:com.rhythm.louie.util.FutureList.java
@Override public E set(int index, E element) { futures.set(index, Futures.immediateFuture(element)); // not sure what to return here return element; }
From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java
@Override public <T> Future<Map<T, Long>> incrementAll(Map<T, Long> offsets, Long initialValue) { return Futures.immediateFuture(memcacheService.incrementAll(offsets, initialValue)); }