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:org.apache.aurora.scheduler.app.local.FakeMaster.java
public void changeState(TaskID task, TaskState state) { assertNotStopped();//from www .j a va 2 s . c om checkState(activeTasks.containsKey(task), "Task " + task + " does not exist."); Futures.getUnchecked(schedulerFuture).statusUpdate(this, TaskStatus.newBuilder().setTaskId(task).setState(state).build()); }
From source file:org.apache.twill.internal.kafka.client.SimpleKafkaPublisher.java
/** * Start the publisher. This method must be called before other methods. This method is only to be called * by KafkaClientService who own this object. * @return A Cancellable for closing this publish. *//*from w w w .jav a 2 s. c o m*/ Cancellable start() { ExecutorService listenerExecutor = Executors .newSingleThreadExecutor(Threads.createDaemonThreadFactory("kafka-publisher")); // Listen to changes in broker list final BrokerListChangeListener listener = new BrokerListChangeListener(listenerCancelled, producer, ack, compression); Cancellable cancelChangeListener = brokerService.addChangeListener(listener, listenerExecutor); // Invoke the change listener at least once. Since every call to the listener is through the single thread // executor, there is no race and for sure the listener always see the latest change, either through this call // or from the BrokerService callback. Future<?> completion = listenerExecutor.submit(new Runnable() { @Override public void run() { listener.changed(brokerService); } }); Futures.getUnchecked(completion); return new ProducerCancellable(listenerExecutor, listenerCancelled, cancelChangeListener, producer); }
From source file:org.apache.twill.yarn.LocationCacheCleaner.java
@VisibleForTesting void forceCleanup(final long currentTime) { Futures.getUnchecked(scheduler.submit(new Runnable() { @Override//from w w w. ja va 2 s. com public void run() { cleanup(currentTime); } })); }
From source file:org.onosproject.store.primitives.impl.DefaultDistributedQueue.java
@Override public E peek() { final MeteringAgent.Context timer = monitor.startTimer(PEEK); return Futures.getUnchecked(database.queuePeek(name) .thenApply(v -> v != null ? serializer.<E>decode(v) : null).whenComplete((r, e) -> timer.stop(e))); }
From source file:com.continuuity.loom.common.zookeeper.lib.ZKMap.java
public T put(String key, T value) { Map<String, T> current = Maps.newHashMap(currentView.get()); T result = current.put(key, value);/* www . j ava2 s . c om*/ currentView.set(ImmutableMap.<String, T>builder().putAll(current).build()); // Note: we do delete and add new node with new data VS createOrSet() to avoid attaching watchers to every node String itemNodePath = getItemNodePath(key); Futures.getUnchecked(ZKClientExt.delete(zkClient, itemNodePath, true)); Futures.getUnchecked(zkClient.create(itemNodePath, serializer.serialize(value), CreateMode.PERSISTENT)); return result; }
From source file:com.continuuity.loom.common.zookeeper.lib.ZKCollection.java
@Override public boolean remove(Object o) { List<T> current = Lists.newArrayList(currentView.get()); boolean removed = current.remove(o); if (removed) { currentView.set(ImmutableList.<T>builder().addAll(current).build()); }/* w ww.j a v a 2s. co m*/ // Hint: we can try to make removal more efficient if we keep map<nodeName->object> internally, or at least try to // remove only when in-mem collection removed smth, but then we may face races... NodeChildren children = Futures.getUnchecked(ZKClientExt.getChildrenOrNull(zkClient, "")); if (children == null) { return false; } List<String> nodes = children.getChildren(); for (String node : nodes) { byte[] data = Futures.getUnchecked(zkClient.getData(getNodePath(node))).getData(); if (o.equals(serializer.deserialize(data))) { return Futures.getUnchecked(ZKClientExt.delete(zkClient, getNodePath(node), true)) != null; } } return removed; }
From source file:com.facebook.buck.remoteexecution.util.OutOfProcessIsolatedExecutionClients.java
private OutOfProcessIsolatedExecutionClients(final Protocol protocol, BuckEventBus eventBus) throws IOException { this.workDir = new NamedTemporaryDirectory("__work__"); this.storage = new LocalContentAddressedStorage(workDir.getPath().resolve("__cache__"), protocol); this.protocol = protocol; this.executionService = (actionDigest, ruleName) -> { Action action = storage.materializeAction(actionDigest); Path buildDir = workDir.getPath().resolve(action.getInputRootDigest().getHash()); try (Closeable ignored = () -> MostFiles.deleteRecursively(buildDir)) { Command command;// w ww . ja v a2 s . com try (Scope ignored2 = LeafEvents.scope(eventBus, "materializing_inputs")) { command = storage.materializeInputs(buildDir, action.getInputRootDigest(), Optional.of(action.getCommandDigest())).get(); } ActionRunner.ActionResult actionResult = new ActionRunner(protocol, eventBus) .runAction(command.getCommand(), command.getEnvironment(), command.getOutputDirectories() .stream().map(Paths::get).collect(ImmutableSet.toImmutableSet()), buildDir); try (Scope ignored2 = LeafEvents.scope(eventBus, "uploading_results")) { Futures.getUnchecked(storage.addMissing(actionResult.requiredData)); } return Futures.immediateFuture(new ExecutionResult() { @Override public ImmutableList<OutputDirectory> getOutputDirectories() { return actionResult.outputDirectories; } @Override public ImmutableList<OutputFile> getOutputFiles() { return actionResult.outputFiles; } @Override public int getExitCode() { return actionResult.exitCode; } @Override public Optional<String> getStdout() { return Optional.of(actionResult.stdout); } @Override public Optional<String> getStderr() { return Optional.of(actionResult.stderr); } @Override public RemoteExecutionMetadata getMetadata() { return RemoteExecutionMetadata.getDefaultInstance(); } @Override public Digest getActionResultDigest() { return protocol.newDigest("", 0); } }); } }; }
From source file:com.facebook.buck.util.concurrent.WorkThreadTrackingTask.java
@Override @Nullable public T getRawResult() { return result.isDone() ? Futures.getUnchecked(result) : null; }
From source file:org.gradle.internal.filewatch.FileSystemChangeWaiter.java
@Override public void execute(FileSystemSubset taskFileSystemInputs, Runnable notifier) { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); final StoppableExecutor executorService = executorFactory.create("quiet period waiter"); FileWatcher watcher = fileWatcherFactory.watch(taskFileSystemInputs, new Action<Throwable>() { @Override// w w w .j a v a 2 s.c o m public void execute(Throwable throwable) { error.set(throwable); latch.countDown(); } }, new FileWatcherListener() { private IdleTimeout timeout; @Override public void onChange(final FileWatcher watcher, FileWatcherEvent event) { if (timeout == null) { timeout = new IdleTimeout(QUIET_PERIOD, new Runnable() { @Override public void run() { watcher.stop(); latch.countDown(); } }); executorService.execute(new Runnable() { @Override public void run() { timeout.await(); } }); } timeout.tick(); } }); final StoppableExecutor keyboardHandlerExecutor = executorFactory .create("Continuous building keyboard handler"); ListenableFuture<Boolean> keyboardHandlerFuture = submitAsyncKeyboardHandler( MoreExecutors.listeningDecorator(keyboardHandlerExecutor), latch); try { notifier.run(); latch.await(); Throwable throwable = error.get(); if (throwable != null) { throw UncheckedException.throwAsUncheckedException(throwable); } } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } finally { if (!keyboardHandlerFuture.isDone()) { keyboardHandlerFuture.cancel(true); } else if (Futures.getUnchecked(keyboardHandlerFuture)) { cancellationRequested.set(true); } CompositeStoppable.stoppable(watcher, executorService, keyboardHandlerExecutor).stop(); } }
From source file:org.apache.aurora.scheduler.mesos.SchedulerDriverService.java
@Override public void blockUntilStopped() { Futures.getUnchecked(driverFuture).join(); }