List of usage examples for java.util.concurrent Future get
V get() throws InterruptedException, ExecutionException;
From source file:ems.web.model.service.resume.ResumeServiceImpl.java
@Override public String hireApply(String content, String email, String subject, MultipartFile file) { EmailDTO emailDTO = new EmailDTO(); emailDTO.setReceiver(email);//from w w w .j av a2 s. c om emailDTO.setSubject(subject); emailDTO.setContent(content); emailDTO.setFile(file); try { Future<String> future = mailSenderServiceImpl.sendApply(emailDTO); return future.get(); } catch (Exception e) { e.printStackTrace(); } return "error/errorMessage"; }
From source file:com.github.tomakehurst.wiremock.ResponseDelayAsynchronousAcceptanceTest.java
@Test public void addsFixedDelayAsynchronously() throws Exception { stubFor(get("/delayed").willReturn(ok().withFixedDelay(SHORTER_THAN_SOCKET_TIMEOUT))); List<Future<TimedHttpResponse>> responses = httpClientExecutor.invokeAll(getHttpRequestCallables(5)); for (Future<TimedHttpResponse> response : responses) { TimedHttpResponse timedResponse = response.get(); assertThat(timedResponse.response.getStatusLine().getStatusCode(), is(200)); assertThat(timedResponse.milliseconds, greaterThan((double) SHORTER_THAN_SOCKET_TIMEOUT)); }//from ww w . j a va 2 s . c o m }
From source file:com.github.tomakehurst.wiremock.ResponseDelayAsynchronousAcceptanceTest.java
@Test public void addsRandomDelayAsynchronously() throws Exception { stubFor(get("/delayed").willReturn(ok().withUniformRandomDelay(100, 300))); List<Future<TimedHttpResponse>> responses = httpClientExecutor.invokeAll(getHttpRequestCallables(5)); for (Future<TimedHttpResponse> response : responses) { TimedHttpResponse timedResponse = response.get(); assertThat(timedResponse.response.getStatusLine().getStatusCode(), is(200)); assertThat(timedResponse.milliseconds, greaterThan(100.0)); }/*ww w .j a va 2s. c om*/ }
From source file:com.webcrawler.manager.impl.ImageManagerImpl.java
@Override public List<ImageDTO> getImageData(final String url) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException { if (url == null || url.equals("")) { throw new IllegalArgumentException("Set URL first"); }/*from ww w . j a va 2 s . c o m*/ Callable<List<ImageDTO>> callable = new Callable<List<ImageDTO>>() { @Override public List<ImageDTO> call() throws Exception { System.out.println("Retrieving image data from url " + url); Document document = null; Elements media = null; List<ImageDTO> images = new ArrayList<ImageDTO>(); try { document = Jsoup.connect(url).get(); media = document.select("[src]"); } catch (Exception e) { e.printStackTrace(); return images; } System.out.println("# of images: " + media.size()); for (Element src : media) { if (src.tagName().equals("img")) { ImageDTO dto = new ImageDTO(); dto.setUrlAddress(src.attr("abs:src")); dto.setFileName(getFileName(src.attr("abs:src"))); images.add(dto); } } return images; } }; Future<List<ImageDTO>> result = executorService.submit(callable); return result.get(); }
From source file:com.github.trask.sandbox.mail.ElasticEmailServiceTest.java
@Test public void shouldSendEmail() throws Exception { // given//from w ww . ja v a 2s. c o m final long random = RandomUtils.nextLong(); String from = "unit.test.from@example.com"; String to = "unit.test.to@example.com"; String subject = getClass().getSimpleName(); String htmlBody = "<html><body>click <a href=\"http://google.com\">here</a> " + random; String textBody = "go to http://google.com " + random; // when Future<Void> future = mailService.sendMail(from, to, subject, htmlBody, textBody); future.get(); // then VerifyUtil.verifyInTheNextNSeconds(120, new Verification() { public void execute() throws IOException, MessagingException { List<PoppedEmail> poppedEmails = popClient.pop(); assertThat(poppedEmails.size(), is(1)); PoppedEmail poppedEmail = poppedEmails.get(0); assertThat(poppedEmail.getTextBody().contains(Long.toString(random)), is(true)); } }); }
From source file:maltcms.ui.fileHandles.serialized.JFCOpenSupport.java
@Override protected CloneableTopComponent createCloneableTopComponent() { final JFCDataObject dobj = (JFCDataObject) entry.getDataObject(); final JFCTopComponent tc = new JFCTopComponent(); tc.setDisplayName(dobj.getName());/* w ww . j a v a2s . co m*/ final ProgressHandle ph = ProgressHandleFactory .createHandle("Loading file " + dobj.getPrimaryFile().getName()); tc.setDisplayName(dobj.getPrimaryFile().getName()); final ExecutorService es = Executors.newSingleThreadExecutor(); final Future<JFreeChart> f = es.submit(new JFCLoader(dobj.getPrimaryFile().getPath(), ph)); try { tc.setChart(f.get()); } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } finally { ph.finish(); } return tc; }
From source file:com.collective.celos.ci.mode.TestTask.java
void waitForCompletion(List<Future> futures) throws Throwable { List<Throwable> throwables = Lists.newArrayList(); for (Future future : futures) { try {/*from w w w . j av a2 s . c om*/ future.get(); } catch (ExecutionException ee) { throwables.add(ee.getCause()); } } if (!throwables.isEmpty()) { List<Throwable> throwablesWOLast = throwables.subList(0, throwables.size() - 1); for (Throwable t : throwablesWOLast) { t.printStackTrace(); } Throwable lastThrowable = throwables.get(throwables.size() - 1); throw lastThrowable; } }
From source file:com.teradata.benchto.driver.listeners.benchmark.BenchmarkStatusReporter.java
public void processCompletedFutures() { synchronized (pendingFutures) { while (!pendingFutures.isEmpty() && pendingFutures.element().isDone()) { Future<?> doneFuture = pendingFutures.remove(); try { doneFuture.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted when retrieving result of an already done future", e); } catch (ExecutionException | CancellationException e) { throw new RuntimeException("Listener failed with: " + e, e); }/*from w ww.j a va2 s . co m*/ } } }
From source file:com.github.trask.sandbox.mail.AmazonMailServiceTest.java
@Test public void shouldSendEmail() throws Exception { // given// ww w . j a va 2 s. c o m final long random = RandomUtils.nextLong(); String from = "unit.test.from@example.com"; String to = "unit.test.to@example.com"; String subject = getClass().getSimpleName(); String htmlBody = "<html><body>click <a href=\"http://google.com\">here</a> " + random; String textBody = "go to http://google.com " + random; // when Future<Void> future = mailService.sendMail(from, to, subject, htmlBody, textBody); future.get(); // then VerifyUtil.verifyInTheNextNSeconds(120, new Verification() { public void execute() throws IOException, MessagingException { List<PoppedEmail> poppedEmails = popClient.pop(); assertThat(poppedEmails.size(), is(1)); PoppedEmail poppedEmail = poppedEmails.get(0); assertThat(poppedEmail.getTextBody().contains(Long.toString(random)), is(true)); } }); }
From source file:ufo.remote.calls.benchmark.server.jms.activemq.ActiveMqBrokerServiceTest.java
@Test public void brokerShouldReplyToAQueue() throws InterruptedException, ExecutionException { ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); String message = "HelloMyLittleWorld" + UUID.randomUUID().toString(); Future<String> response = producerTemplate.asyncRequestBody(EchoQueueConfig.ECHO_QUEUE_URL, message, String.class); assertEquals(message, response.get()); }