List of usage examples for java.util.concurrent Future get
V get() throws InterruptedException, ExecutionException;
From source file:com.alibaba.doris.admin.service.failover.node.check.NodeCheckService.java
/** * ??//from w w w.jav a2 s .com * * @param timeout ???0? * @see java.util.concurrent.ExecutorService#invokeAll(java.util.Collection) */ public List<NodeCheckResult> invokeAll(List<? extends NodeCheckTask> tasks, long timeout) { List<NodeCheckResult> nodes = new ArrayList<NodeCheckResult>(tasks.size()); try { List<Future<NodeCheckResult>> futures = null; if (timeout < 0) { futures = executorService.invokeAll(tasks, DEFAULT_TASK_TIMEOUT * tasks.size(), TimeUnit.MILLISECONDS); } else { futures = executorService.invokeAll(tasks, timeout, TimeUnit.MILLISECONDS); } for (Future<NodeCheckResult> future : futures) { try { nodes.add(future.get()); } catch (ExecutionException e) { log.error("failed to check node, skip and continue.", e); } } } catch (InterruptedException e) { log.error("failed to check node, skip and continue.", e); } return nodes; }
From source file:com.nebhale.gpxconverter.GoogleMapsAugmenter.java
@Override public List<Point> augment(List<Point> points) { List<Future<List<Point>>> futures = new ArrayList<>(); for (int i = 0, delay = 0; i < points.size(); i += CHUNK_SIZE, delay++) { int max = CHUNK_SIZE + i; List<Point> slice = points.subList(i, max < points.size() ? max : points.size()); futures.add(this.scheduledExecutorService.schedule( new PointAugmenter(delay, this.encoder, this.restOperations, slice), delay * 10 * CHUNK_SIZE, TimeUnit.MILLISECONDS)); }//from w w w . jav a 2s . c o m List<Point> augmented = new ArrayList<>(points.size()); for (Future<List<Point>> future : futures) { try { augmented.addAll(future.get()); } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } } return augmented; }
From source file:idc.storyalbum.fetcher.FilterService.java
public Set<Photo> filter(Set<Photo> photos, Set<String> tags) throws ExecutionException, InterruptedException, FlickrException { log.info("Removing from {} photos photos without tags {}", photos.size(), tags); ExecutorService executorService = Executors.newFixedThreadPool(20); List<Future<Pair<Photo, Photo>>> futures = new ArrayList<>(); for (Photo photo : photos) { futures.add(executorService.submit(new FilterTagTask(photo, tags))); }//from ww w.jav a 2s . c o m executorService.shutdown(); Set<Photo> result = new HashSet<>(); for (Future<Pair<Photo, Photo>> future : futures) { Pair<Photo, Photo> photoBooleanPair = future.get(); Photo photo = photoBooleanPair.getLeft(); String url; try { url = photo.getOriginalUrl(); } catch (Exception e) { url = photo.getUrl(); } Photo detailedPhoto = photoBooleanPair.getRight(); if (detailedPhoto == null) { log.info("Filtered {}", url); photos.remove(photo); } else { result.add(detailedPhoto); } } return result; }
From source file:org.anhonesteffort.p25.ACAP25.java
private Optional<Double> findActiveControlChannel(Integer systemId, Integer systemWacn, Site site) { for (Double channelFreq : site.getControlChannels()) { P25ChannelSpec channelSpec = new P25ChannelSpec(channelFreq); P25Channel channel = new P25Channel(channelSpec); ControlChannelQualifier channelQualifier = new ControlChannelQualifier(controlChannelPool, samplesController, channel, systemId, systemWacn); try {// ww w .ja va 2 s . com Future<Optional<Double>> channelQualified = controlChannelPool.submit(channelQualifier); Optional<Double> controlFreq = channelQualified.get(); if (controlFreq.isPresent()) { log.info( "found active control channel at " + controlFreq.get() + " for site " + site.getName()); return Optional.of(controlFreq.get()); } } catch (InterruptedException | ExecutionException e) { log.error("error while identifying active control channels, exiting", e); java.lang.System.exit(1); } } return Optional.empty(); }
From source file:org.openbaton.nfvo.vnfm_reg.tasks.AllocateresourcesTask.java
@Override protected NFVMessage doWork() throws Exception { log.info("Executing task: AllocateResources for VNFR: " + virtualNetworkFunctionRecord.getName()); log.debug("Verison is: " + virtualNetworkFunctionRecord.getHb_version()); try {/*w w w . j a v a2 s . c o m*/ for (VirtualDeploymentUnit vdu : virtualNetworkFunctionRecord.getVdu()) { List<Future<List<String>>> ids = new ArrayList<>(); VimInstance vimInstance = vims.get(vdu.getId()); if (vimInstance == null) throw new NullPointerException( "Our algorithms are too complex, even for us, this is what abnormal IQ means :("); try { ids.add(resourceManagement.allocate(vdu, virtualNetworkFunctionRecord, vimInstance, userData, keys)); for (Future<List<String>> id : ids) { id.get(); } } catch (VimException e) { e.printStackTrace(); log.error(e.getMessage()); LifecycleEvent lifecycleEvent = new LifecycleEvent(); lifecycleEvent.setEvent(Event.ERROR); VNFCInstance vnfcInstance = e.getVnfcInstance(); if (vnfcInstance != null) { log.info("The VM was not correctly deployed. ExtId is: " + vnfcInstance.getVc_id()); log.debug("Details are: " + vnfcInstance); vdu.getVnfc_instance().add(vnfcInstance); } virtualNetworkFunctionRecord.getLifecycle_event_history().add(lifecycleEvent); saveVirtualNetworkFunctionRecord(); return new OrVnfmErrorMessage(virtualNetworkFunctionRecord, e.getMessage()); } } } catch (VimDriverException e) { e.printStackTrace(); log.error(e.getMessage()); LifecycleEvent lifecycleEvent = new LifecycleEvent(); lifecycleEvent.setEvent(Event.ERROR); virtualNetworkFunctionRecord.getLifecycle_event_history().add(lifecycleEvent); virtualNetworkFunctionRecord.setStatus(Status.ERROR); saveVirtualNetworkFunctionRecord(); return new OrVnfmErrorMessage(virtualNetworkFunctionRecord, e.getMessage()); } for (LifecycleEvent event : virtualNetworkFunctionRecord.getLifecycle_event()) { if (event.getEvent().ordinal() == Event.ALLOCATE.ordinal()) { virtualNetworkFunctionRecord.getLifecycle_event_history().add(event); break; } } saveVirtualNetworkFunctionRecord(); OrVnfmGenericMessage orVnfmGenericMessage = new OrVnfmGenericMessage(virtualNetworkFunctionRecord, Action.ALLOCATE_RESOURCES); log.debug("Answering to RPC allocate resources: " + orVnfmGenericMessage); log.info("Finished task: AllocateResources for VNFR: " + virtualNetworkFunctionRecord.getName()); return orVnfmGenericMessage; }
From source file:org.openspaces.rest.space.SpaceTaskAPIController.java
private ModelAndView execute(String spaceName, String locators, final SpaceTaskRequest request) { GigaSpace space = ControllerUtils.xapCache.get(spaceName, locators); final int instanceCount = ControllerUtils.xapCache.getInstances(spaceName); ExecutorService svc = Executors.newFixedThreadPool(instanceCount); int instances = 0; log.fine("request.target=" + request.target); if (request.target != null && !request.target.equals("all")) { instances = 1;/* w w w . j a v a 2 s .co m*/ } else { instances = instanceCount; } System.out.println("instances=" + instances); List<Callable<Object>> tasks = new ArrayList<Callable<Object>>(instances); for (int i = 0; i < instances; i++) { Object routing = 0; if (request.target != null && request.target.equals("all")) { routing = i; } else { routing = request.target; } tasks.add(new ScriptCallable(space, request, routing)); } ModelAndView mv = new ModelAndView("jsonView"); List<Object> model = new ArrayList<Object>(instances); try { List<Future<Object>> results = svc.invokeAll(tasks); for (Future<Object> fut : results) { if (fut.get() != null) model.add(fut.get()); } mv.addObject("results", model); } catch (Exception e) { throw new RuntimeException(e); } finally { svc.shutdownNow(); } return mv; }
From source file:com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable.java
private void collectPartETags(final List<Future<PartETag>> futures, final List<PartETag> partETags) { for (Future<PartETag> future : futures) { try {/* w w w.j a v a 2s . co m*/ partETags.add(future.get()); } catch (Exception e) { throw new AmazonClientException("Unable to upload part: " + e.getCause().getMessage(), e.getCause()); } } }
From source file:com.amazonaws.devicefarm.DeviceFarmUploader.java
public Collection<Upload> batchUpload(final List<File> artifacts, final Project project, final UploadType uploadType) { List<Future<Upload>> futures = Lists.newArrayList(); // Upload each artifact and create a future for it. for (final File file : artifacts) { futures.add(uploadExecutor.submit(new Callable<Upload>() { @Override/*from w ww .ja va2s. c o m*/ public Upload call() throws Exception { return upload(file, project, uploadType); } })); } List<Upload> uploads = Lists.newArrayList(); // Check future results and append the upload results to a list. for (Future<Upload> f : futures) { try { uploads.add(f.get()); } catch (Exception e) { throw new DeviceFarmException(e); } } return uploads; }
From source file:org.fcrepo.kernel.impl.spring.ModeShapeRepositoryFactoryBean.java
/** * Attempts to undeploy the repository and shutdown the ModeShape engine on * context destroy.// ww w. j a v a 2 s .co m * * @throws InterruptedException if interrupted exception occurred */ @PreDestroy public void stopRepository() throws InterruptedException { LOGGER.info("Initiating shutdown of ModeShape"); final String repoName = repository.getName(); try { final Future<Boolean> futureUndeployRepo = modeShapeEngine.undeploy(repoName); futureUndeployRepo.get(); LOGGER.info("Repository {} undeployed.", repoName); } catch (final NoSuchRepositoryException e) { LOGGER.error("Repository {} unknown, cannot undeploy.", repoName, e); } catch (final ExecutionException e) { LOGGER.error("Repository {} cannot undeploy.", repoName, e); } final Future<Boolean> futureShutdownEngine = modeShapeEngine.shutdown(); try { if (futureShutdownEngine.get()) { LOGGER.info("ModeShape Engine has shutdown."); } else { LOGGER.error("ModeShape Engine shutdown failed without an exception, still running."); } } catch (final ExecutionException e) { LOGGER.error("ModeShape Engine shutdown failed.", e); } }
From source file:com.amazonaws.services.kinesis.multilang.MessageWriterTest.java
@Test public void writeCheckpointMessageNoErrorTest() throws IOException, InterruptedException, ExecutionException { Future<Boolean> future = this.messageWriter.writeCheckpointMessageWithError("1234", null); future.get(); Mockito.verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());// w ww . ja v a 2s . c o m Mockito.verify(this.stream, Mockito.atLeastOnce()).flush(); }