List of usage examples for com.google.common.util.concurrent Futures immediateFailedFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable)
From source file:org.jclouds.blobstore.LocalAsyncBlobStore.java
/** * {@inheritDoc}/*w w w . j ava2 s . c o m*/ */ @Override public ListenableFuture<String> putBlob(String containerName, Blob blob) { checkNotNull(containerName, "containerName must be set"); checkNotNull(blob, "blob must be set"); String blobKey = blob.getMetadata().getName(); logger.debug("Put blob with key [%s] to container [%s]", blobKey, containerName); if (!storageStrategy.containerExists(containerName)) { return Futures .immediateFailedFuture(new IllegalStateException("containerName not found: " + containerName)); } try { return immediateFuture(storageStrategy.putBlob(containerName, blob)); } catch (IOException e) { logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey, containerName); throw Throwables.propagate(e); } }
From source file:org.jclouds.blobstore.TransientAsyncBlobStore.java
/** * throws IllegalStateException if the container already exists */// w w w . j ava 2s. c o m public ListenableFuture<Void> createContainerInLocationIfAbsent(final Location location, final String name) { ConcurrentMap<String, Blob> container = getContainerToBlobs().putIfAbsent(name, new ConcurrentHashMap<String, Blob>()); if (container == null) { getContainerToLocation().put(name, location != null ? location : defaultLocation.get()); return immediateFuture((Void) null); } else { return Futures .immediateFailedFuture(new IllegalStateException("container " + name + " already exists")); } }
From source file:com.mypurecloud.sdk.v2.api.LicenseApiAsync.java
/** * Get PureCloud license feature toggle value. * //from w w w .j a va2 s. co m * @param request the request object * @param callback the action to perform when the request is completed * @return the future indication when the request has completed */ public Future<ApiResponse<LicenseOrgToggle>> getLicenseToggleAsync(ApiRequest<Void> request, final AsyncApiCallback<ApiResponse<LicenseOrgToggle>> callback) { try { final SettableFuture<ApiResponse<LicenseOrgToggle>> future = SettableFuture.create(); final boolean shouldThrowErrors = pcapiClient.getShouldThrowErrors(); pcapiClient.invokeAsync(request, new TypeReference<LicenseOrgToggle>() { }, new AsyncApiCallback<ApiResponse<LicenseOrgToggle>>() { @Override public void onCompleted(ApiResponse<LicenseOrgToggle> response) { notifySuccess(future, callback, response); } @Override public void onFailed(Throwable exception) { if (exception instanceof ApiException) { @SuppressWarnings("unchecked") ApiResponse<LicenseOrgToggle> response = (ApiResponse<LicenseOrgToggle>) (ApiResponse<?>) exception; notifySuccess(future, callback, response); } if (shouldThrowErrors) { notifyFailure(future, callback, exception); } else { @SuppressWarnings("unchecked") ApiResponse<LicenseOrgToggle> response = (ApiResponse<LicenseOrgToggle>) (ApiResponse<?>) (new ApiException( exception)); notifySuccess(future, callback, response); } } }); return future; } catch (Throwable exception) { return Futures.immediateFailedFuture(exception); } }
From source file:org.opendaylight.faas.fabric.general.FabricServiceAPIProvider.java
@Override public Future<RpcResult<CreateGatewayOutput>> createGateway(CreateGatewayInput input) { final RpcResultBuilder<CreateGatewayOutput> resultBuilder = RpcResultBuilder.<CreateGatewayOutput>success(); CreateGatewayOutputBuilder outputBuilder = new CreateGatewayOutputBuilder(); final FabricId fabricId = input.getFabricId(); final NodeId routerId = input.getLogicalRouter(); final NodeId swId = input.getLogicalSwitch(); final FabricInstance fabricObj = FabricInstanceCache.INSTANCE.retrieveFabric(fabricId); if (fabricObj == null) { return Futures.immediateFailedFuture( new IllegalArgumentException(String.format("fabric %s does not exist", fabricId))); }/*from w w w. j a v a2 s . c o m*/ WriteTransaction trans = dataBroker.newWriteOnlyTransaction(); // add logic port to Router TpId tpid1 = createGWPortOnRouter(input, outputBuilder, trans, fabricObj); // add logic port to switch TpId tpid2 = createGWPortOnSwitch(fabricId, swId, trans); // add link LinkId linkId = createGatewayLink(routerId, tpid1); createLogicLink(fabricId, routerId, swId, trans, tpid1, tpid2, linkId); return Futures.transform(trans.submit(), new AsyncFunction<Void, RpcResult<CreateGatewayOutput>>() { @Override public ListenableFuture<RpcResult<CreateGatewayOutput>> apply(Void submitResult) throws Exception { resultBuilder.withResult(outputBuilder); return Futures.immediateFuture(resultBuilder.build()); } }, executor); }
From source file:org.opendaylight.faas.fabricmgr.VContainerNetNodeServiceProvider.java
@Override public Future<RpcResult<Void>> rmLneLayer3(RmLneLayer3Input input) { VcLneId lrId = input.getLneId();/*from w ww .j ava 2s . com*/ RmLogicalRouterInputBuilder inputBuilder = new RmLogicalRouterInputBuilder(); FabricId fabricId = new FabricId(input.getVfabricId()); inputBuilder.setFabricId(fabricId); inputBuilder.setNodeId(new NodeId(lrId)); LOG.debug("FABMGR: rmLneLayer3: fabricId={}, lrId={}", fabricId.getValue(), lrId.getValue()); final RpcResultBuilder<Void> resultBuilder = RpcResultBuilder.<Void>success(); Future<RpcResult<Void>> result = this.fabServiceService.rmLogicalRouter(inputBuilder.build()); try { RpcResult<Void> output = result.get(); if (output.isSuccessful()) { LOG.debug("FABMGR: rmLneLayer3: rmLogicRouter RPC success"); return result; } else { return Futures.immediateFuture( resultBuilder.withError(ErrorType.RPC, "rmLogicRouter RPC failed").build()); } } catch (Exception e) { LOG.error("FABMGR: ERROR: rmLneLayer3: rmLogicRouter RPC failed.", e); } return Futures.immediateFailedFuture(new IllegalArgumentException("rmLogicRouter RPC failed")); }
From source file:io.v.v23.rpc.ReflectInvoker.java
@Override public ListenableFuture<Type[]> getArgumentTypes(VContext ctx, String method) { try {/*from ww w .ja v a 2 s . co m*/ return Futures.immediateFuture(findMethod(method).getArgumentTypes()); } catch (VException e) { return Futures.immediateFailedFuture(e); } }
From source file:io.v.v23.rpc.ReflectInvoker.java
@Override public ListenableFuture<Type[]> getResultTypes(VContext ctx, String method) { try {//from w w w . ja v a 2s .c o m return Futures.immediateFuture(findMethod(method).getResultTypes()); } catch (VException e) { return Futures.immediateFailedFuture(e); } }
From source file:io.v.v23.rpc.ReflectInvoker.java
@Override public ListenableFuture<VdlValue[]> getMethodTags(VContext ctx, String method) { try {//from www . j a v a 2 s. com return Futures.immediateFuture(findMethod(method).getTags()); } catch (VException e) { return Futures.immediateFailedFuture(e); } }
From source file:com.mypurecloud.sdk.v2.api.LicenseApiAsync.java
/** * Get licenses for specified user./*from ww w .j a v a 2 s .com*/ * * @param request the request object * @param callback the action to perform when the request is completed * @return the future indication when the request has completed */ public Future<LicenseUser> getLicenseUserAsync(GetLicenseUserRequest request, final AsyncApiCallback<LicenseUser> callback) { try { final SettableFuture<LicenseUser> future = SettableFuture.create(); final boolean shouldThrowErrors = pcapiClient.getShouldThrowErrors(); pcapiClient.invokeAsync(request.withHttpInfo(), new TypeReference<LicenseUser>() { }, new AsyncApiCallback<ApiResponse<LicenseUser>>() { @Override public void onCompleted(ApiResponse<LicenseUser> response) { notifySuccess(future, callback, response.getBody()); } @Override public void onFailed(Throwable exception) { if (shouldThrowErrors) { notifyFailure(future, callback, exception); } else { notifySuccess(future, callback, null); } } }); return future; } catch (Throwable exception) { return Futures.immediateFailedFuture(exception); } }
From source file:org.opendaylight.netvirt.natservice.internal.VpnFloatingIpHandler.java
@Override public void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp, final long label) { //Remove Prefix from BGP String rd = NatUtil.getVpnRd(dataBroker, vpnName); NatUtil.removePrefixFromBGP(dataBroker, bgpManager, fibManager, rd, externalIp + "/32", vpnName, LOG); //Remove custom FIB routes //Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input); RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId) .setIpAddress(externalIp + "/32").setServiceId(label).build(); Future<RpcResult<Void>> future = fibService.removeFibEntry(input); ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform( JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> { //Release label if (result.isSuccessful()) { removeTunnelTableEntry(dpnId, label); removeLFibTableEntry(dpnId, label); RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput); return JdkFutureAdapters.listenInPoolThread(labelFuture1); } else { String errMsg = String.format( "RPC call to remove custom FIB entries on dpn %s for " + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors()); LOG.error(errMsg);//from w w w.j a v a 2s . com return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } }); Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { LOG.error("Error in removing the label or custom fib entries", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { LOG.debug("Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName); } else { LOG.error("Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors()); } } }); }