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.filters.MotionBlurController.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.  j a  v a 2s.  co m
 * @param angle
 * @param distance
 * @param rotation
 * @param wrapEdges
 * @param zoom
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter simulates motion blur on an image. You specify a combination of angle/distance for linear motion blur, a rotaiton angle for spin blur or a zoom factor for zoom blur. You can combine these in any proportions you want to get effects like spiral blurs.")
@RequestMapping(value = "/filter/{documentId}/motionblur.{format}", method = { RequestMethod.GET })
@ResponseBody
public ResponseEntity<byte[]> imageMotionBlurByFile(
        @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId,
        @ApiParam(name = "angle", required = true, defaultValue = "0") @RequestParam(value = "angle", required = false, defaultValue = "0") float angle,
        @ApiParam(name = "distance", required = true, defaultValue = "1") @RequestParam(value = "distance", required = false, defaultValue = "0") float distance,
        @ApiParam(name = "rotation", required = true, defaultValue = "0") @RequestParam(value = "rotation", required = false, defaultValue = "0") float rotation,
        @ApiParam(name = "wrapEdges", required = true, defaultValue = "false") @RequestParam(value = "wrapEdges", required = false, defaultValue = "false") boolean wrapEdges,
        @ApiParam(name = "zoom", required = true, defaultValue = "0") @RequestParam(value = "zoom", required = false, defaultValue = "0") float zoom,
        @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);
    }

    MotionBlurJob args = new MotionBlurJob();
    args.setDocumentId(documentId);
    args.setAngle(angle);
    args.setDistance(distance);
    args.setRotation(rotation);
    args.setWrapEdges(wrapEdges);
    args.setZoom(zoom);

    Future<Map> imageFuture = imageFilterMotionBlurGateway.imageMotionBlurFilter(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.ProtectController.java

/**
 * Secure a pdf//from w  ww.j a v a  2s  .c o  m
 * @param file
 * @param password  Owner or user password of the source PDF document, if the document is password-protected.
 * @param newUserPassword   Password used to open PDF document.
 * @param newOwnerPassword  Password used to set permissions on a PDF document
 * @param encrypt   RC4_40|RC4_128|RC4_128M|AES_128|none
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Secure a pdf with a password")
@RequestMapping(value = "/protect", method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<byte[]> protectPdf(HttpServletRequest request,
        @ApiParam(name = "file", required = true) @RequestParam(value = "file", required = true) MultipartFile file,
        @ApiParam(name = "encrypt", required = false, allowableValues = "RC4_40,RC4_128,RC4_128M,AES_128,none", value = "Encryption type for the PDF output file:", defaultValue = "RC4_128") @RequestParam(value = "encrypt", required = false) String encrypt,
        @ApiParam(name = "password", required = false, value = "Owner or user password of the source PDF document, if the document is password-protected.") @RequestParam(value = "password", required = false) String password,
        @ApiParam(name = "newUserPassword", required = true, value = "Password used to open PDF document.") @RequestParam(value = "newUserPassword", required = false) String newUserPassword,
        @ApiParam(name = "newOwnerPassword", required = true, value = "Password used to set permissions on a PDF document.") @RequestParam(value = "newOwnerPassword", required = false) String newOwnerPassword,
        @ApiParam(name = "allowAssembly", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowAssembly", required = false) Boolean allowAssembly,
        @ApiParam(name = "allowCopy", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowCopy", required = false) Boolean allowCopy,
        @ApiParam(name = "allowDegradedPrinting", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowDegradedPrinting", required = false) Boolean allowDegradedPrinting,
        @ApiParam(name = "allowFillIn", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowFillIn", required = false) Boolean allowFillIn,
        @ApiParam(name = "allowModifyAnnotations", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowModifyAnnotations", required = false) Boolean allowModifyAnnotations,
        @ApiParam(name = "allowPrinting", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowPrinting", required = false) Boolean allowPrinting,
        @ApiParam(name = "allowScreenReaders", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowScreenReaders", required = false) Boolean allowScreenReaders,
        @ApiParam(name = "allowSecure", required = false, value = "permissions on the PDF document") @RequestParam(value = "allowSecure", required = false) Boolean allowSecure)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    if (newUserPassword == null && newOwnerPassword == null) {
        throw new MessageConfigException("Missing newUserPassword or newOwnerPassword");
    }

    SecurePdfResult job = new SecurePdfResult();
    //file
    job.setFile(new Document(file));
    if (password != null)
        job.setPassword(password);
    if (newUserPassword != null)
        job.setNewUserPassword(newUserPassword);
    if (newOwnerPassword != null)
        job.setNewOwnerPassword(newOwnerPassword);
    if (encrypt != null)
        job.setEncrypt(encrypt);
    // permission
    if (allowAssembly != null)
        job.setAllowAssembly(allowAssembly);
    if (allowCopy != null)
        job.setAllowCopy(allowCopy);
    if (allowDegradedPrinting != null)
        job.setAllowDegradedPrinting(allowDegradedPrinting);
    if (allowFillIn != null)
        job.setAllowFillIn(allowFillIn);
    if (allowModifyAnnotations != null)
        job.setAllowModifyAnnotations(allowModifyAnnotations);
    if (allowPrinting != null)
        job.setAllowPrinting(allowPrinting);
    if (allowScreenReaders != null)
        job.setAllowScreenReaders(allowScreenReaders);
    if (allowSecure != null)
        job.setAllowSecure(allowSecure);

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

    byte[] fileBytes = payload.getResult();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}

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

/**
 * Remove watermark/*w  w w. ja  va2 s  .com*/
 * @param file
 * @param pages
 * @param password
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Remove Watermark")
@RequestMapping(value = "/modify/watermark", method = RequestMethod.DELETE, produces = "application/pdf")
public ResponseEntity<byte[]> removeWatermarkFromPdf(
        @ApiParam(name = "file", required = true) @RequestPart("file") MultipartFile file,
        @ApiParam(name = "pages", required = false) @RequestPart("pages") String pages,
        @ApiParam(name = "password", required = false) @RequestParam(value = "password") String password)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    WatermarkPdfJob job = new WatermarkPdfJob();
    //file
    job.setFile(new Document(file));
    if (pages != null)
        job.setPages(pages);
    if (password != null)
        job.setPassword(password);

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

    byte[] fileBytes = payload.getPdfBytes();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}

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

