List of usage examples for com.google.common.util.concurrent Futures immediateFailedCheckedFuture
@GwtIncompatible("TODO") @CheckReturnValue public static <V, X extends Exception> CheckedFuture<V, X> immediateFailedCheckedFuture(X exception)
From source file:org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadWriteTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { try {//w w w . ja va 2 s .c o m return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent()); } catch (ReadFailedException e) { return Futures.immediateFailedCheckedFuture(e); } }
From source file:org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider.java
private CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> download( final SourceIdentifier sId) { final URL url = availableSources.get(sId); try (final InputStream in = url.openStream()) { final String schemaContent = new String(ByteStreams.toByteArray(in)); final NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource yangSource = new NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource( id, sId, Optional.of(schemaContent)); LOG.debug("Source {} downloaded from a yang library's url {}", sId, url); return Futures.immediateCheckedFuture(yangSource); } catch (IOException e) { LOG.warn("Unable to download source {} from a yang library's url {}", sId, url, e); return Futures.immediateFailedCheckedFuture( new SchemaSourceException("Unable to download remote schema for " + sId + " from " + url, e)); }// ww w. j a va 2s . co m }
From source file:org.opendaylight.aaa.authz.srv.AuthzDataReadWriteTransaction.java
@Deprecated @Override//from w ww . ja v a 2 s . c om public ListenableFuture<RpcResult<TransactionStatus>> commit() { if (AuthzServiceImpl.isAuthorized(ActionType.Commit)) { return domDataReadWriteTransaction.commit(); } TransactionCommitFailedException e = new TransactionCommitFailedException("Unauthorized User"); return Futures.immediateFailedCheckedFuture(e); }
From source file:org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache.java
@Override public CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) { final T present = cache.getIfPresent(sourceIdentifier); if (present != null) { return Futures.immediateCheckedFuture(present); }/* w w w .j ava2 s .c om*/ return Futures.immediateFailedCheckedFuture( new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
From source file:org.opendaylight.distributed.tx.impl.RollbackImpl.java
@Override public CheckedFuture<Void, DTxException.RollbackFailedException> rollback( @Nonnull final Map<InstanceIdentifier<?>, ? extends TxCache> perNodeCachesByType, @Nonnull final Map<InstanceIdentifier<?>, ? extends ReadWriteTransaction> perNodeRollbackTxs) { final List<ListenableFuture<Void>> perNodeRollbackSubmitFutures = Lists .newArrayListWithCapacity(perNodeRollbackTxs.size()); for (final Map.Entry<InstanceIdentifier<?>, ? extends TxCache> perNodeCacheEntry : perNodeCachesByType .entrySet()) {/*from ww w .j ava2 s. co m*/ InstanceIdentifier<?> nodeId = perNodeCacheEntry.getKey(); TxCache perNodeCache = perNodeCacheEntry.getValue(); final ReadWriteTransaction perNodeRollbackTx = perNodeRollbackTxs.get(nodeId); for (CachedData cachedData : perNodeCache) { final InstanceIdentifier<DataObject> dataId = (InstanceIdentifier<DataObject>) cachedData.getId(); ModifyAction revertAction = getRevertAction(cachedData.getOperation(), cachedData.getData()); switch (revertAction) { case REPLACE: { try { perNodeRollbackTx.put(cachedData.getDsType(), dataId, cachedData.getData().get()); break; } catch (Exception e) { return Futures.immediateFailedCheckedFuture(new DTxException.RollbackFailedException(String .format("Unable to rollback change for node: %s, %s data: %s. Node in unknown state.", perNodeCacheEntry.getKey(), revertAction, dataId), e)); } } case DELETE: { try { perNodeRollbackTx.delete(cachedData.getDsType(), dataId); break; } catch (Exception e) { return Futures.immediateFailedCheckedFuture(new DTxException.RollbackFailedException(String .format("Unable to rollback change for node: %s, %s data: %s. Node in unknown state.", perNodeCacheEntry.getKey(), revertAction, dataId), e)); } } case NONE: { break; } default: { return Futures.immediateFailedCheckedFuture(new DTxException.RollbackFailedException( "Unable to handle rollback for node: " + perNodeCacheEntry.getKey() + ", revert action: " + revertAction + ". Unknown operation type")); } } } CheckedFuture<Void, TransactionCommitFailedException> perNodeRollbackSumitFuture = null; try { perNodeRollbackSumitFuture = perNodeRollbackTx.submit(); } catch (Exception submitException) { perNodeRollbackSumitFuture = Futures.immediateFailedCheckedFuture( new TransactionCommitFailedException("Rollback submit error occur", submitException)); } perNodeRollbackSubmitFutures.add(perNodeRollbackSumitFuture); Futures.addCallback(perNodeRollbackSumitFuture, new LoggingRollbackCallback(perNodeCacheEntry.getKey())); } //} return aggregateRollbackFutures(perNodeRollbackSubmitFutures); }
From source file:org.opendaylight.aaa.authz.srv.AuthzWriteOnlyTransaction.java
@Override public CheckedFuture<Void, TransactionCommitFailedException> submit() { if (AuthzServiceImpl.isAuthorized(ActionType.Submit)) { return domDataWriteTransaction.submit(); }/*from w ww . j a v a 2 s . c om*/ TransactionCommitFailedException e = new TransactionCommitFailedException("Unauthorized User"); return Futures.immediateFailedCheckedFuture(e); }
From source file:com.google.cloud.bigtable.grpc.async.RetryingRpcFunction.java
@Override public ListenableFuture<ResponseT> apply(StatusRuntimeException statusException) throws Exception { final Status status = statusException.getStatus(); Status.Code code = status.getCode(); if (retryOptions.isRetryable(code) && isRetryable.apply(request)) { return backOffAndRetry(statusException, status); } else {/*from ww w. j a va 2 s . c o m*/ return Futures.immediateFailedCheckedFuture(statusException); } }
From source file:io.airlift.discovery.client.HttpDiscoveryAnnouncementClient.java
@Override public ListenableFuture<Duration> announce(Set<ServiceAnnouncement> services) { Preconditions.checkNotNull(services, "services is null"); URI uri = discoveryServiceURI.get(); if (uri == null) { return Futures .immediateFailedCheckedFuture(new DiscoveryException("No discovery servers are available")); }// ww w .j a va2s. com Announcement announcement = new Announcement(nodeInfo.getEnvironment(), nodeInfo.getNodeId(), nodeInfo.getPool(), nodeInfo.getLocation(), services); Request request = preparePut().setUri(URI.create(uri + "/v1/announcement/" + nodeInfo.getNodeId())) .setHeader("User-Agent", nodeInfo.getNodeId()).setHeader("Content-Type", MEDIA_TYPE_JSON.toString()) .setBodyGenerator(jsonBodyGenerator(announcementCodec, announcement)).build(); return httpClient.executeAsync(request, new DiscoveryResponseHandler<Duration>("Announcement", uri) { @Override public Duration handle(Request request, Response response) throws DiscoveryException { int statusCode = response.getStatusCode(); if (!isSuccess(statusCode)) { throw new DiscoveryException(String.format("Announcement failed with status code %s: %s", statusCode, getBodyForError(response))); } Duration maxAge = extractMaxAge(response); return maxAge; } }); }
From source file:com.google.appengine.tools.cloudstorage.oauth.AbstractOAuthURLFetchService.java
@Override public Future<HTTPResponse> fetchAsync(HTTPRequest req) { HTTPRequest authorizedRequest;// www. j a v a2s . co m try { authorizedRequest = createAuthorizeRequest(req); } catch (RetryHelperException e) { return Futures.immediateFailedCheckedFuture(e); } return urlFetch.fetchAsync(authorizedRequest); }
From source file:org.opendaylight.mdsal.dom.broker.SerializedDOMDataBroker.java
@Override protected CheckedFuture<Void, TransactionCommitFailedException> submit( final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts) { Preconditions.checkArgument(transaction != null, "Transaction must not be null."); Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier()); ListenableFuture<Void> commitFuture = null; try {/*from w w w . j a v a2s.c o m*/ commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts, commitStatsTracker)); } catch (RejectedExecutionException e) { LOG.error("The commit executor's queue is full - submit task was rejected. \n" + executor, e); return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException( "Could not submit the commit task - the commit queue capacity has been exceeded.", e)); } return MappingCheckedFuture.create(commitFuture, TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER); }