List of usage examples for java.util.concurrent Future isDone
boolean isDone();
From source file:com.chinamobile.bcbsp.comm.CommunicatorNew.java
@Override public void sendSGAMessage(IMessage msg, boolean subgraphComputeFlag) throws IOException { String vertexID = msg.getDstVertexID(); int dstPartitonID = this.partitioner.getPartitionID(new Text(vertexID)); msg.setDstPartition(dstPartitonID);//from w ww. j av a 2s . co m int bucketID = Constants.PEER_COMPUTE_BUCK_ID; // if(subgraphComputeFlag){ // // }else{ // // } // msg.setMessageId(Constants.DEFAULT_PEER_DST_MESSSAGE_ID); // LOG.info("ljn test : sendSGAMessage MessageId is " + msg.getMessageId()); // The destination partition is just in this staff. int dstPartitionBucket = PartitionRule.getDestPartitionBucketId(dstPartitonID, bucketID); switch (messageManager.outgoAMessage(dstPartitionBucket, msg)) { case MetaDataOfMessage.BufferStatus.NORMAL: break; case MetaDataOfMessage.BufferStatus.SPILL: Future<Boolean> result = sendMssgResult.get(dstPartitionBucket); if (result != null && !result.isDone()) { try { result.get(); } catch (Exception e) { throw new RuntimeException("<sendMessage>--<SendThread>", e); } } startSendMessageThread(dstPartitionBucket, this.superstepCounter); break; default: LOG.error("<Controll Message Sending Error>" + "<SuperStep>" + "<DestPartition>" + "<Bucket>"); } MetaDataOfMessage.SENDMSGCOUNTER++; }
From source file:org.codice.solr.factory.impl.SolrClientAdapter.java
@SuppressWarnings("PMD.CompareObjectsWithEquals" /* purposely testing previous client identity */) private void finalizeStateChange(boolean notifyAvailability, @Nullable Future<?> futureToCancel, @Nullable SolrClient previousClientToClose, boolean swallowIOExceptions) throws IOException { if (notifyAvailability) { notifyListenersAndInitializers(); }//from w w w .j a v a 2s .c o m if ((futureToCancel != null) && !futureToCancel.isDone()) { LOGGER.debug("Solr({}): cancelling its previous failsafe task", core); futureToCancel.cancel(true); } // don't close if we still use the same client if ((previousClientToClose != null) && (previousClientToClose != realClient)) { LOGGER.debug("Solr({}): closing its previous client [{}]", core, previousClientToClose); Closeables.close(previousClientToClose, swallowIOExceptions); } }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
public void parallelMutate(List<MutateWorker> workers) throws BackendException { CompletionService<Void> completion = new ExecutorCompletionService<>(clientThreadPool); List<Future<Void>> futures = Lists.newLinkedList(); for (MutateWorker worker : workers) { futures.add(completion.submit(worker)); }/*from www. j a va 2 s.c om*/ //block on the futures all getting or throwing instead of using a latch as i need to check future status anyway boolean interrupted = false; try { for (int i = 0; i < workers.size(); i++) { try { completion.take().get(); //Void } catch (InterruptedException e) { interrupted = true; // fail out because janusgraph does not poll this thread for interrupted anywhere throw new BackendRuntimeException("was interrupted during parallelMutate"); } catch (ExecutionException e) { throw unwrapExecutionException(e, MUTATE_ITEM); } } } finally { for (Future<Void> future : futures) { if (!future.isDone()) { future.cancel(interrupted /* mayInterruptIfRunning */); } } if (interrupted) { // set interrupted on this thread Thread.currentThread().interrupt(); } } }
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
public List<QueryResultWrapper> parallelQuery(List<QueryWorker> queryWorkers) throws BackendException { CompletionService<QueryResultWrapper> completionService = new ExecutorCompletionService<>(clientThreadPool); List<Future<QueryResultWrapper>> futures = Lists.newLinkedList(); for (QueryWorker worker : queryWorkers) { futures.add(completionService.submit(worker)); }/*from w w w. j av a 2s . c o m*/ boolean interrupted = false; List<QueryResultWrapper> results = Lists.newLinkedList(); try { for (int i = 0; i < queryWorkers.size(); i++) { try { QueryResultWrapper result = completionService.take().get(); results.add(result); } catch (InterruptedException e) { interrupted = true; // fail out because titan does not poll this thread for interrupted anywhere throw new BackendRuntimeException("was interrupted during parallelQuery"); } catch (ExecutionException e) { throw unwrapExecutionException(e, QUERY); } } } finally { for (Future<QueryResultWrapper> future : futures) { if (!future.isDone()) { future.cancel(interrupted /* mayInterruptIfRunning */); } } if (interrupted) { // set interrupted on this thread and fail out Thread.currentThread().interrupt(); } } return results; }
From source file:org.dasein.cloud.compute.AbstractVMSupport.java
@Override public @Nonnull Iterable<String> launchMany(final @Nonnull VMLaunchOptions withLaunchOptions, final @Nonnegative int count) throws CloudException, InternalException { if (count < 1) { throw new InternalException( "Invalid attempt to launch less than 1 virtual machine (requested " + count + ")."); }//from w w w .j a v a 2s .c om if (count == 1) { return Collections.singleton(launch(withLaunchOptions).getProviderVirtualMachineId()); } final List<Future<String>> results = new ArrayList<Future<String>>(); MachineImage image = null; ComputeServices services = getProvider().getComputeServices(); if (services != null) { MachineImageSupport support = services.getImageSupport(); if (support != null) { image = support.getImage(withLaunchOptions.getMachineImageId()); } } NamingConstraints c = NamingConstraints.getHostNameInstance(image == null || image.getPlatform().equals(Platform.UNKNOWN) || image.getPlatform().equals(Platform.WINDOWS)); String baseHost = c.convertToValidName(withLaunchOptions.getHostName(), Locale.US); if (baseHost == null) { baseHost = withLaunchOptions.getHostName(); } for (int i = 1; i <= count; i++) { String hostName = c.incrementName(baseHost, i); String friendlyName = withLaunchOptions.getFriendlyName() + "-" + i; VMLaunchOptions options = withLaunchOptions .copy(hostName == null ? withLaunchOptions.getHostName() + "-" + i : hostName, friendlyName); results.add(launchAsync(options)); } PopulatorThread<String> populator = new PopulatorThread<String>(new JiteratorPopulator<String>() { @Override public void populate(@Nonnull Jiterator<String> iterator) throws Exception { List<Future<String>> original = results; List<Future<String>> copy = new ArrayList<Future<String>>(); Exception exception = null; boolean loaded = false; while (!original.isEmpty()) { for (Future<String> result : original) { if (result.isDone()) { try { iterator.push(result.get()); loaded = true; } catch (Exception e) { exception = e; } } else { copy.add(result); } } original = copy; // copy has to be a new list else we'll get into concurrently modified list state copy = new ArrayList<Future<String>>(); } if (exception != null && !loaded) { throw exception; } } }); populator.populate(); return populator.getResult(); }
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
public Map<StaticBuffer, GetItemResult> parallelGetItem(List<GetItemWorker> workers) throws BackendException { final CompletionService<GetItemResultWrapper> completionService = new ExecutorCompletionService<>( clientThreadPool);//from w ww. jav a 2s . c om final List<Future<GetItemResultWrapper>> futures = Lists.newLinkedList(); for (GetItemWorker worker : workers) { futures.add(completionService.submit(worker)); } boolean interrupted = false; final Map<StaticBuffer, GetItemResult> results = Maps.newHashMap(); try { for (int i = 0; i < workers.size(); i++) { try { GetItemResultWrapper result = completionService.take().get(); results.put(result.getTitanKey(), result.getDynamoDBResult()); } catch (InterruptedException e) { interrupted = true; throw new BackendRuntimeException("was interrupted during parallelGet"); } catch (ExecutionException e) { throw unwrapExecutionException(e, GET_ITEM); } } } finally { for (Future<GetItemResultWrapper> future : futures) { if (!future.isDone()) { future.cancel(interrupted /* mayInterruptIfRunning */); } } if (interrupted) { // set interrupted on this thread and fail out Thread.currentThread().interrupt(); } } return results; }
From source file:com.opendoorlogistics.studio.appframe.AppFrame.java
@Override public PendingScriptExecution postScriptExecution(File file, String[] optionIds) { Future<Void> future = scriptManager.executeScript(file, optionIds); return new PendingScriptExecution() { @Override/*from w w w . jav a2 s . c o m*/ public boolean isDone() { return future.isDone(); } }; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
public List<QueryResultWrapper> parallelQuery(List<QueryWorker> queryWorkers) throws BackendException { CompletionService<QueryResultWrapper> completionService = new ExecutorCompletionService<>(clientThreadPool); List<Future<QueryResultWrapper>> futures = Lists.newLinkedList(); for (QueryWorker worker : queryWorkers) { futures.add(completionService.submit(worker)); }/*from w w w .java 2 s . c om*/ boolean interrupted = false; List<QueryResultWrapper> results = Lists.newLinkedList(); try { for (int i = 0; i < queryWorkers.size(); i++) { try { QueryResultWrapper result = completionService.take().get(); results.add(result); } catch (InterruptedException e) { interrupted = true; // fail out because janusgraph does not poll this thread for interrupted anywhere throw new BackendRuntimeException("was interrupted during parallelQuery"); } catch (ExecutionException e) { throw unwrapExecutionException(e, QUERY); } } } finally { for (Future<QueryResultWrapper> future : futures) { if (!future.isDone()) { future.cancel(interrupted /* mayInterruptIfRunning */); } } if (interrupted) { // set interrupted on this thread and fail out Thread.currentThread().interrupt(); } } return results; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java
public Map<StaticBuffer, GetItemResult> parallelGetItem(List<GetItemWorker> workers) throws BackendException { final CompletionService<GetItemResultWrapper> completionService = new ExecutorCompletionService<>( clientThreadPool);/*from w w w . j av a 2s . com*/ final List<Future<GetItemResultWrapper>> futures = Lists.newLinkedList(); for (GetItemWorker worker : workers) { futures.add(completionService.submit(worker)); } boolean interrupted = false; final Map<StaticBuffer, GetItemResult> results = Maps.newHashMap(); try { for (int i = 0; i < workers.size(); i++) { try { GetItemResultWrapper result = completionService.take().get(); results.put(result.getJanusGraphKey(), result.getDynamoDBResult()); } catch (InterruptedException e) { interrupted = true; throw new BackendRuntimeException("was interrupted during parallelGet"); } catch (ExecutionException e) { throw unwrapExecutionException(e, GET_ITEM); } } } finally { for (Future<GetItemResultWrapper> future : futures) { if (!future.isDone()) { future.cancel(interrupted /* mayInterruptIfRunning */); } } if (interrupted) { // set interrupted on this thread and fail out Thread.currentThread().interrupt(); } } return results; }
From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java
protected SerializationReport exportEntity(CmsEntityType cmsEntityToExport, SerializationConfiguration serializationConfiguration) throws InterruptedException, ExecutionException { long timeStart = System.currentTimeMillis(); Future<SerializationReport> exportReportFuture = serializationDao .serializeAllInstancesOfEntity(cmsEntityToExport, serializationConfiguration); //Wait until export is finished while (!exportReportFuture.isDone()) { final long timePassed = System.currentTimeMillis() - timeStart; Assert.assertTrue(timePassed < (5 * 60 * 1000), "Export does not seem to have finished. Time passed " + timePassed + " ms"); }//from w w w . ja v a2 s.com return exportReportFuture.get(); }