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:co.cask.cdap.gateway.router.RouterMain.java
@Override public void start() { LOG.info("Starting Router..."); Futures.getUnchecked(Services.chainStart(zkClientService, router)); LOG.info("Router started."); }
From source file:org.onosproject.store.primitives.impl.DefaultDistributedQueue.java
@Override public long size() { final MeteringAgent.Context timer = monitor.startTimer(SIZE); return Futures.getUnchecked(database.queueSize(name).whenComplete((r, e) -> timer.stop(e))); }
From source file:com.webbfontaine.valuewebb.irms.impl.risk.data.RiskResultCollector.java
public void calculateResults() { if (results == null) { LOGGER.trace("Calculating 'Risk Collector' state based on results: {}", results); ListenableFuture<List<List<RiskResult>>> future = Futures.allAsList(futures); results = Futures.getUnchecked(future); finalColor = getHighestColor();/* w w w . j a v a 2 s . c om*/ hitsCount = size(nonEmptyResults(results)); groupedSelectedResults = groupByCriterionName(); LOGGER.trace("'Risk Collector' state, finalColor: {}, hitsCount: {}, groupedSelectedResults: {}", new Object[] { finalColor, hitsCount, groupedSelectedResults }); } }
From source file:co.cask.cdap.gateway.router.RouterMain.java
@Override public void stop() { LOG.info("Stopping Router..."); Futures.getUnchecked(Services.chainStop(router, zkClientService)); LOG.info("Router stopped."); }
From source file:org.onosproject.store.primitives.impl.DefaultDistributedQueue.java
@Override public void push(E entry) { checkNotNull(entry, ERROR_NULL_ENTRY); final MeteringAgent.Context timer = monitor.startTimer(PUSH); Futures.getUnchecked( database.queuePush(name, serializer.encode(entry)).whenComplete((r, e) -> timer.stop(e))); }
From source file:org.onosproject.store.consistent.impl.DefaultTransactionContext.java
@SuppressWarnings("unchecked") @Override/*w w w . jav a2s.c om*/ public void commit() { // TODO: rework commit implementation to be more intuitive checkState(isOpen, TX_NOT_OPEN_ERROR); CommitResponse response = null; try { List<DatabaseUpdate> updates = Lists.newLinkedList(); txMaps.values().forEach(m -> updates.addAll(m.prepareDatabaseUpdates())); Transaction transaction = new DefaultTransaction(transactionId, updates); response = Futures.getUnchecked(database.prepareAndCommit(transaction)); } finally { if (response != null && !response.success()) { abort(); } isOpen = false; } }
From source file:co.cask.cdap.internal.app.runtime.distributed.AbstractTwillProgramController.java
@Override protected final void doStop() throws Exception { stopRequested = true; Futures.getUnchecked(twillController.terminate()); }
From source file:co.cask.cdap.common.election.InMemoryElectionRegistry.java
/** * Joins the leader election process of the given named group. * * @param name The group name for performing leader election * @param handler The callback for acting on leader election events * @return A {@link Cancellable} to withdraw from the process *///from w w w. j av a2 s .c o m public Cancellable join(final String name, ElectionHandler handler) { final RegistryElectionHandler registryHandler = new RegistryElectionHandler(name, handler); executor.execute(new Runnable() { @Override public void run() { registry.put(name, registryHandler); // Fetch the first handler from the registry map. If it is the same as the newly added one, notify it as leader. // The iterator shouldn't be empty if (registryHandler == registry.get(name).iterator().next()) { registryHandler.leader(); } else { registryHandler.follower(); } } }); // Return a Cancellable that remove the handler from the registry map and notify it become follower. // It also select the new leader and notify it. return new Cancellable() { @Override public void cancel() { Futures.getUnchecked(executor.submit(new Runnable() { @Override public void run() { // If not in register or not a leader, simply return. if (!registry.remove(name, registryHandler) || !registryHandler.isLeader()) { return; } // The removed handler is the leader. Notify that it becomes follower registryHandler.follower(); // Try to find a new leader. It'll be the first in the list. Iterator<RegistryElectionHandler> iterator = registry.get(name).iterator(); if (!iterator.hasNext()) { return; } // Schedule notification of the new leader. final RegistryElectionHandler leader = iterator.next(); executor.submit(new Runnable() { @Override public void run() { Iterator<RegistryElectionHandler> iterator = registry.get(name).iterator(); // Make sure the leader hasn't changed. // If the leader changed, the adding/removal logic should already handler notification. if (iterator.hasNext() && iterator.next() == leader) { leader.leader(); } } }); } })); } }; }
From source file:co.cask.cdap.security.runtime.AuthenticationServerMain.java
@Override public void stop() { if (authServer != null) { LOG.info("Stopping AuthenticationServer."); Futures.getUnchecked(Services.chainStop(authServer, zkClientService)); }/*from w ww . j ava 2 s . co m*/ }
From source file:com.facebook.buck.util.concurrent.WorkThreadTrackingTask.java
@Nullable protected final T compute() { /**/* w w w. j ava 2 s. c o m*/ * Since we now manually implement work stealing in the ForkJoinPool through callined {@link * #externalCompute()}, fork join framework no longer guarantees synchronization around the * task. So we manually synchronize it. */ try { Thread currentThread = Thread.currentThread(); if (UNSAFE.compareAndSwapObject(this, WORKTHREAD, null, currentThread) || workThread == currentThread) { try (Scope ignored = () -> workThread = null) { if (result.isDone()) { return getRawResult(); } T res = Objects.requireNonNull(work).get(); Preconditions.checkState(getRawResult() == null || getRawResult() == result, "A value for this task has already been created: %s", getRawResult()); result.set(res); return res; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } return Futures.getUnchecked(result); } finally { work = null; workThread = null; } }