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.continuuity.loom.common.zookeeper.lib.ZKMap.java
public void clear() { currentView.set(Collections.<String, T>emptyMap()); // Hint: again, we can try to make removal more efficient by cleaning only when in-mem collection cleaned smth, // but then we may face races... NodeChildren nodeChildren = Futures.getUnchecked(zkClient.getChildren("")); List<ListenableFuture<String>> deleteFutures = Lists.newArrayList(); for (String node : nodeChildren.getChildren()) { deleteFutures.add(ZKClientExt.delete(zkClient, getNodePath(node), true)); }//from w w w . jav a 2 s . c o m Futures.getUnchecked(Futures.allAsList(deleteFutures)); }
From source file:org.apache.aurora.scheduler.mesos.SchedulerDriverService.java
@Override public void declineOffer(Protos.OfferID offerId, Protos.Filters filter) { ensureRunning();//from w w w.j av a 2 s . c om OfferID convertedOfferId = ProtosConversion.convert(offerId); Filters convertedFilter = ProtosConversion.convert(filter); Futures.getUnchecked(driverFuture).declineOffer(convertedOfferId, convertedFilter); }
From source file:org.robotninjas.barge.log.RaftLogBase.java
public void load() throws IOException { LOGGER.info("Replaying log"); // journal.init(); long oldCommitIndex = commitIndex; // TODO: fireCommitted more often?? replay(new Visitor() { @Override/*from w w w. j a va 2 s . c o m*/ public void term(long term) { currentTerm = Math.max(currentTerm, term); } @Override public void vote(Optional<Replica> vote) { votedFor = vote; } @Override public void commit(long commit) { commitIndex = Math.max(commitIndex, commit); } @Override public void append(Entry entry, long index) { lastLogIndex = Math.max(index, lastLogIndex); lastLogTerm = Math.max(entry.getTerm(), lastLogTerm); if (entry.hasMembership()) { config.addMembershipEntry(index, entry); } if (entry.hasSnapshot()) { lastSnapshot = entry.getSnapshot(); } } }); final SettableFuture<Object> lastResult; if (oldCommitIndex != commitIndex) { lastResult = SettableFuture.create(); operationResults.put(commitIndex, lastResult); } else { lastResult = null; } fireComitted(); if (lastResult != null) { Futures.getUnchecked(lastResult); } LOGGER.info("Finished replaying log lastIndex {}, currentTerm {}, commitIndex {}, lastVotedFor {}", lastLogIndex, currentTerm, commitIndex, votedFor.orNull()); }
From source file:org.apache.rya.periodic.notification.twill.yarn.PeriodicNotificationTwillRunner.java
/** * Start an instance of the {@link PeriodicNotificationTwillApp}. * * @param interactive - If true, this method will block until the user terminates this JVM, at which point the * {@link PeriodicNotificationTwillApp} on the YARN cluster will also be terminated. If false, this * method will return after startup. *//* w w w . j a v a2 s.com*/ public void startApp(final boolean interactive) { final String yarnClasspath = yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH, Joiner.on(",").join(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)); final List<String> applicationClassPaths = Lists.newArrayList(); Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath)); final TwillController controller = twillRunner.prepare(new PeriodicNotificationTwillApp(configFile)) .addLogHandler(new PrinterLogHandler( new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true))) .withApplicationClassPaths(applicationClassPaths) //.withApplicationArguments(args) //.withArguments(runnableName, args) // .withBundlerClassAcceptor(new HadoopClassExcluder()) .start(); final ResourceReport r = getResourceReport(controller, 5, TimeUnit.MINUTES); LOG.info("Received ResourceReport: {}", r); LOG.info("{} started successfully!", PeriodicNotificationTwillApp.APPLICATION_NAME); if (interactive) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } }); try { LOG.info("{} waiting termination by user. Type ctrl-c to terminate.", PeriodicNotificationTwillApp.class.getSimpleName()); controller.awaitTerminated(); } catch (final ExecutionException e) { e.printStackTrace(); } } }
From source file:com.facebook.buck.core.rules.resolver.impl.MultiThreadedActionGraphBuilder.java
@Override public BuildRule requireRule(BuildTarget target) { Preconditions.checkState(isValid);/*from w ww .j av a 2 s . c o m*/ return Futures.getUnchecked(buildRuleIndex.computeIfAbsent(target, wrap(key -> buildRuleGenerator .transform(toolchainProviderResolver.apply(target), targetGraph, this, targetGraph.get(target))))); }
From source file:com.github.parboiled1.grappa.backport.buffers.CharSequenceInputBuffer.java
@Override public int getLineCount() { return Futures.getUnchecked(lineCounter).getNrLines(); }
From source file:org.apache.aurora.scheduler.mesos.SchedulerDriverService.java
@Override public void killTask(String taskId) { ensureRunning();//from ww w . j a v a2s . co m Status status = Futures.getUnchecked(driverFuture).killTask(TaskID.newBuilder().setValue(taskId).build()); if (status != DRIVER_RUNNING) { LOG.error("Attempt to kill task {} failed with code {}", taskId, status); killFailures.incrementAndGet(); } }
From source file:org.apache.tephra.distributed.TransactionService.java
@Override protected void doStart() { leaderElection = new LeaderElection(zkClient, "/tx.service/leader", new ElectionHandler() { @Override//from w ww . j av a2s. c o m public void leader() { // if the txManager fails, we should stop the server txManager = txManagerProvider.get(); txManager.addListener(new ServiceListenerAdapter() { @Override public void failed(State from, Throwable failure) { LOG.error("Transaction manager aborted, stopping transaction service"); TransactionService.this.abort(failure); } }, MoreExecutors.sameThreadExecutor()); pruningService = createPruningService(conf, txManager); server = ThriftRPCServer.builder(TTransactionServer.class).setHost(address).setPort(port) .setWorkerThreads(threads).setMaxReadBufferBytes(maxReadBufferBytes).setIOThreads(ioThreads) .build(new TransactionServiceThriftHandler(txManager, pruningService)); try { server.startAndWait(); pruningService.startAndWait(); doRegister(); LOG.info("Transaction Thrift Service started successfully on " + getAddress()); } catch (Throwable t) { LOG.info("Transaction Thrift Service didn't start on " + server.getBindAddress()); leaderElection.stop(); notifyFailed(t); } } @Override public void follower() { ListenableFuture<State> stopFuture = null; if (pruningService != null && pruningService.isRunning()) { // Wait for pruning service to stop after un-registering from discovery stopFuture = pruningService.stop(); } // First stop the transaction server as un-registering from discovery can block sometimes. // That can lead to multiple transaction servers being active at the same time. if (server != null && server.isRunning()) { server.stopAndWait(); } undoRegister(); if (stopFuture != null) { Futures.getUnchecked(stopFuture); } } }); leaderElection.start(); notifyStarted(); }
From source file:com.continuuity.weave.discovery.ZKDiscoveryService.java
/** * Registers a {@link Discoverable} in zookeeper. * <p>/* www .j a v a 2 s.c om*/ * Registering a {@link Discoverable} will create a node <base>/<service-name> * in zookeeper as a ephemeral node. If the node already exists (timeout associated with emphemeral, then a runtime * exception is thrown to make sure that a service with an intent to register is not started without registering. * When a runtime is thrown, expectation is that the process being started with fail and would be started again * by the monitoring service. * </p> * @param discoverable Information of the service provider that could be discovered. * @return An instance of {@link Cancellable} */ @Override public Cancellable register(final Discoverable discoverable) { final Discoverable wrapper = new DiscoverableWrapper(discoverable); byte[] discoverableBytes = encode(wrapper); // Path /<service-name>/service-sequential final String sb = "/" + wrapper.getName() + "/service-"; final String path = Futures .getUnchecked(zkClient.create(sb, discoverableBytes, CreateMode.EPHEMERAL_SEQUENTIAL, true)); return new Cancellable() { @Override public void cancel() { Futures.getUnchecked(zkClient.delete(path)); } }; }
From source file:org.apache.aurora.scheduler.mesos.VersionedSchedulerDriverService.java
@Override public void declineOffer(OfferID offerId, Filters filter) { whenRegistered(() -> {/*from w w w. ja v a2 s .c o m*/ LOG.info("Declining offer {}", offerId.getValue()); Futures.getUnchecked(mesosFuture) .send(Call.newBuilder().setType(Call.Type.DECLINE).setFrameworkId(getFrameworkId()) .setDecline(Call.Decline.newBuilder().setFilters(filter).addOfferIds(offerId)).build()); }); }