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:org.jclouds.virtualbox.compute.extensions.VirtualBoxImageExtension.java
@Override public ListenableFuture<Image> createImage(ImageTemplate template) { checkState(template instanceof CloneImageTemplate, " vbox image extension only supports cloning for the moment."); CloneImageTemplate cloneTemplate = CloneImageTemplate.class.cast(template); IMachine source = manager.get().getVBox().findMachine(cloneTemplate.getSourceNodeId()); String flags = ""; List<String> groups = ImmutableList.of(); String group = ""; String settingsFile = manager.get().getVBox().composeMachineFilename(template.getName(), group, flags, workingDir);// w w w.j a v a 2s . co m IMachine clonedMachine = manager.get().getVBox().createMachine(settingsFile, template.getName(), groups, source.getOSTypeId(), flags); List<CloneOptions> options = Lists.newArrayList(); if (isLinkedClone) options.add(CloneOptions.Link); // TODO snapshot name ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "pre-image-spawn", "before spawning " + template.getName(), logger).apply(source); checkNotNull(currentSnapshot); // clone IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); progress.waitForCompletion(-1); logger.debug(String.format("<< master(%s) is cloned correctly to vm(%s)", source.getName(), clonedMachine.getName())); // registering manager.get().getVBox().registerMachine(clonedMachine); return Futures.immediateFuture(imachineToImage.apply(clonedMachine)); }
From source file:org.apache.qpid.server.security.FileTrustStoreImpl.java
@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE) protected ListenableFuture<Void> doActivate() { setState(State.ACTIVE); return Futures.immediateFuture(null); }
From source file:com.google.gapid.server.Client.java
public ListenableFuture<List<Path.Device>> getDevices() { LOG.log(FINE, "RPC->getDevices()"); return Futures.transformAsync(client.getDevices(GetDevicesRequest.newBuilder().build()), in -> Futures.immediateFuture(throwIfError(in.getDevices(), in.getError()).getListList())); }
From source file:org.opendaylight.netvirt.fibmanager.FibRpcServiceImpl.java
/** * To install FIB routes on specified dpn with given instructions. */// w w w .ja v a2s . c om @Override public Future<RpcResult<Void>> createFibEntry(CreateFibEntryInput input) { BigInteger dpnId = input.getSourceDpid(); String vpnName = input.getVpnName(); long vpnId = getVpnId(dataBroker, vpnName); String vpnRd = getVpnRd(dataBroker, vpnName); String ipAddress = input.getIpAddress(); LOG.info("Create custom FIB entry - {} on dpn {} for VPN {} ", ipAddress, dpnId, vpnName); List<Instruction> instructions = input.getInstruction(); LOG.info("ADD: Adding Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId()); makeLocalFibEntry(vpnId, dpnId, ipAddress, instructions); updateVpnToDpnAssociation(vpnId, dpnId, ipAddress, vpnName); LOG.info("ADD: Added Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId()); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:org.opendaylight.openflowplugin.impl.role.RoleManagerImpl.java
@Override public void onDeviceContextLevelUp(@CheckForNull final DeviceContext deviceContext) { LOG.debug("RoleManager called for device:{}", deviceContext.getPrimaryConnectionContext().getNodeId()); if (deviceContext.getDeviceState().getFeatures().getVersion() < OFConstants.OFP_VERSION_1_3) { // Roles are not supported before OF1.3, so move forward. deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceContext); return;//from w w w. j a v a 2s .co m } final RoleContext roleContext = new RoleContextImpl(deviceContext, entityOwnershipService, makeEntity(deviceContext.getDeviceState().getNodeId())); // if the device context gets closed (mostly on connection close), we would need to cleanup deviceContext.addDeviceContextClosedHandler(this); Verify.verify(contexts.putIfAbsent(roleContext.getEntity(), roleContext) == null, "RoleCtx for master Node {} is still not close.", deviceContext.getDeviceState().getNodeId()); final ListenableFuture<OfpRole> roleChangeFuture = roleContext.initialization(); final ListenableFuture<Void> initDeviceFuture = Futures.transform(roleChangeFuture, new AsyncFunction<OfpRole, Void>() { @Override public ListenableFuture<Void> apply(final OfpRole input) throws Exception { final ListenableFuture<Void> nextFuture; if (OfpRole.BECOMEMASTER.equals(input)) { LOG.debug("Node {} was initialized", deviceContext.getDeviceState().getNodeId()); nextFuture = DeviceInitializationUtils.initializeNodeInformation(deviceContext, switchFeaturesMandatory); } else { LOG.debug("Node {} we are not Master so we are going to finish.", deviceContext.getDeviceState().getNodeId()); nextFuture = Futures.immediateFuture(null); } return nextFuture; } }); Futures.addCallback(initDeviceFuture, new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { LOG.debug("Initialization Node {} is done.", deviceContext.getDeviceState().getNodeId()); getRoleContextLevelUp(deviceContext); } @Override public void onFailure(final Throwable t) { LOG.warn("Unexpected error for Node {} initialization", deviceContext.getDeviceState().getNodeId(), t); deviceContext.close(); } }); }
From source file:com.android.tools.idea.run.ConnectedAndroidDevice.java
@NotNull @Override public ListenableFuture<IDevice> getLaunchedDevice() { return Futures.immediateFuture(myDevice); }
From source file:org.opendaylight.tsdr.datastorage.TSDRStorageServiceImpl.java
/** * stores TSDRMetricRecord./* ww w . j a va 2 s .c om*/ * */ @Override public Future<RpcResult<java.lang.Void>> storeTSDRMetricRecord(StoreTSDRMetricRecordInput input) { log.debug("Entering TSDRStorageService.storeTSDRMetrics()"); if (input == null || input.getTSDRMetricRecord() == null) { log.error("Input of storeTSDRMetrics is null"); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); } List<TSDRMetricRecord> tsdrMetricRecordList = new ArrayList<TSDRMetricRecord>( input.getTSDRMetricRecord().size()); tsdrMetricRecordList.addAll(input.getTSDRMetricRecord()); if (this.metricPersistenceService != null) { metricPersistenceService.storeMetric(tsdrMetricRecordList); } else { log.warn("storeTSDRMetricRecord: cannot store the metric -- persistence service is found to be null"); } log.debug("Exiting TSDRStorageService.storeTSDRMetrics()"); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:org.opendaylight.ipsec.impl.IPsecImpl.java
@Override public Future<RpcResult<RuleAllOutput>> ruleAll(RuleAllInput input) { List<IPsecRule> rules = IPsecRuleBuffer.listAll(); JSONArray jsonRules = new JSONArray(); for (IPsecRule ir : rules) { jsonRules.put(new JSONObject(ir)); }// w w w . ja v a 2s.c o m RuleAllOutputBuilder builder = new RuleAllOutputBuilder(); builder.setResult(jsonRules.toString()); RpcResult<RuleAllOutput> rpcResult = Rpcs.<RuleAllOutput>getRpcResult(true, builder.build(), Collections.<RpcError>emptySet()); return Futures.immediateFuture(rpcResult); }
From source file:org.apache.shindig.social.websockbackend.spi.WsNativeFriendSPI.java
@Override public Future<Void> requestFriendship(UserId userId, Person target, SecurityToken token) { // create query final WebsockQuery query = new WebsockQuery(EQueryType.PROCEDURE_CALL); query.setPayload(ShindigNativeQueries.REQUEST_FRIENDSHIP_QUERY); // set parameters for method query.setParameter(ShindigNativeQueries.USER_ID, userId.getUserId(token)); query.setParameter(ShindigNativeQueries.TARGET_USER_ID, target.getId()); try {/*from ww w . ja v a 2s. c o m*/ this.fQueryHandler.sendQuery(query).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 request or confirm friendship", e); } return Futures.immediateFuture(null); }
From source file:com.infinities.skyport.cache.impl.service.compute.CachedMachineImageSupportImpl.java
@Override public AsyncResult<Iterable<MachineImage>> listImages(ImageFilterOptions options) throws CloudException, InternalException { if (options == null || (!options.hasCriteria() && !options.isMatchesAny())) { Iterable<MachineImage> list = new ArrayList<MachineImage>(imageCache.values()); ListenableFuture<Iterable<MachineImage>> future = Futures.immediateFuture(list); AsyncResult<Iterable<MachineImage>> ret = new AsyncResult<Iterable<MachineImage>>(future); return ret; } else {/* ww w . ja v a2 s . com*/ return inner.listImages(options); } }