/**
 * Remove watermark//from   w  ww. ja va 2  s. c o  m
 * @param documentId
 * @param pages
 * @param password
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Remove Watermark")
@RequestMapping(value = "/modify/{documentId}/watermark", method = RequestMethod.DELETE, produces = "application/pdf")
public ResponseEntity<byte[]> removeWatermarkFromCachedPdf(
        @ApiParam(name = "documentId", required = true) @RequestPart("documentId") String documentId,
        @ApiParam(name = "pages", required = false) @RequestPart("pages") String pages,
        @ApiParam(name = "password", required = false) @RequestParam(value = "password") String password)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    WatermarkPdfJob job = new WatermarkPdfJob();
    //file
    job.setDocumentId(documentId);
    if (pages != null)
        job.setPages(pages);
    if (password != null)
        job.setPassword(password);

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

    byte[] fileBytes = payload.getPdfBytes();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}

From source file:com.isthari.spring.cloud.config.cassandra.CassandraEnvironmentRepository.java

private void addToEnvironment(Future<PropertySource> future, Environment environment) {
    PropertySource propertySource;//from   ww  w .ja va2s  . c o  m
    try {
        propertySource = future.get(1000, TimeUnit.MILLISECONDS);
        if (propertySource != null) {
            environment.add(propertySource);
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOGGER.error("", e);
    }
}

From source file:smpp.networking.SimpleStompClient.java

public void connect(MessageHandler handler) throws Exception {
    StompWebSocketHandler wsHandler = new StompWebSocketHandler(handler);
    /* /*from w  w w .ja va  2s .c o m*/
     *  //need to handle those big
     * tracking frames //wscfb.setMaxTextMessageBufferSize(8192*4);
     * //StandardWebSocketClient client = new
     * StandardWebSocketClient(wscfb.getObject());
     */
    client = new WebSocketClient();
    client.start();
    ClientUpgradeRequest handShakeReq = new ClientUpgradeRequest();
    handShakeReq.setHeaders(handshakeHeaders);
    //        List<HttpCookie> cookies = new ArrayList<HttpCookie>();
    //        String jsesId = handshakeHeaders.getFirst("Cookie").split("=")[1];
    //        cookies.add(new HttpCookie("JSESSIONID", jsesId));
    //        handShakeReq.setCookies(cookies);
    try {
        Future<Session> f = client.connect(wsHandler, handshakeUri, handShakeReq);
        session = f.get(CONNECT_TIMEOUT, TimeUnit.SECONDS);
        // this.session = client.doHandshake(wsHandler,
        // this.handshakeHeaders, this.handshakeUri).get();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

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

/**
 * Add Watermark//  w w  w.java2 s.com
 * @param file
 * @param image
 * @param foreground
 * @param showOnPrint
 * @param position
 * @param opacity
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Add Watermark")
@RequestMapping(value = "/modify/watermark", method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<byte[]> addWatermarkToPdf(
        @ApiParam(name = "file", required = true) @RequestPart("file") MultipartFile file,
        @ApiParam(name = "image", required = true) @RequestPart("image") MultipartFile image,
        @ApiParam(name = "foreground", required = false) @RequestParam(value = "foreground") Boolean foreground,
        @ApiParam(name = "showOnPrint", required = false) @RequestParam(value = "showOnPrint") Boolean showOnPrint,
        @ApiParam(name = "position", required = false) @RequestParam(value = "position") String position,
        @ApiParam(name = "opacity", required = false) @RequestParam(value = "opacity") Double opacity)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    WatermarkPdfJob job = new WatermarkPdfJob();
    //file
    job.setFile(new Document(file));
    if (image != null)
        job.setImage(new Document(image));
    if (foreground != null)
        job.setForeground(foreground);
    if (showOnPrint != null)
        job.setShowOnPrint(showOnPrint);
    if (position != null)
        job.setPosition(position);
    if (opacity != null)
        job.setOpacity(opacity);

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

    byte[] fileBytes = payload.getPdfBytes();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}

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

/**
 * Add Watermark to cached pdf//from  www. ja  v a 2 s  . c  om
 * @param documentId
 * @param image
 * @param foreground
 * @param showOnPrint
 * @param position
 * @param opacity
 * @return
 * @throws InterruptedException
 * @throws java.util.concurrent.ExecutionException
 * @throws java.util.concurrent.TimeoutException
 * @throws java.io.IOException
 * @throws Exception
 */
@ApiOperation(value = "Add Watermark to cached pdf")
@RequestMapping(value = "/modify/{documentId}/watermark", method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<byte[]> addWatermarkToCachedPdf(
        @ApiParam(name = "documentId", required = true) @RequestPart("documentId") String documentId,
        @ApiParam(name = "image", required = true) @RequestPart("image") MultipartFile image,
        @ApiParam(name = "foreground", required = false) @RequestParam(value = "foreground") Boolean foreground,
        @ApiParam(name = "showOnPrint", required = false) @RequestParam(value = "showOnPrint") Boolean showOnPrint,
        @ApiParam(name = "position", required = false) @RequestParam(value = "position") String position,
        @ApiParam(name = "opacity", required = false) @RequestParam(value = "opacity") Double opacity)
        throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception {
    WatermarkPdfJob job = new WatermarkPdfJob();
    //file
    job.setDocumentId(documentId);
    if (image != null)
        job.setImage(new Document(image));
    if (foreground != null)
        job.setForeground(foreground);
    if (showOnPrint != null)
        job.setShowOnPrint(showOnPrint);
    if (position != null)
        job.setPosition(position);
    if (opacity != null)
        job.setOpacity(new Double(opacity));

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

    byte[] fileBytes = payload.getPdfBytes();
    String contentType = "application/pdf";
    ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false);
    return result;
}