Example usage for java.util.concurrent Future get

List of usage examples for java.util.concurrent Future get

Introduction

In this page you can find the example usage for java.util.concurrent Future get.

Prototype

V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;

Source Link

Document

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Usage

From source file:apiserver.services.images.controllers.manipulations.BorderController.java

/**
 * Draw a border around an image//from  w  ww.jav  a2s  .co m
 *
 * @param documentId
 * @param color
 * @param thickness
 * @param format
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 */
@RequestMapping(value = "/modify/{documentId}/border.{format}", method = { RequestMethod.GET })
public ResponseEntity<byte[]> drawBorderByImage(
        @ApiParam(name = "documentId", required = true) @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "color", required = true) @RequestParam(required = true) String color,
        @ApiParam(name = "thickness", required = true) @RequestParam(required = true) Integer thickness,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

) throws InterruptedException, ExecutionException, TimeoutException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    FileBorderJob args = new FileBorderJob();
    args.setDocumentId(documentId);
    args.setColor(color);
    args.setThickness(thickness);
    args.setFormat(format);

    Future<Map> imageFuture = imageDrawBorderGateway.imageDrawBorderFilter(args);
    FileBorderJob payload = (FileBorderJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    //pass CF Response back to the client
    return payload.getHttpResponse();
}

From source file:apiserver.services.images.controllers.filters.MedianController.java

/**
 * This filter replaces each pixel by the median of the input pixel and its eight neighbours. Each of the RGB channels is considered separately.
 *
 * @param documentId//from  w w  w . java 2s  . c  om
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter replaces each pixel by the median of the input pixel and its eight neighbours. Each of the RGB channels is considered separately.")
@RequestMapping(value = "/filter/{documentId}/median.{format}", method = { RequestMethod.GET })
@ResponseBody
public ResponseEntity<byte[]> imageMedianByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob args = new ImageDocumentJob();
    args.setDocumentId(documentId);

    Future<Map> imageFuture = imageFilterMedianGateway.imageMedianFilter(args);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType,
            false);
    return result;
}

From source file:apiserver.services.pdf.controllers.FormController.java

/**
 * Extract the value of the form fields in a pdf
 * @param file//  w w w .  ja  v a2 s. c  o  m
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Extract the value of the form fields in a pdf")
@RequestMapping(value = "/form/extract", method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<Object> extractFormFields(
        @ApiParam(name = "file", required = true) @RequestPart("file") MultipartFile file,
        @ApiParam(name = "password", required = false) @RequestPart("password") String password)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    ExtractPdfFormJob job = new ExtractPdfFormJob();
    job.setFile(new Document(file));
    if (password != null)
        job.setPassword(password);

    Future<Map> future = gateway.extractPdfForm(job);
    ExtractPdfFormJob payload = (ExtractPdfFormJob) future.get(defaultTimeout, TimeUnit.MILLISECONDS);

    return ResponseEntityHelper.processObject(payload);
}

From source file:apiserver.services.pdf.controllers.FormController.java

/**
 * Extract the value of the form fields in a pdf
 * @param documentId//w  w  w.  j  a v  a 2  s  . co m
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Extract the value of the form fields in a pdf")
@RequestMapping(value = "/form/{documentId}/extract", method = RequestMethod.GET, produces = "application/pdf")
public ResponseEntity<Object> extractCachedFormFields(
        @ApiParam(name = "documentId", required = true) @RequestPart("documentId") String documentId,
        @ApiParam(name = "password", required = false) @RequestPart("password") String password)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    ExtractPdfFormJob job = new ExtractPdfFormJob();
    job.setDocumentId(documentId);
    if (password != null)
        job.setPassword(password);

    Future<Map> future = gateway.extractPdfForm(job);
    ExtractPdfFormJob payload = (ExtractPdfFormJob) future.get(defaultTimeout, TimeUnit.MILLISECONDS);

    return ResponseEntityHelper.processObject(payload);
}

From source file:com.consol.citrus.samples.docker.AbstractDockerIT.java

@BeforeSuite(alwaysRun = true)
public void checkDockerEnvironment() {
    try {/*  w  w  w.ja v  a  2s  .  co  m*/
        Future<Boolean> future = Executors.newSingleThreadExecutor().submit(() -> {
            dockerClient.getEndpointConfiguration().getDockerClient().pingCmd().exec();
            return true;
        });

        future.get(5000, TimeUnit.MILLISECONDS);
        connected = true;
    } catch (Exception e) {
        log.warn("Skipping Docker test execution as no proper Docker environment is available on host system!",
                e);
    }
}

