List of usage examples for java.util.concurrent Future get
V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
From source file:apiserver.services.images.controllers.filters.MinimumController.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/* w w w .j a v a 2s . c o m*/ * @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 minimum of the input pixel and its eight neighbours. Each of the RGB channels is considered separately.") @RequestMapping(value = "/filter/{documentId}/minimum.{format}", method = { RequestMethod.GET }) @ResponseBody public ResponseEntity<byte[]> imageMinimumByFile( @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 = imageFilterMinimumGateway.imageMinimumFilter(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.service.HtmlToPdfCFService.java
public Object execute(Message<?> message) throws ColdFusionException { Html2PdfResult props = (Html2PdfResult) message.getPayload(); try {// w ww . ja v a 2s .c om long startTime = System.nanoTime(); Grid grid = verifyGridConnection(); // Get grid-enabled executor service for nodes where attribute 'worker' is defined. ExecutorService exec = getColdFusionExecutor(); Future<ByteArrayResult> future = exec.submit(new HtmlToPdfCallable(props.getHtml(), props.getHeaderHtml(), props.getFooterHtml(), props.getOptions())); ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS); props.setResult(_result.getBytes()); long endTime = System.nanoTime(); log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total=" + (endTime - startTime) + "ms"); return props; } catch (Exception ge) { throw new RuntimeException(ge); } }
From source file:com.cisco.surf.jenkins.plugins.jenkow.tests.ManualTrigger.ActualTest.java
public void testManualTriggerSuccess() throws Exception { setNumExecutors(10);/* w ww.j a v a2 s .c o m*/ FreeStyleProject one = createFreeStyleProject("one"); one.getBuildersList().add(new Shell("echo \"one running\"; sleep 5; exit 0")); FreeStyleProject two = createFreeStyleProject("two"); two.getBuildersList().add(new Shell("echo \"two running\"; sleep 8; exit 0")); FreeStyleProject launcher = createFreeStyleProject("launcher"); DescribableList<Builder, Descriptor<Builder>> bl = launcher.getBuildersList(); bl.add(new JenkowBuilder(getWfName("workflow"))); bl.add(new Shell("echo wf.done")); Future<FreeStyleBuild> launcherBF = launcher.scheduleBuild2(0); Thread.sleep(5000); one.scheduleBuild2(0); two.scheduleBuild2(0); FreeStyleBuild build = launcherBF.get(30, TimeUnit.SECONDS); System.out.println(build.getDisplayName() + " completed"); String s = FileUtils.readFileToString(build.getLogFile()); assertTrue(s.contains("+ echo wf.done")); }
From source file:apiserver.services.images.controllers.filters.DespeckleController.java
/** * This filter reduces light noise in an image using the eight hull algorithm described in Applied Optics, Vol. 24, No. 10, 15 May 1985, "Geometric filter for Speckle Reduction", by Thomas R Crimmins. Basically, it tries to move each pixel closer in value to its neighbours. As it only has a small effect, you may need to apply it several times. This is good for removing small levels of noise from an image but does give the image some fuzziness. * * @param documentId/*from w w w . jav a2s . com*/ * @param format * @return * @throws java.util.concurrent.TimeoutException * @throws java.util.concurrent.ExecutionException * @throws InterruptedException * @throws java.io.IOException */ @ApiOperation(value = "This filter reduces light noise in an image using the eight hull algorithm described in Applied Optics, Vol. 24, No. 10, 15 May 1985, \"Geometric filter for Speckle Reduction\", by Thomas R Crimmins. Basically, it tries to move each pixel closer in value to its neighbours. As it only has a small effect, you may need to apply it several times. This is good for removing small levels of noise from an image but does give the image some fuzziness.") @RequestMapping(value = "/filter/{documentId}/despeckle.{format}", method = { RequestMethod.GET }) public ResponseEntity<byte[]> imageDespeckleByFile( @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 = imageFilterDespeckleGateway.imageDespeckleFilter(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.manipulations.ResizeController.java
/** * Resize an image//from ww w. j ava 2s .c om * * @param documentId * @param interpolation - highestQuality,highQuality,mediumQuality,highestPerformance,highPerformance,mediumPerformance,nearest,bilinear,bicubic,bessel,blackman,hamming,hanning,hermite,lanczos,mitchell,quadratic * @param width * @param height * @return */ @ApiOperation(value = "Resize an uploaded image") @RequestMapping(value = "/modify/{documentId}/resize.{format}", method = { RequestMethod.GET }) @ResponseBody public ResponseEntity<byte[]> resizeImageByImage( @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId, @ApiParam(name = "width", required = true, defaultValue = "200") @RequestParam(required = true) Integer width, @ApiParam(name = "height", required = true, defaultValue = "200") @RequestParam(required = true) Integer height, @ApiParam(name = "interpolation", required = false, defaultValue = "bicubic") @RequestParam(required = false, defaultValue = "bicubic") String interpolation, @ApiParam(name = "scaleToFit", required = false, defaultValue = "false") @RequestParam(required = false, defaultValue = "false") Boolean scaleToFit, @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format ) throws IOException, InterruptedException, ExecutionException, TimeoutException { String _contentType = MimeType.getMimeType(format).contentType; if (!MimeType.getMimeType(format).isSupportedImage()) { return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } FileResizeJob job = new FileResizeJob(); job.setDocumentId(documentId); job.setWidth(width); job.setHeight(height); job.setInterpolation(interpolation.toUpperCase()); job.setScaleToFit(scaleToFit); Future<Map> imageFuture = imageResizeGateway.resizeImage(job); FileResizeJob payload = (FileResizeJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); //pass CF Response back to the client return payload.getHttpResponse(); }
From source file:apiserver.services.cache.controllers.CacheDocumentController.java
/** * put document into cache, usable for future manipulations APIs * * @param uploadedFile uploaded file/*from w w w . j a v a 2 s .co m*/ * @param tags list of metadata tags * @return cache ID */ //@ApiOperation(value = "add a document to cache", multiValueResponse = true) @RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public WebAsyncTask<String> addDocument( @ApiParam(name = "uploadedFile", required = true) @RequestParam(value = "uploadedFile", required = true) MultipartFile uploadedFile, @ApiParam(name = "tags", required = false) @RequestParam(required = false) String[] tags) throws InterruptedException, TimeoutException, ExecutionException { final MultipartFile _file = uploadedFile; final String[] _tags = tags; Callable<String> callable = new Callable<String>() { @Override public String call() throws Exception { UploadDocumentJob job = new UploadDocumentJob(_file); job.setTags(_tags); Future<DocumentJob> imageFuture = documentAddGateway.addDocument(job); DocumentJob payload = imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); return payload.getDocument().getId(); } }; return new WebAsyncTask<String>(10000, callable); }
From source file:apiserver.services.images.controllers.manipulations.BorderController.java
/** * Draw a border around an image/*from www .j a va 2s . com*/ * * @param file * @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/border", method = { RequestMethod.POST }) public ResponseEntity<byte[]> drawBorderByImage(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file, @ApiParam(name = "color", required = true) @RequestParam(required = true) String color, @ApiParam(name = "thickness", required = true) @RequestParam(required = true) Integer thickness, @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format ) throws InterruptedException, ExecutionException, TimeoutException, IOException { 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); } FileBorderJob job = new FileBorderJob(); job.setDocumentId(null); job.setDocument(_file); job.setColor(color); job.setThickness(thickness); job.setFormat(format); Future<Map> imageFuture = imageDrawBorderGateway.imageDrawBorderFilter(job); 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 file/*from w ww .j a va2s .c o m*/ * @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/median", method = { RequestMethod.POST }) @ResponseBody public ResponseEntity<byte[]> imageMedianByFile(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 { 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(new Document(file)); Future<Map> imageFuture = imageFilterMedianGateway.imageMedianFilter(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.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 file//from ww w. j a v a2 s . c o m * @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/glow", method = { RequestMethod.POST }) public ResponseEntity<byte[]> imageGlowByFile(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file, @ApiParam(name = "amount", required = true, defaultValue = "2") @RequestParam(required = false, defaultValue = "2") int amount, @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format ) throws TimeoutException, ExecutionException, InterruptedException, IOException { 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); } GlowJob job = new GlowJob(); job.setDocumentId(null); job.setDocument(new Document(file)); job.setAmount(amount); Future<Map> imageFuture = imageFilterGlowGateway.imageGlowFilter(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.pdf.controllers.FormController.java
/** * Populate the pdf form fields/* www . j a v a 2s . co m*/ * @param file * @param xfdf XML * @return * @throws InterruptedException * @throws java.util.concurrent.ExecutionException * @throws java.util.concurrent.TimeoutException * @throws java.io.IOException * @throws Exception */ @ApiOperation(value = "Populate the pdf form fields") @RequestMapping(value = "/form/populate", method = RequestMethod.POST, produces = "application/pdf") public ResponseEntity<byte[]> populateFormFields( @ApiParam(name = "file", required = true) @RequestPart("file") MultipartFile file, @ApiParam(name = "XFDF", required = true) @RequestPart("XFDF") String xfdf, @ApiParam(name = "password", required = false) @RequestPart("password") String password) throws InterruptedException, ExecutionException, TimeoutException, IOException, Exception { PopulatePdfFormJob job = new PopulatePdfFormJob(); job.setFile(new Document(file)); job.setXFDF(xfdf); if (password != null) job.setPassword(password); Future<Map> future = gateway.populatePdfForm(job); PopulatePdfFormJob payload = (PopulatePdfFormJob) future.get(defaultTimeout, TimeUnit.MILLISECONDS); byte[] fileBytes = payload.getPdfBytes(); String contentType = "application/pdf"; ResponseEntity<byte[]> result = ResponseEntityHelper.processFile(fileBytes, contentType, false); return result; }