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.opendaylight.openflowplugin.applications.frsync.impl.SyncReactorFutureZipDecorator.java
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath, final SyncupEntry syncupEntry) throws InterruptedException { final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath); LOG.trace("syncup zip decorator: {}", nodeId.getValue()); try {/*from w w w . j av a2 s .co m*/ compressionGuard.acquire(); final boolean newFutureNecessary = updateCompressionState(flowcapableNodePath, syncupEntry); if (newFutureNecessary) { super.syncup(flowcapableNodePath, syncupEntry); } return Futures.immediateFuture(true); } finally { compressionGuard.release(); } }
From source file:com.facebook.buck.artifact_cache.ArtifactUploader.java
public static ListenableFuture<Void> performUploadToArtifactCache(ImmutableSet<RuleKey> ruleKeys, ArtifactCache artifactCache, BuckEventBus eventBus, ImmutableMap<String, String> buildMetadata, SortedSet<Path> pathsToIncludeInArchive, BuildTarget buildTarget, ProjectFilesystem projectFilesystem, long buildTimeMs) { NamedTemporaryFile archive;/*from w ww. j av a 2 s .c o m*/ try { archive = getTemporaryArtifactArchive(buildTarget, projectFilesystem, ruleKeys, eventBus, pathsToIncludeInArchive); } catch (BuckUncheckedExecutionException e) { LOG.error(e.getMessage()); LOG.debug(e.toString() + "\n" + Throwables.getStackTraceAsString(e)); return Futures.immediateFuture(null); } // Store the artifact, including any additional metadata. ListenableFuture<Void> storeFuture = artifactCache.store(ArtifactInfo.builder().setRuleKeys(ruleKeys) .setMetadata(buildMetadata).setBuildTimeMs(buildTimeMs).build(), BorrowablePath.borrowablePath(archive.get())); Futures.addCallback(storeFuture, new FutureCallback<Void>() { @Override public void onSuccess(Void result) { onCompletion(); } @Override public void onFailure(Throwable t) { onCompletion(); new ErrorLogger(new ErrorLogger.LogImpl() { @Override public void logUserVisible(String message) { } @Override public void logUserVisibleInternalError(String message) { } @Override public void logVerbose(Throwable e) { LOG.debug(t, "When storing RuleKeys %s to the cache for %s.", ruleKeys, buildTarget); } }, new HumanReadableExceptionAugmentor(ImmutableMap.of())).logException(t); } private void onCompletion() { try { // The archive file may have been borrowed when storing to the cache so only close it // if // it still exists. if (Files.exists(archive.get())) { archive.close(); } } catch (IOException e) { new ErrorLogger(new ErrorLogger.LogImpl() { @Override public void logUserVisible(String message) { } @Override public void logUserVisibleInternalError(String message) { } @Override public void logVerbose(Throwable e) { LOG.debug(e, "When deleting temporary archive %s for upload of %s.", archive.get(), buildTarget); } }, new HumanReadableExceptionAugmentor(ImmutableMap.of())).logException(e); } } }); return storeFuture; }
From source file:org.opendaylight.bgpcep.bgp.topology.provider.config.TopologyReferenceSingletonServiceImpl.java
@Override public ListenableFuture<Void> closeServiceInstance() { this.topologyBuilder.close(); return Futures.immediateFuture(null); }
From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java
@Override public Future<Boolean> contains(Object key) { return Futures.immediateFuture(memcacheService.contains(key)); }
From source file:io.v.impl.google.lib.discovery.UpdateImpl.java
@Override public ListenableFuture<byte[]> getAttachment(VContext ctx, final String name) throws VException { synchronized (ad) { Attachments attachments = ad.getAttachments(); if (attachments != null) { if (attachments.containsKey(name)) { byte[] data = attachments.get(name); return Futures.immediateFuture(Arrays.copyOf(data, data.length)); }//from ww w. j a v a 2s . c om } } ListenableFutureCallback<byte[]> callback = new ListenableFutureCallback<>(); nativeAttachment(nativeRef, ctx, name, callback); return VFutures.withUserLandChecks(ctx, Futures.transform(callback.getVanillaFuture(), new Function<byte[], byte[]>() { @Override public byte[] apply(byte[] data) { synchronized (ad) { Attachments attachments = ad.getAttachments(); if (attachments == null) { attachments = new Attachments(); ad.setAttachments(attachments); } attachments.put(name, data); return Arrays.copyOf(data, data.length); } } })); }
From source file:com.facebook.buck.util.concurrent.ListeningMultiSemaphore.java
/** * Returns the future which will be completed by the moment when resources will be acquired. * Future may be returned already completed. You should subscribe to the future and perform your * resource requiring job once the future will be completed and not cancelled. * When you finish your job, you must release acquired resources by calling release() method * below./*from w w w . j a va 2 s . c o m*/ * * @param resources Resource amounts that need to be acquired. If they are higher than maximum * amounts, they will be capped to them. * * @return Future that will be completed once resource will be acquired. */ public synchronized ListenableFuture<Void> acquire(ResourceAmounts resources) { if (resources.equals(ResourceAmounts.ZERO)) { return Futures.immediateFuture(null); } resources = capResourceAmounts(resources); if (!checkIfResourcesAvailable(resources)) { SettableFuture<Void> pendingFuture = SettableFuture.create(); pending.add(ListeningSemaphoreArrayPendingItem.of(pendingFuture, resources)); return pendingFuture; } increaseUsedResources(resources); return Futures.immediateFuture(null); }
From source file:org.eclipse.scada.protocol.iec60870.server.data.AbstractBaseDataModel.java
protected synchronized ListenableFuture<Void> disposeSubscription(final DefaultSubscription subscription) { this.subscriptions.remove(subscription); this.numberOfSubscriptions = this.subscriptions.size(); if (this.executor.isShutdown()) { // if we are already disposed return Futures.immediateFuture(null); }/*from w w w.jav a2 s. c o m*/ // the completion will come from the executor, so the completion has to wait in line // with possible remaining updated return this.executor.submit(new Callable<Void>() { @Override public Void call() throws Exception { // this is only a marker return null; } }); }
From source file:io.airlift.discovery.client.testing.StaticServiceSelector.java
@Override public ListenableFuture<List<ServiceDescriptor>> refresh() { return Futures.immediateFuture(serviceDescriptors); }
From source file:org.opendaylight.openflowplugin.applications.frsync.impl.SyncReactorFutureWithCompressionDecorator.java
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath, final FlowCapableNode configTree, final FlowCapableNode operationalTree) throws InterruptedException { final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath); LOG.trace("syncup {}", nodeId.getValue()); try {/*w ww. j a va2 s .com*/ compressionGuard.acquire(); final boolean newFutureNecessary = updateCompressionState(flowcapableNodePath, configTree, operationalTree); if (newFutureNecessary) { super.syncup(flowcapableNodePath, configTree, operationalTree); } return Futures.immediateFuture(true); } finally { compressionGuard.release(); } }
From source file:org.opendaylight.netconf.topology.example.ExampleNodeManagerCallback.java
@Nonnull @Override//from w w w . jav a 2 s .com public ListenableFuture<Node> onNodeCreated(@Nonnull final NodeId nodeId, @Nonnull final Node configNode) { return Futures .immediateFuture(new NodeBuilder() .addAugmentation(NetconfNode.class, new NetconfNodeBuilder() .setConnectionStatus(NetconfNodeFields.ConnectionStatus.Connected).build()) .build()); }