List of usage examples for com.google.common.util.concurrent Futures getUnchecked
@GwtIncompatible("TODO") public static <V> V getUnchecked(Future<V> future)
From source file:com.salesforce.grpc.contrib.MoreFutures.java
/** * Returns the result of the input {@code Future}, which must have already completed. * * <p>The benefits of this method are twofold. First, the name "getDoneUnchecked" suggests to readers that the * {@code Future} is already done. Second, if buggy code calls {@code getDone} on a {@code Future} that is still * pending, the program will throw instead of block. * * <p>If you are looking for a method to determine whether a given {@code Future} is done, use the instance method * {@link Future#isDone()}./*from w w w.j a v a2 s . c o m*/ * * @throws UncheckedExecutionException if the {@code Future} failed with an exception * @throws IllegalStateException if the {@code Future} is not done */ public static <V> V getDoneUnchecked(Future<V> future) { /* * We throw IllegalStateException, since the call could succeed later. Perhaps we "should" throw * IllegalArgumentException, since the call could succeed with a different argument. Those * exceptions' docs suggest that either is acceptable. Google's Java Practices page recommends * IllegalArgumentException here, in part to keep its recommendation simple: Static methods * should throw IllegalStateException only when they use static state. * * * Why do we deviate here? The answer: We want for fluentFuture.getDone() to throw the same * exception as Futures.getDone(fluentFuture). */ checkState(future.isDone(), "Future was expected to be done: %s", future); return Futures.getUnchecked(future); }
From source file:org.jclouds.virtualbox.util.NetworkUtils.java
public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) { ListenableFuture<ExecResponse> execEnableNetworkInterface = machineUtils.runScriptOnNode(nodeMetadata, new EnableNetworkInterface(networkInterfaceCard), RunScriptOptions.NONE); ExecResponse execEnableNetworkInterfaceResponse = Futures.getUnchecked(execEnableNetworkInterface); return execEnableNetworkInterfaceResponse.getExitStatus() == 0; }
From source file:com.facebook.buck.core.graph.transformation.DefaultGraphTransformationEngine.java
@Override public final <KeyType extends ComputeKey<ResultType>, ResultType extends ComputeResult> ResultType computeUnchecked( KeyType key) {//from w ww . j av a 2 s .co m return Futures.getUnchecked(compute(key)); }
From source file:org.apache.aurora.scheduler.mesos.SchedulerDriverService.java
@Override public void reconcileTasks(Collection<Protos.TaskStatus> statuses) { ensureRunning();/*from www . j ava 2 s . c om*/ Collection<TaskStatus> convertedStatuses = Collections2.transform(statuses, ProtosConversion::convert); Futures.getUnchecked(driverFuture).reconcileTasks(convertedStatuses); }
From source file:com.continuuity.loom.common.zookeeper.lib.ZKCollection.java
private void setExternalChangeWatcher() throws ExecutionException, InterruptedException { ZKOperations.watchChildren(zkClient, "", new ZKOperations.ChildrenCallback() { @Override//from w w w . ja va 2 s .c om public void updated(NodeChildren nodeChildren) { List<String> nodes = nodeChildren.getChildren(); List<OperationFuture<NodeData>> dataFutures = Lists.newArrayList(); for (String node : nodes) { dataFutures.add(zkClient.getData(getNodePath(node))); } final ListenableFuture<List<NodeData>> fetchFuture = Futures.successfulAsList(dataFutures); fetchFuture.addListener(new Runnable() { @Override public void run() { ImmutableList.Builder<T> builder = ImmutableList.builder(); // fetchFuture is set by this time List<NodeData> nodesData = Futures.getUnchecked(fetchFuture); for (NodeData nodeData : nodesData) { builder.add(serializer.deserialize(nodeData.getData())); } currentView.set(builder.build()); } }, Threads.SAME_THREAD_EXECUTOR); } }); }
From source file:org.apache.rya.periodic.notification.twill.yarn.PeriodicNotificationTwillRunner.java
/** * Terminates all instances of the {@link PeriodicNotificationTwillApp} on the YARN cluster. */// w ww . j av a 2s . c o m public void stopApp() { LOG.info("Stopping any running instances..."); int counter = 0; // It is possible that we have launched multiple instances of the app. For now, stop them all, one at a time. for (final TwillController c : twillRunner.lookup(PeriodicNotificationTwillApp.APPLICATION_NAME)) { final ResourceReport report = c.getResourceReport(); LOG.info("Attempting to stop {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId()); Futures.getUnchecked(c.terminate()); LOG.info("Stopped {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId()); counter++; } LOG.info("Stopped {} instance(s) of {}", counter, PeriodicNotificationTwillApp.APPLICATION_NAME); }
From source file:org.apache.twill.internal.logging.KafkaAppender.java
@Override public void stop() { super.stop(); scheduler.shutdownNow(); Futures.getUnchecked(Services.chainStop(kafkaClient, zkClientService)); }
From source file:co.cask.cdap.internal.app.runtime.workflow.AbstractProgramWorkflowRunner.java
/** * Adds a listener to the {@link ProgramController} and blocks for completion. * * @param controller the {@link ProgramController} for the program * @param context the {@link RuntimeContext} * @return {@link RuntimeContext} of the completed program * @throws Exception if the execution failed *///from ww w . j ava2s.com protected RuntimeContext executeProgram(final ProgramController controller, final RuntimeContext context) throws Exception { // Execute the program. final SettableFuture<RuntimeContext> completion = SettableFuture.create(); controller.addListener(new AbstractListener() { @Override public void completed() { completion.set(context); } @Override public void killed() { completion.set(context); } @Override public void error(Throwable cause) { completion.setException(cause); } }, Threads.SAME_THREAD_EXECUTOR); // Block for completion. try { return completion.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof Exception) { throw (Exception) cause; } throw Throwables.propagate(cause); } catch (InterruptedException e) { try { Futures.getUnchecked(controller.stop()); } catch (Throwable t) { // no-op } // reset the interrupt Thread.currentThread().interrupt(); return null; } }
From source file:com.google.idea.blaze.android.run.runner.BlazeAndroidRunConfigurationRunner.java
private static String canDebug(DeviceFutures deviceFutures, AndroidFacet facet, String moduleName) { // If we are debugging on a device, then the app needs to be debuggable for (ListenableFuture<IDevice> future : deviceFutures.get()) { if (!future.isDone()) { // this is an emulator, and we assume that all emulators are debuggable continue; }//from ww w .j a v a2 s .com IDevice device = Futures.getUnchecked(future); if (!LaunchUtils.canDebugAppOnDevice(facet, device)) { return AndroidBundle.message("android.cannot.debug.noDebugPermissions", moduleName, device.getName()); } } return null; }
From source file:co.cask.cdap.logging.run.LogSaverTwillRunnable.java
@Override public void stop() { LOG.info("Stopping runnable " + name); Futures.getUnchecked(Services.chainStop(logSaverStatusService, multiElection, logSaver, metricsCollectionService, kafkaClientService, zkClientService)); completion.set(null);/* w w w . j a va 2 s . c o m*/ }