List of usage examples for javax.ejb AsyncResult AsyncResult
public AsyncResult(V result)
AsyncResult
instance to wrap the result of an asynchronous method call From source file:ips1ap101.ejb.core.mail.MailerBean.java
@Asynchronous @Override//from w ww .j a va 2 s.c o m public Future<Object> sendMessageAsynchronously(String addressList, String subject, String text) { try { Object message = sendMessage(addressList, subject, text); return new AsyncResult<>(message); } catch (Exception ex) { logger.fatal(ex.getMessage(), ex); Object message = ex; return new AsyncResult<>(message); } }
From source file:dk.dma.msinm.common.audit.AuditService.java
/** * Asynchronous method for logging a new audit entry * * @param level the audit level/* www .j a va 2s .c o m*/ * @param module the module * @param message the message * @param exception optionally, an exception */ @Asynchronous public Future<AuditEntry> log(AuditEntry.Level level, String module, String message, Throwable exception) { AuditEntry entry = new AuditEntry(); entry.setCreated(DateTime.now(DateTimeZone.UTC)); entry.setMessage(StringUtils.abbreviate(message, 200)); entry.setModule(module); entry.setLevel(level); if (exception != null) { StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); entry.setStackTrace(StringUtils.abbreviate(sw.toString(), 4000)); } AuditEntry result = saveEntity(entry); log.debug("Saved a new audit log " + result); return new AsyncResult<>(result); }
From source file:com.dnastack.bob.service.parser.impl.JsonExistsResponseParser.java
@Asynchronous @Override// w ww. j a v a 2s . com public synchronized Future<Boolean> parseQueryResponse(Beacon b, Future<String> response) { Boolean res = null; try { res = parseUtils.parseBooleanFromJson(response.get(REQUEST_TIMEOUT, TimeUnit.SECONDS), "exists"); } catch (InterruptedException | ExecutionException | JSONException | TimeoutException ex) { // ignore } return new AsyncResult<>(res); }
From source file:com.dnastack.bob.service.parser.impl.JsonResponseResponseParser.java
@Asynchronous @Override//from w ww . j a v a2 s . c o m public synchronized Future<Boolean> parseQueryResponse(Beacon b, Future<String> response) { Boolean res = null; try { res = parseUtils.parseYesNoFromJson(response.get(REQUEST_TIMEOUT, TimeUnit.SECONDS), "response"); } catch (InterruptedException | ExecutionException | JSONException | TimeoutException ex) { // ignore } return new AsyncResult<>(res); }
From source file:com.dnastack.bob.service.processor.impl.BeaconizerBeaconProcessor.java
@Override @Asynchronous//from w ww . j a v a2 s. c om public Future<String> getQueryResponse(Beacon beacon, Query query) { String res = null; // should be POST, but the server accepts GET as well try { HttpRequestBase request = createRequest(getQueryUrl(beacon.getId(), query.getChromosome().toString(), query.getPosition(), query.getAllele()), false, null); request.setHeader("Accept", "application/json"); res = executeRequest(request); } catch (MalformedURLException | UnsupportedEncodingException ex) { // ignore, already null } return new AsyncResult<>(res); }
From source file:com.dnastack.bob.service.processor.impl.BeaconizerBeaconProcessor.java
@Override @Asynchronous/*from ww w . j a v a2 s. c o m*/ public Future<Boolean> parseQueryResponse(Beacon b, String response) { Boolean res = parseBooleanFromJson(response, "exists"); return new AsyncResult<>(res); }
From source file:com.dnastack.bob.service.processor.impl.AmpLabBeaconProcessor.java
@Override @Asynchronous//from www.j ava 2s. c om public Future<String> getQueryResponse(Beacon beacon, Query query) { String res = null; try { res = executeRequest(createRequest(BASE_URL, true, getQueryData(query.getReference().toString(), denormalizeChromosome(CHROM_TEMPLATE, query.getChromosome()), query.getPosition(), denormalizeAllele(query.getAllele())))); } catch (UnsupportedEncodingException ex) { // ignore, already null } return new AsyncResult<>(res); }
From source file:com.dnastack.bob.service.processor.impl.AmpLabBeaconProcessor.java
@Override @Asynchronous// www. ja v a2 s .co m public Future<Boolean> parseQueryResponse(Beacon b, String response) { Boolean res = parseContainsStringCaseInsensitive(response, "beacon found", "beacon cannot find"); return new AsyncResult<>(res); }
From source file:pl.psnc.synat.wrdz.zmkd.plan.DeliveryPlanProcessorBean.java
@Override @Asynchronous// w w w .j a v a 2 s .c om @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Future<Void> process(String planId) { DeliveryPlan plan = planDao.findById(planId); if (plan == null) { logger.error("No such plan: " + planId); return new AsyncResult<Void>(null); } planManager.changeStatus(planId, DeliveryPlanStatus.RUNNING); String objectIdentifier = plan.getObjectIdentifier(); HttpClient client = httpsClientHelper.getHttpsClient(WrdzModule.ZMKD); HttpGet get = new HttpGet(zmkdConfiguration.getZmdObjectUrl(objectIdentifier)); HttpResponse response = null; File digitalObjectFile; File workDir; try { planExecutor.setWait(planId, objectIdentifier); response = client.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_ACCEPTED) { planExecutor.confirmWait(planId); return new AsyncResult<Void>(null); } planExecutor.clearWait(planId); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error("Unexpected response: " + response.getStatusLine()); return new AsyncResult<Void>(null); } workDir = new File(zmkdConfiguration.getWorkingDirectory(uuidGenerator.generateCacheFolderName())); workDir.mkdir(); digitalObjectFile = httpsClientHelper.storeResponseEntity(workDir, response.getEntity(), response.getFirstHeader("Content-Disposition")); ZipUtility.unzip(digitalObjectFile, workDir); } catch (IOException e) { planExecutor.clearWait(planId); planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error(e.getMessage(), e); return new AsyncResult<Void>(null); } finally { if (response != null) { EntityUtils.consumeQuietly(response.getEntity()); } } DigitalObjectInfo objectInfo = reader.parseMets(workDir, METS_PATH); String clientLocation = null; try { for (ConversionPath conversion : plan.getConversionPaths()) { List<TransformationInfo> path = planExecutionParser.parseTransformationPath(conversion); planExecutionManager.transform(objectInfo, path); } } catch (InconsistentServiceDescriptionException e) { planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error(e.getMessage(), e); return new AsyncResult<Void>(null); } catch (TransformationException e) { planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error(e.getMessage(), e); return new AsyncResult<Void>(null); } try { DeliveryInfo deliveryInfo = planExecutionParser.parseDelivery(plan.getDelivery()); clientLocation = planExecutionManager.deliver(objectInfo, deliveryInfo); } catch (InconsistentServiceDescriptionException e) { planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error(e.getMessage(), e); return new AsyncResult<Void>(null); } catch (DeliveryException e) { planManager.changeStatus(planId, DeliveryPlanStatus.ERROR); logger.error(e.getMessage(), e); return new AsyncResult<Void>(null); } planManager.completePlan(planId, clientLocation); return new AsyncResult<Void>(null); }
From source file:org.hawkular.component.pinger.Pinger.java
/** * Performs a test request against the given {@link PingDestination}. * * @param destination the destination to ping * @return a {@link Future}//from w ww .j av a2 s . com */ @Asynchronous public Future<PingStatus> ping(final PingDestination destination) { Log.LOG.debugf("About to ping %s", destination.getUrl()); HttpUriRequest request = RequestBuilder.create(destination.getMethod()).setUri(destination.getUrl()) .build(); try (CloseableHttpClient client = getHttpClient(destination.getUrl())) { long start = System.currentTimeMillis(); HttpResponse httpResponse = client.execute(request); StatusLine statusLine = httpResponse.getStatusLine(); EntityUtils.consumeQuietly(httpResponse.getEntity()); long now = System.currentTimeMillis(); final int code = statusLine.getStatusCode(); final int duration = (int) (now - start); Traits traits = Traits.collect(httpResponse, now); PingStatus result = new PingStatus(destination, code, now, duration, traits); Log.LOG.debugf("Got status code %d from %s", code, destination.getUrl()); return new AsyncResult<>(result); } catch (UnknownHostException e) { PingStatus result = PingStatus.error(destination, 404, System.currentTimeMillis()); Log.LOG.debugf("Got UnknownHostException for %s", destination.getUrl()); return new AsyncResult<>(result); } catch (IOException e) { Log.LOG.dCouldNotPingUrl(destination.getUrl(), e.getMessage()); PingStatus result = PingStatus.error(destination, 500, System.currentTimeMillis()); return new AsyncResult<>(result); } }