List of usage examples for com.google.common.util.concurrent ListeningExecutorService isShutdown
boolean isShutdown();
From source file:org.eclipse.osee.executor.admin.internal.ExecutorCache.java
public ListeningExecutorService getById(String id) { if (id == null || id.length() <= 0) { throw new OseeArgumentException("Error - executorId cannot be null"); }/*from ww w . j av a 2 s . com*/ ListeningExecutorService executor = executors.get(id); if (executor != null && (executor.isShutdown() || executor.isTerminated())) { executors.remove(id); executor = null; } return executor; }
From source file:com.github.rinde.datgen.pdptw.DatasetGenerator.java
static void submitJob(final AtomicLong currentJobs, final ListeningExecutorService service, final ScenarioCreator job, final int numInstances, final Dataset<GeneratedScenario> dataset, final Map<GeneratorSettings, IdSeedGenerator> rngMap, final AtomicLong datasetSize) { if (service.isShutdown()) { return;/*from www .j a v a2 s. c om*/ } currentJobs.getAndIncrement(); final ListenableFuture<GeneratedScenario> future = service.submit(job); Futures.addCallback(future, new FutureCallback<GeneratedScenario>() { @Override public void onSuccess(@Nullable GeneratedScenario result) { LOGGER.info(" - Job finished!"); currentJobs.decrementAndGet(); if (result == null) { final ScenarioCreator newJob = ScenarioCreator.create(rngMap.get(job.getSettings()).next(), job.getSettings(), job.getGenerator()); LOGGER.info(" - Job result was NULL, submitting new job"); submitJob(currentJobs, service, newJob, numInstances, dataset, rngMap, datasetSize); return; } final GeneratedScenario res = verifyNotNull(result); if (dataset.get(res.getDynamismBin(), res.getSettings().getUrgency(), res.getSettings().getScale()) .size() < numInstances) { datasetSize.getAndIncrement(); LOGGER.info(" - Job Putting dataset..."); dataset.put(res.getDynamismBin(), res.getSettings().getUrgency(), res.getSettings().getScale(), res); } else { // TODO check if this job should be respawned by seeing if it uses the // correct TSG // TODO respawn more tasks if currentJobs < numThreads final Collection<Double> dynamismLevels = job.getSettings().getDynamismRangeCenters() .asMapOfRanges().values(); boolean needMore = false; for (final Double d : dynamismLevels) { if (dataset.get(d, res.getSettings().getUrgency(), res.getSettings().getScale()) .size() < numInstances) { needMore = true; break; } } if (needMore) { // respawn job final ScenarioCreator newJob = ScenarioCreator.create(rngMap.get(job.getSettings()).next(), job.getSettings(), job.getGenerator()); if (!service.isShutdown()) { submitJob(currentJobs, service, newJob, numInstances, dataset, rngMap, datasetSize); } } } } @Override public void onFailure(Throwable t) { throw new IllegalStateException(t); } }, MoreExecutors.directExecutor()); }
From source file:org.eclipse.osee.executor.admin.internal.ExecutorAdminImpl.java
public ListeningExecutorService getExecutor(String id) { ListeningExecutorService service = null; synchronized (cache) { service = cache.getById(id);//from ww w . ja v a 2s .c o m if (service == null) { service = createExecutor(id, -1); } } if (service == null) { throw new OseeStateException("Error creating executor [%s].", id); } if (service.isShutdown() || service.isTerminated()) { throw new OseeStateException("Error executor [%s] was previously shutdown.", id); } return service; }
From source file:org.attribyte.relay.AsyncPublisher.java
/** * Shutdown the publisher./* ww w . ja v a 2s .c om*/ * @param notificationExecutor The notification executor. * @param httpClient The HTTP client. * @param maxWaitSeconds The maximum amount of time to be patient for normal shutdown. * @throws Exception on shutdown error. */ private void shutdown(final ListeningExecutorService notificationExecutor, final HttpClient httpClient, final int maxWaitSeconds) throws Exception { if (isInit.compareAndSet(true, false)) { notificationExecutor.shutdown(); notificationExecutor.awaitTermination(maxWaitSeconds, TimeUnit.SECONDS); if (!notificationExecutor.isShutdown()) { notificationExecutor.shutdownNow(); } httpClient.stop(); } }
From source file:org.apache.hive.ptest.execution.Phase.java
protected List<RemoteCommandResult> initalizeHosts() throws Exception { List<ListenableFuture<List<RemoteCommandResult>>> futures = Lists.newArrayList(); ListeningExecutorService executor = MoreExecutors .listeningDecorator(Executors.newFixedThreadPool(hostExecutors.size())); try {// www. ja va 2s .c o m for (final HostExecutor hostExecutor : hostExecutors) { futures.add(executor.submit(new Callable<List<RemoteCommandResult>>() { @Override public List<RemoteCommandResult> call() throws Exception { return initalizeHost(hostExecutor); } })); } List<RemoteCommandResult> results = Lists.newArrayList(); for (ListenableFuture<List<RemoteCommandResult>> future : futures) { List<RemoteCommandResult> result = future.get(); if (result != null) { results.addAll(result); } } executor.shutdown(); return results; } finally { if (executor.isShutdown()) { executor.shutdownNow(); } } }