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.manipulations.RotateController.java
/** * rotate an image/*from ww w .ja v a2 s . co m*/ * * @param documentId * @param angle * @return */ @ApiOperation(value = "Rotate an uploaded image") @RequestMapping(value = "/modify/{documentId}/rotate.{format}", method = { RequestMethod.GET }) @ResponseBody public ResponseEntity<byte[]> rotateImageByImage( @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId, @ApiParam(name = "angle", required = true, defaultValue = "90") @RequestParam(required = true, defaultValue = "90") Integer angle, @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); } FileRotateJob job = new FileRotateJob(); job.setDocumentId(documentId); job.setAngle(angle); Future<Map> imageFuture = imageRotateGateway.rotateImage(job); FileRotateJob payload = (FileRotateJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType, false); return result; }
From source file:net.urlgrey.mythpodcaster.transcode.FFMpegTranscoderImpl.java
public void transcode(File workingDirectory, GenericTranscoderConfigurationItem genericConfig, File inputFile, File outputFile) throws Exception { LOG.info("transcode started: inputFile [" + inputFile.getAbsolutePath() + "], outputFile [" + outputFile.getAbsolutePath() + "]"); FFMpegTranscoderConfigurationItem config = (FFMpegTranscoderConfigurationItem) genericConfig; List<String> commandList = new ArrayList<String>(); commandList.add(niceLocation);//from ww w . ja va 2 s . c om commandList.add("-n"); commandList.add(Integer.toString(config.getNiceness())); commandList.add(ffmpegLocation); commandList.add("-i"); commandList.add(inputFile.getAbsolutePath()); commandList.addAll(config.getParsedEncoderArguments()); commandList.add(outputFile.getAbsolutePath()); ProcessBuilder pb = new ProcessBuilder(commandList); // Needed for ffmpeg pb.environment().put("LD_LIBRARY_PATH", "/usr/local/lib:"); pb.redirectErrorStream(true); pb.directory(workingDirectory); Process process = null; try { // Get the ffmpeg process process = pb.start(); // We give a couple of secs to complete task if needed Future<List<String>> stdout = pool.submit(new OutputMonitor(process.getInputStream())); List<String> result = stdout.get(config.getTimeout(), TimeUnit.SECONDS); process.waitFor(); final int exitValue = process.exitValue(); LOG.info("FFMPEG exit value: " + exitValue); if (exitValue != 0) { for (String line : result) { LOG.error(line); } throw new Exception("FFMpeg return code indicated failure: " + exitValue); } } catch (InterruptedException e) { throw new Exception("FFMpeg process interrupted by another thread", e); } catch (ExecutionException ee) { throw new Exception("Something went wrong parsing FFMpeg output", ee); } catch (TimeoutException te) { // We could not get the result before timeout throw new Exception("FFMpeg process timed out", te); } catch (RuntimeException re) { // Unexpected output from FFMpeg throw new Exception("Something went wrong parsing FFMpeg output", re); } finally { if (process != null) { process.destroy(); } } LOG.debug("transcoding finished"); }
From source file:com.flipkart.poseidon.serviceclients.FutureTaskResultToDomainObjectPromiseWrapper.java
@Override public void await(long timeout, TimeUnit timeUnit) throws InterruptedException { try {//from ww w .ja va2s. c o m for (Future<TaskResult> future : futureList) { future.get(timeout, timeUnit); } } catch (ExecutionException exception) { promiseBrokenException = new PromiseBrokenException(exception); throw new InterruptedException(exception.getMessage()); } catch (CancellationException exception) { promiseBrokenException = new PromiseBrokenException(exception); } catch (TimeoutException ignored) { } }
From source file:net.urlgrey.mythpodcaster.transcode.SegmentedVodTranscoderImpl.java
public void transcode(File workingDirectory, GenericTranscoderConfigurationItem genericConfig, File inputFile, File outputFile) throws Exception { LOG.info("transcode started: inputFile [" + inputFile.getAbsolutePath() + "], outputFile [" + outputFile.getAbsolutePath() + "]"); SegmenterTranscoderConfigurationItem config = (SegmenterTranscoderConfigurationItem) genericConfig; List<String> commandList = new ArrayList<String>(); commandList.add(niceLocation);// w w w . ja v a2s. c o m commandList.add("-n"); commandList.add(Integer.toString(config.getNiceness())); commandList.add(segmenterLocation); commandList.add(inputFile.getAbsolutePath()); commandList.add(config.getSegmentDuration()); commandList.add(config.getSegmentFilePrefix()); commandList.add(config.getPlaylistFileName()); commandList.add(config.getHttpPrefix()); ProcessBuilder pb = new ProcessBuilder(commandList); pb.environment().put("LD_LIBRARY_PATH", "/usr/local/lib:"); pb.redirectErrorStream(true); pb.directory(outputFile.getParentFile()); Process process = null; try { // Get the segmenter process process = pb.start(); // We give a couple of secs to complete task if needed Future<List<String>> stdout = pool.submit(new OutputMonitor(process.getInputStream())); List<String> result = stdout.get(config.getTimeout(), TimeUnit.SECONDS); process.waitFor(); final int exitValue = process.exitValue(); LOG.info("Segmenter exit value: " + exitValue); if (exitValue != 0) { for (String line : result) { LOG.error(line); } throw new Exception("Segmenter return code indicated failure: " + exitValue); } } catch (InterruptedException e) { throw new Exception("Segmenter process interrupted by another thread", e); } catch (ExecutionException ee) { throw new Exception("Something went wrong parsing Segmenter output", ee); } catch (TimeoutException te) { // We could not get the result before timeout throw new Exception("Segmenter process timed out", te); } catch (RuntimeException re) { // Unexpected output from Segmenter throw new Exception("Something went wrong parsing Segmenter output", re); } finally { if (process != null) { process.destroy(); } } LOG.debug("transcoding finished"); }
From source file:apiserver.services.cache.controllers.CacheDocumentController.java
/** * pull document out of cache/*w w w . j a v a 2 s.c o m*/ * * @param documentId id of document in the persistence/cache layer * @return byte[] array of cached file */ @ResponseBody @ApiOperation(value = "get a document out of cache") @RequestMapping(value = "/{documentId}", method = { RequestMethod.GET }) public ResponseEntity<byte[]> getImage( @ApiParam(name = "documentId", required = true, defaultValue = "a3c8af38-82e3-4241-8162-28e17ebcbf52") @PathVariable(value = "documentId") String documentId) throws InterruptedException, TimeoutException, ExecutionException, IOException { GetDocumentJob args = new GetDocumentJob(); args.setDocumentId(documentId); Future<DocumentJob> imageFuture = documentGetGateway.getDocument(args); DocumentJob payload = imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); return ResponseEntityHelper.processFile(payload.getDocument().getFileBytes(), payload.getDocument().getContentType().name(), false); }
From source file:apiserver.services.pdf.controllers.FormController.java
/** * Populate the pdf form fields/*from w w w . j a v a 2s.co m*/ * @param documentId * @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/{documentId}/populate", method = RequestMethod.POST, produces = "application/pdf") public ResponseEntity<byte[]> populateCachedFormFields( @ApiParam(name = "documentId", required = true) @RequestPart("documentId") String documentId, @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.setDocumentId(documentId); job.setXFDF(xfdf); if (password != null) job.setPassword(password); Future<Map> future = gateway.populatePdfForm(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.images.controllers.filters.BlurController.java
/** * This filter blurs an uploaded image very slightly using a 3x3 blur kernel. * * @param documentId/*from www . ja va 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 blurs an image very slightly using a 3x3 blur kernel.") @RequestMapping(value = "/filter/{documentId}/blur.{format}", method = RequestMethod.GET) public ResponseEntity<byte[]> imageBlurById( @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, URISyntaxException { String _contentType = MimeType.getMimeType(format).contentType; if (!MimeType.getMimeType(format).isSupportedImage()) { return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } ImageDocumentJob job = new ImageDocumentJob(); job.setDocumentId(documentId); Future<Map> imageFuture = imageFilterBlurGateway.imageBlurFilter(job); ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType, false); return result; }
From source file:com.mirth.connect.connectors.ws.WebServiceConnectorService.java
private WsdlInterface getWsdlInterface(URI wsdlUrl, String username, String password) throws Exception { /* add the username:password to the URL if using authentication */ if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { String hostWithCredentials = username + ":" + password + "@" + wsdlUrl.getHost(); wsdlUrl = new URI(wsdlUrl.getScheme(), hostWithCredentials, wsdlUrl.getPath(), wsdlUrl.getQuery(), wsdlUrl.getFragment());//from w w w. j a va 2 s . co m } // SoapUI.setSoapUICore(new EmbeddedSoapUICore()); WsdlProject wsdlProject = new WsdlProjectFactory().createNew(); WsdlLoader wsdlLoader = new UrlWsdlLoader(wsdlUrl.toURL().toString()); try { Future<WsdlInterface> future = importWsdlInterface(wsdlProject, wsdlUrl, wsdlLoader); return future.get(30, TimeUnit.SECONDS); } catch (Exception e) { wsdlLoader.abort(); throw e; } }
From source file:org.activiti.extension.cache.MemcachedManager.java
/** * Set, ??updateTimeout, ?false??.// w w w. j a v a 2 s .c om */ @ManagedOperation(description = "Set, ??updateTimeout, ?false??.") @ManagedOperationParameters({ @ManagedOperationParameter(name = "key", description = "key"), @ManagedOperationParameter(name = "expiration", description = "expiration"), @ManagedOperationParameter(name = "value", description = "value") }) public boolean safeSet(String key, int expiration, Object value) { Future<Boolean> future = memcachedClient.set(key, expiration, value); try { return future.get(updateTimeout, TimeUnit.MILLISECONDS); } catch (Exception e) { future.cancel(false); } return false; }
From source file:apiserver.services.images.controllers.manipulations.RotateController.java
/** * rotate an image/*from w w w .j av a2s .c o m*/ * * @param file * @param angle * @return */ @ApiOperation(value = "Rotate an uploaded image") @RequestMapping(value = "/modify/rotate", method = { RequestMethod.POST }) @ResponseBody public ResponseEntity<byte[]> rotateImageByImage(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = true) @RequestParam(value = "file", required = false) MultipartFile file, @ApiParam(name = "angle", required = true, defaultValue = "90") @RequestParam(required = true, defaultValue = "90") Integer angle, @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format ) throws IOException, InterruptedException, ExecutionException, TimeoutException { 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); } FileRotateJob job = new FileRotateJob(); job.setDocumentId(null); job.setDocument(_file); //job.getDocument().setContentType( MimeType.getMimeType(file.getContentType()) ); //job.getDocument().setFileName(file.getOriginalFilename()); job.setAngle(angle); job.setFormat(format); Future<Map> imageFuture = imageRotateGateway.rotateImage(job); FileRotateJob payload = (FileRotateJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); //pass CF Response back to the client return payload.getHttpResponse(); }