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.IdService.java
private long generateId(Type type) { idLock.get().acquire();/*from w w w.j a v a 2s.c o m*/ try { NodeData nodeData = Futures.getUnchecked(zkClient.getData(type.path)); long counterVal = Longs.fromByteArray(nodeData.getData()); Futures.getUnchecked(zkClient.setData(type.path, Longs.toByteArray(counterVal + incrementBy))); return counterVal; } finally { idLock.get().release(); } }
From source file:co.cask.cdap.gateway.runtime.Main.java
@Override public void start() { LOG.info("Starting Gateway..."); Futures.getUnchecked( Services.chainStart(zkClientService, kafkaClientService, metricsCollectionService, flumeCollector)); }
From source file:com.continuuity.loom.common.zookeeper.lib.ZKInterProcessReentrantLock.java
public boolean release() { if (lockNode == null) { return false; }// w w w .j a v a 2 s. c om // if we hold a lock, we release it by deleting the node // todo: check that we still hold the lock? Futures.getUnchecked(zkClient.delete(lockNode)); return true; }
From source file:org.apache.aurora.scheduler.app.local.FakeMaster.java
@Override public Status start() { assertNotStopped();/*from w w w . j a v a 2s . c om*/ Futures.getUnchecked(schedulerFuture).registered(this, FrameworkID.newBuilder().setValue("local").build(), MasterInfo.getDefaultInstance()); eventBus.post(new Started()); executor.scheduleAtFixedRate(() -> { List<Offer> allOffers; synchronized (sentOffers) { synchronized (idleOffers) { sentOffers.putAll(idleOffers); allOffers = ImmutableList.copyOf(idleOffers.values()); idleOffers.clear(); } } if (allOffers.isEmpty()) { LOG.info("All offers consumed, suppressing offer cycle."); } else { Futures.getUnchecked(schedulerFuture).resourceOffers(this, allOffers); } }, 1, 5, TimeUnit.SECONDS); return Status.DRIVER_RUNNING; }
From source file:org.apache.twill.internal.TwillContainerLauncher.java
/** * Start execution run for a class in a container. Will return instance of {@link TwillContainerController} * that allows sending messages directly to the container. * * @param runId Use to represent unique id of the container run. * @param instanceId The Twill instance Id. * @param mainClass The main class to run in the container. * @param classPath The class path to load classes for the container. * @param logLevelLocation The log level file location for the container to localize. * @return instance of {@link TwillContainerController} to control the container run. *//*from w w w. j av a2 s .c o m*/ public TwillContainerController start(RunId runId, int instanceId, Class<?> mainClass, String classPath, @Nullable Location logLevelLocation) { // Clean up zookeeper path in case this is a retry and there are old messages and state there. Futures.getUnchecked(ZKOperations.ignoreError(ZKOperations.recursiveDelete(zkClient, "/" + runId), KeeperException.NoNodeException.class, null)); // Adds all file to be localized to container launchContext.addResources(runtimeSpec.getLocalFiles()); // Optionally localize secure store and log level file. try { if (secureStoreLocation != null && secureStoreLocation.exists()) { launchContext .addResources(new DefaultLocalFile(Constants.Files.CREDENTIALS, secureStoreLocation.toURI(), secureStoreLocation.lastModified(), secureStoreLocation.length(), false, null)); } if (logLevelLocation != null && logLevelLocation.exists()) { launchContext .addResources(new DefaultLocalFile(Constants.Files.LOG_LEVELS, logLevelLocation.toURI(), logLevelLocation.lastModified(), logLevelLocation.length(), false, null)); } } catch (IOException e) { LOG.warn("Failed to launch container with secure store {}.", secureStoreLocation); } // Currently no reporting is supported for runnable containers launchContext.addEnvironment(EnvKeys.TWILL_RUN_ID, runId.getId()) .addEnvironment(EnvKeys.TWILL_RUNNABLE_NAME, runtimeSpec.getName()) .addEnvironment(EnvKeys.TWILL_INSTANCE_ID, Integer.toString(instanceId)) .addEnvironment(EnvKeys.TWILL_INSTANCE_COUNT, Integer.toString(instanceCount)); // assemble the command based on jvm options ImmutableList.Builder<String> commandBuilder = ImmutableList.builder(); String firstCommand; if (jvmOpts.getDebugOptions().doDebug(runtimeSpec.getName())) { // for debugging we run a quick Java program to find a free port, then pass that port as the debug port and also // as a System property to the runnable (Java has no general way to determine the port from within the JVM). // PORT=$(java FindFreePort) && java -agentlib:jdwp=...,address=\$PORT -Dtwill.debug.port=\$PORT... TwillLauncher // The $ must be escaped, otherwise it gets expanded (to "") before the command is submitted. String suspend = jvmOpts.getDebugOptions().doSuspend() ? "y" : "n"; firstCommand = "TWILL_DEBUG_PORT=$($JAVA_HOME/bin/java"; commandBuilder.add("-cp", Constants.Files.LAUNCHER_JAR, FindFreePort.class.getName() + ")", "&&", // this will stop if FindFreePort fails "$JAVA_HOME/bin/java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=" + suspend + "," + "address=\\$TWILL_DEBUG_PORT", "-Dtwill.debug.port=\\$TWILL_DEBUG_PORT"); } else { firstCommand = "$JAVA_HOME/bin/java"; } maxHeapSizeMB = Resources.computeMaxHeapSize(containerInfo.getMemoryMB(), reservedMemory, minHeapRatio); commandBuilder.add("-Djava.io.tmpdir=tmp", "-Dyarn.container=$" + EnvKeys.YARN_CONTAINER_ID, "-Dtwill.runnable=$" + Constants.TWILL_APP_NAME + ".$" + EnvKeys.TWILL_RUNNABLE_NAME, "-cp", Constants.Files.LAUNCHER_JAR + ":" + classPath, "-Xmx" + maxHeapSizeMB + "m"); String extraOptions = jvmOpts.getRunnableExtraOptions(runtimeSpec.getName()); if (!extraOptions.isEmpty()) { commandBuilder.add(extraOptions); } commandBuilder.add(TwillLauncher.class.getName(), mainClass.getName(), Boolean.TRUE.toString()); List<String> command = commandBuilder.build(); ProcessController<Void> processController = launchContext .addCommand(firstCommand, command.toArray(new String[command.size()])).launch(); TwillContainerControllerImpl controller = new TwillContainerControllerImpl(zkClient, runId, runtimeSpec.getName(), instanceId, processController); controller.start(); return controller; }
From source file:com.torodb.torod.db.backends.metaInf.CollectionMetaInfo.java
void createSubDocTypeTable(@Nonnull SessionExecutor sessionExecutor, @Nonnull SubDocType type) { if (createdSubDocTypes.contains(type)) { //it was previously created return; //so nothing has to be done }//w w w. j a v a 2 s . c o m Long tick = creationPendingJobs.get(type); if (tick != null) { //if we are creating the table right now... sessionExecutor.pauseUntil(tick); //wait until the table is created return; } LOGGER.debug("{}.{} table was not created", collection, type); lock.lock(); try { if (createdSubDocTypes.contains(type)) { //another thread oredered the creation and it has already been executed LOGGER.debug("{}.{} table was created while I was waiting", collection, type); return; //so nothing has to be done } tick = creationPendingJobs.get(type); if (tick != null) { //another thread ordered the table creation LOGGER.debug("{}.{} table creation has been scheduled while I was waiting", collection, type); sessionExecutor.pauseUntil(tick); //so this thread must wait until the creation is executed return; } //this thread has the lock and nobody ordered the creation before it get the lock, so this thread must order the creation LOGGER.debug("I will schedule creation of {}.{} table", collection, type); Future<?> future = systemExecutor.createSubDocTable(collection, type, CREATE_SUB_DOC_TYPE_CALLBACK); LOGGER.debug("{}.{} table creation has been scheduled", collection, type); Futures.getUnchecked(future); LOGGER.debug("{}.{} table creation has been executed", collection, type); createdSubDocTypes.add(type); } catch (ToroTaskExecutionException ex) { //TODO: Change exception throw new RuntimeException(ex); } finally { lock.unlock(); } }
From source file:com.continuuity.loom.common.zookeeper.lib.ZKInterProcessReentrantLock.java
private boolean isOwnerOfLock() { if (lockNode == null) { return false; }//from w ww. j a va2 s .c o m return Futures.getUnchecked(zkClient.exists(lockNode)) != null; }
From source file:org.apache.aurora.scheduler.mesos.SchedulerDriverService.java
@Override public void abort() { Futures.getUnchecked(driverFuture).abort(); }
From source file:co.cask.cdap.gateway.runtime.Main.java
@Override public void stop() { LOG.info("Stopping Gateway..."); Futures.getUnchecked( Services.chainStop(flumeCollector, metricsCollectionService, kafkaClientService, zkClientService)); }
From source file:org.asoem.greyfish.impl.environment.DefaultBasicEnvironment.java
private void executeAgents() { final List<ListenableFuture<?>> agentExecutions = Lists.newArrayList(); for (BasicAgent agent : agents) { agentExecutions.add(executorService.submit(agent)); }//from w w w.j a v a 2s . c om Futures.getUnchecked(Futures.allAsList(agentExecutions)); }