From source file:apiserver.services.images.controllers.filters.GlowController.java

/**
 * This filter produces a glowing effect on an uploaded image by adding a blurred version of the image to subtracted from the original image.
 *
 * @param documentId//  www.  j  av a 2s .c om
 * @param amount
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter produces a glowing effect on an image by adding a blurred version of the image to subtracted from the original image.")
@RequestMapping(value = "/filter/{documentId}/glow.{format}", method = { RequestMethod.GET })
public ResponseEntity<byte[]> imageGlowByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "amount", required = true, defaultValue = "2") @RequestParam(required = false, defaultValue = "2") int amount,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    GlowJob args = new GlowJob();
    args.setDocumentId(documentId);
    args.setAmount(amount);

    Future<Map> imageFuture = imageFilterGlowGateway.imageGlowFilter(args);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType,
            false);
    return result;
}

From source file:org.mule.service.http.impl.functional.server.HttpServerClientTimeoutTestCase.java

@Test
public void executingRequestsFinishesOnDispose() throws Exception {
    try {/* w ww  .j a va2  s  .c  o  m*/
        Request.Get(format("http://localhost:%s/%s", port.getValue(), "test")).connectTimeout(TIMEOUT)
                .socketTimeout(TIMEOUT).execute();
        fail();
    } catch (SocketTimeoutException ste) {
        // Expected
    }
    server.stop();

    Future<?> disposeTask = newSingleThreadExecutor().submit(() -> {
        server.dispose();
        server = null;
    });

    requestLatch.countDown();
    disposeTask.get(TIMEOUT, MILLISECONDS);
    responseLatch.await(TIMEOUT, MILLISECONDS);
}

From source file:apiserver.services.images.controllers.filters.BlurController.java

/**
 * This filter blurs an uploaded image very slightly using a 3x3 blur kernel.
 * @param file/*from w  ww. j  a  v  a 2 s .  c  om*/
 * @param format
 * @return
 * @throws TimeoutException
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws IOException
 * @throws URISyntaxException
 */
@ApiOperation(value = "This filter blurs an image very slightly using a 3x3 blur kernel.")
@RequestMapping(value = "/filter/blur", method = RequestMethod.POST)
public ResponseEntity<byte[]> imageBlurByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException, URISyntaxException,
        ServletException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob job = new ImageDocumentJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    Future<Map> imageFuture = imageFilterBlurGateway.imageBlurFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.GrayscaleController.java

/**
 * This filter converts an uploaded image to a grayscale image. To do this it finds the brightness of each pixel and sets the red, green and blue of the output to the brightness value. But what is the brightness? The simplest answer might be that it is the average of the RGB components, but that neglects the way in which the human eye works. The eye is much more sensitive to green and red than it is to blue, and so we need to take less acount of the blue and more account of the green. The weighting used by GrayscaleFilter is: luma = 77R + 151G + 28B
 *
 * @param documentId/*from   ww w  .jav a 2s  .co m*/
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter converts an image to a grayscale image. To do this it finds the brightness of each pixel and sets the red, green and blue of the output to the brightness value. But what is the brightness? The simplest answer might be that it is the average of the RGB components, but that neglects the way in which the human eye works. The eye is much more sensitive to green and red than it is to blue, and so we need to take less acount of the blue and more account of the green. The weighting used by GrayscaleFilter is: luma = 77R + 151G + 28B")
@RequestMapping(value = "/filter/{documentId}/grayscale.{format}", method = { RequestMethod.GET })
public ResponseEntity<byte[]> imageGrayscaleByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob args = new ImageDocumentJob();
    args.setDocumentId(documentId);

    Future<Map> imageFuture = imageFilterGrayScaleGateway.imageGrayScaleFilter(args);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType,
            false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.MaximumController.java

/**
 * This filter blurs an uploaded image very slightly using a 3x3 blur kernel.
 *
 * @param documentId/*from   w w  w  . j  a  v  a  2  s  .  c  om*/
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter replaces each pixel by the maximum of the input pixel and its eight neighbours. Each of the RGB channels is considered separately.")
@RequestMapping(value = "/filter/{documentId}/maximum.{format}", method = { RequestMethod.GET })
@ResponseBody
public ResponseEntity<byte[]> imageMaximumByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    String _contentType = MimeType.getMimeType(format).contentType;
    if (!MimeType.getMimeType(format).isSupportedImage()) {
        return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob args = new ImageDocumentJob();
    args.setDocumentId(documentId);

    Future<Map> imageFuture = imageFilterMaximumGateway.imageMaximumFilter(args);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType,
            false);
    return result;
}