List of usage examples for java.util.concurrent Future get
V get() throws InterruptedException, ExecutionException;
From source file:com.reactive.hzdfs.TestRunner.java
@Test public void testFailOnZIPFile() { Throwable c = null;//from w w w .ja v a2s . c o m try { File f = ResourceLoaderHelper.loadFromFileOrClassPath("text_example.zip"); Future<DFSSResponse> fut = dfss.distribute(f, new DFSSTaskConfig()); fut.get(); Assert.fail(); } catch (IOException e) { Assert.fail("IOException - " + e); } catch (InterruptedException e) { Assert.fail("InterruptedException - " + e); } catch (ExecutionException e) { c = e.getCause(); } Assert.assertNotNull(c); Assert.assertTrue(c instanceof DFSSException); Assert.assertEquals(DFSSException.ERR_IO_FILE, ((DFSSException) c).getErrorCode()); }
From source file:com.reactive.hzdfs.TestRunner.java
@Test public void testFailOnPPTFile() { Throwable c = null;// w w w. j a va 2 s. co m try { File f = ResourceLoaderHelper.loadFromFileOrClassPath("Presentation1.pptx"); Future<DFSSResponse> fut = dfss.distribute(f, new DFSSTaskConfig()); fut.get(); Assert.fail(); } catch (IOException e) { Assert.fail("IOException - " + e); } catch (InterruptedException e) { Assert.fail("InterruptedException - " + e); } catch (ExecutionException e) { c = e.getCause(); } Assert.assertNotNull(c); Assert.assertTrue(c instanceof DFSSException); Assert.assertEquals(DFSSException.ERR_IO_FILE, ((DFSSException) c).getErrorCode()); }
From source file:cn.clxy.upload.UploadFileService.java
private String checkFuture(Future<String> future) { String result = null;/*from w w w .j a va 2 s.c o m*/ try { result = future.get(); return result; } catch (InterruptedException e) { Thread.currentThread().interrupt(); return null; } catch (ExecutionException e) { listener.onFail(result); log.error(e.getCause()); throw new RuntimeException(e.getCause()); } }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles/new", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> getNewArticlesAround(@RequestParam Double lat, @RequestParam Double lon) throws InterruptedException, ExecutionException, JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(GEO_URL).queryParam("lat", lat.toString()) .queryParam("lon", lon.toString()); RestTemplate template = new RestTemplate(); List<Map<String, Object>> geoResponse = template.getForObject(builder.build().encode().toUri(), List.class); Iterator<Map<String, Object>> it = geoResponse.iterator(); List<Future<ResponseEntity<Map>>> jobs = new ArrayList<>(); // to be able to merge answers from rating to geoitems there is a need // to map the article to its articleID // (articleID) => (articleItem) Map<String, Map<String, Object>> mappedResponseObjects = new HashMap<>(); while (it.hasNext()) { Map<String, Object> item = it.next(); AsyncRestTemplate async = new AsyncRestTemplate(); Future<ResponseEntity<Map>> futureResult = async.getForEntity((String) item.get("rating"), Map.class); jobs.add(futureResult);//w w w . j a v a2 s. c o m mappedResponseObjects.put((String) item.get("articleID"), item); } for (Future<ResponseEntity<Map>> job : jobs) { Map<String, Object> ratingMap = job.get().getBody(); String articleID = (String) ratingMap.get("articleID"); mappedResponseObjects.get(articleID).putAll(ratingMap); } WeightingPolicy policy = new WeightingPolicyImpl(); List<Map<String, Object>> orderedResponse = policy.sortExcludingRating(mappedResponseObjects.values()); List<Map<String, Object>> result = new ResponseMapFilterImpl().filter(orderedResponse); return new ResponseEntity<>(objectMapper.writeValueAsString(result), HttpStatus.OK); }
From source file:edu.stolaf.cs.wmrserver.TestJobEngine.java
protected synchronized TestJobResult getResult(long submissionID) throws NotFoundException, ExecutionException, CancellationException { Future<TestJobResult> job = findJob(submissionID); while (true) { try {//w w w . j a va2s. c om return job.get(); } catch (InterruptedException ex) { // Swallow and try again } } }
From source file:org.apache.hadoop.gateway.shell.Hadoop.java
public void waitFor(Future<?>... futures) throws ExecutionException, InterruptedException { if (futures != null) { for (Future future : futures) { future.get(); }//from www .j a va 2 s. c o m } }
From source file:com.github.lukaszbudnik.dqueue.QueueClientIntegrationTest.java
@Test public void shouldHandlePreviousDay() throws ExecutionException, InterruptedException { long yesterdayTimestamp = System.currentTimeMillis() - 24 * 60 * 60 * 1_000; UUID yesterdayUUID = UUIDsTesting.timeBased(yesterdayTimestamp); Future<UUID> published = queueClient.publish(new Item(yesterdayUUID, ByteBuffer.wrap("".getBytes()))); published.get(); Future<Optional<Item>> itemFuture = queueClient.consume(); Optional<Item> itemOptional = itemFuture.get(); Item item = itemOptional.get();//from w w w .jav a 2s .c o m assertEquals(yesterdayUUID, item.getStartTime()); }
From source file:com.ritesh.idea.plugin.reviewboard.ReviewDataProvider.java
public List<Review.File> files(final Review review, final Progress progress) throws Exception { List<Review.File> result = new ArrayList<>(); final List<Future> futures = new CopyOnWriteArrayList<>(); final MutableFloat progressF = new MutableFloat(0f); final RBDiffList diffList = client.diffListApi(review.id); if (diffList.total_results > 0) { final String revision = String.valueOf(diffList.diffs[0].revision); RBFileDiff fileDiff = client.fileDiffApi(review.id, revision); for (final RBFileDiff.File file : fileDiff.files) { final Review.File diffFile = new Review.File(); diffFile.fileId = file.id;/*w ww. j av a2 s . c o m*/ diffFile.srcFileName = file.source_file; diffFile.dstFileName = file.dest_file; diffFile.sourceRevision = file.source_revision; diffFile.revision = revision; futures.add(ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { progress.progress("Loading file contents " + Paths.get(diffFile.srcFileName).getFileName(), progressF.floatValue()); diffFile.srcFileContents = client.contents(file.links.original_file.href); progressF.setValue(progressF.floatValue() + 1.0f / diffList.total_results); progress.progress("Completed loading contents", progressF.floatValue()); } })); futures.add(ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { progress.progress("Loading file contents " + Paths.get(diffFile.dstFileName).getFileName(), progressF.floatValue()); diffFile.dstFileContents = client.contents(file.links.patched_file.href); progressF.setValue(progressF.floatValue() + 1.0f / diffList.total_results); progress.progress("Completed loading contents", progressF.floatValue()); } })); result.add(diffFile); } } for (Future future : futures) future.get(); return result; }
From source file:com.github.lukaszbudnik.dqueue.QueueClientIntegrationTest.java
@Test public void shouldReturnNothingIfQueueIsEmpty() throws ExecutionException, InterruptedException { Future<Optional<Item>> itemFuture = queueClient.consume(ImmutableMap.of("type", "123")); Optional<Item> item = itemFuture.get(); assertFalse(item.isPresent());/*www . j a v a 2 s . c o m*/ }
From source file:com.reactive.hzdfs.TestRunner.java
@Test public void testDistributeSimpleFile() { try {/*from w w w . j av a 2s. c o m*/ File f = ResourceLoaderHelper.loadFromFileOrClassPath("vp-client.log"); Future<DFSSResponse> fut = dfss.distribute(f, new DFSSTaskConfig()); resp = fut.get(); Assert.assertEquals("Records do not match", 48, resp.getNoOfRecords()); Assert.assertTrue("error list not empty", resp.getErrorNodes().isEmpty()); return; } catch (IOException e) { Assert.fail("Job did not start - " + e); } catch (InterruptedException e) { Assert.fail("InterruptedException - " + e); } catch (ExecutionException e) { Assert.fail("File distribution error - " + e.getCause()); } return; }