Java 类javax.ejb.AsyncResult 实例源码

项目:eplmp    文件:ImporterBean.java   
@Override
@Asynchronous
@FileImport
public Future<ImportResult> importIntoPathData(String workspaceId, File file, String originalFileName, String revisionNote, boolean autoFreezeAfterUpdate, boolean permissiveUpdate) {
    PathDataImporter selectedImporter = selectPathDataImporter(file);
    Locale userLocale = getUserLocale(workspaceId);
    Properties properties = PropertiesLoader.loadLocalizedProperties(userLocale, I18N_CONF, ImporterBean.class);

    PathDataImporterResult pathDataImporterResult;

    if (selectedImporter != null) {
        pathDataImporterResult = selectedImporter.importFile(getUserLocale(workspaceId), workspaceId, file, autoFreezeAfterUpdate, permissiveUpdate);
    } else {
        List<String> errors = getNoImporterAvailableError(properties);
        pathDataImporterResult = new PathDataImporterResult(file, new ArrayList<>(), errors, null, null, null);
    }

    ImportResult result = doPathDataImport(properties, workspaceId, revisionNote, autoFreezeAfterUpdate, permissiveUpdate, pathDataImporterResult);

    return new AsyncResult<>(result);
}
项目:darceo    文件:PluginExecutor.java   
/**
 * Executes the plugin with the given name. Internal use only.
 * 
 * @param pluginName
 *            plugin name
 * @return execution status
 */
@Asynchronous
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Future<Void> execute(String pluginName) {

    PluginExecutor proxy = ctx.getBusinessObject(PluginExecutor.class);

    boolean finished = false;
    while (!ctx.wasCancelCalled() && !finished) {
        finished = !proxy.executeOnce(pluginName);
        if (finished) {
            proxy.finishCycle(pluginName);
        }

    }

    return new AsyncResult<Void>(null);
}
项目:asw    文件:AsynchronousHelloImpl.java   
/** Un'operazione asincrona (che puo' essere interrotta). */
@Asynchronous
public Future<String> hello(String name) throws HelloException, InterruptedException {
    String result = null;
    logger.info("AsynchronousHello.hello(" + name + ") called");

    if (name==null) {
        throw new HelloException("Invalid parameters for hello()");
    }

    /* diciamo che questa operazione perde un po' di tempo e
     * poi restituisce proprio il saluto desiderato */
    for (int i=0; i<name.length()*10; i++) {
        sleep(40);
        if (ctx.wasCancelCalled()) {
            logger.info("AsynchronousHello.hello(" + name + ") was cancelled");
            /* credo che la cosa giusta da fare qui sia sollevare un'eccezione */
            throw new InterruptedException("Operation AsynchronousHello.hello(" + name + ") was cancelled");
        }
    }
    result = "Hello, " + name.toUpperCase() + "!";
    logger.info("AsynchronousHello.hello(" + name + ") ==> " + result);
    return new AsyncResult<String>(result);
}
项目:darceo    文件:FileFormatProcessorBean.java   
@Override
@Asynchronous
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Future<Void> processAll() {
    logger.info("Format processing started");

    FileFormatProcessor proxy = ctx.getBusinessObject(FileFormatProcessor.class);

    int count = 0;
    boolean finished = false;

    while (!ctx.wasCancelCalled() && !finished) {
        boolean processed = proxy.processOne();
        if (processed) {
            count++;
        }
        finished = !processed;
    }

    logger.info("Format processing stopped: checked {} format(s)", count);

    return new AsyncResult<Void>(null);
}
项目:training    文件:ParalellizerWorker.java   
@Asynchronous // SOLUTION
    //public Integer executeWorkItem(String workItem) { // INITIAL
    public Future<Integer> executeWorkItem(String workItem) { // SOLUTION
        int result = workItem.length();
        System.out.println("Worker " + workerId + ": Start processing item '" + workItem + "'");

        System.out.println("Worker " + workerId + ": " + Thread.currentThread().getName());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Worker " + workerId + ": Item '" + workItem + "' done.");

        return new AsyncResult<Integer>(result); // SOLUTION
//      return result; // INITIAL
    }
项目:aerogear-unifiedpush-server    文件:HealthServiceImpl.java   
@Asynchronous
@Override
public Future<HealthDetails> dbStatus() {
    HealthDetails details = new HealthDetails();
    details.setDescription("Database connection");
    details.start();
    try {
        healthDao.dbCheck();
        details.setTestStatus(Status.OK);
        details.setResult("connected");
    } catch (Exception e) {
        details.setTestStatus(Status.CRIT);
        details.setResult(e.getMessage());
    }
    details.stop();
    return new AsyncResult<>(details);
}
项目:aerogear-unifiedpush-server    文件:HealthNetworkServiceImpl.java   
@Asynchronous
@Override
public Future<List<HealthDetails>> networkStatus() {
    final List<HealthDetails> results = new ArrayList<>(PUSH_NETWORKS.size());

    PUSH_NETWORKS.forEach(pushNetwork -> {
        HealthDetails details = new HealthDetails();
        details.start();
        details.setDescription(pushNetwork.getName());
        if (Ping.isReachable(pushNetwork.getHost(), pushNetwork.getPort())) {
            details.setTestStatus(Status.OK);
            details.setResult("online");
        } else {
            details.setResult(String.format("Network not reachable '%s'", pushNetwork.getName()));
            details.setTestStatus(Status.WARN);
        }

        results.add(details);
        details.stop();
    });

    return new AsyncResult<>(results);
}
项目:jee-architecture-domain    文件:ChefServiceImpl.java   
@Override
@Asynchronous
@Transactional
public Future<ResponseChefEvent> createChef(final CreateChefEvent event) {

    final ChefEntity chefEntity = this.chefMapper.map(event.getChef(), CreateChefGroup.class);

    this.chefRepository.insert(chefEntity);

    return new AsyncResult<>(ResponseChefEvent.builder().chef(this.chefMapper.map(chefEntity)).build());
}
项目:jee-architecture-domain    文件:ChefServiceImpl.java   
@Override
@Asynchronous
@Transactional
public Future<ResponseChefEvent> getChef(final RequestChefEvent event) {

    final ChefEntity chefEntity = this.chefRepository.findOne(event.getId());

    return new AsyncResult<>(ResponseChefEvent.builder().chef(this.chefMapper.map(chefEntity)).build());
}
项目:jee-architecture-domain    文件:ChefServiceImpl.java   
@Override
@Asynchronous
@Transactional
public Future<CatalogChefEvent> getChefs(final RequestAllChefEvent event) {

    final List<ChefEntity> chefEntities = this.chefRepository.findAll(event.getPage() - 1, event.getLimit());
    final long total = this.chefRepository.count();

    return new AsyncResult<>(CatalogChefEvent.builder()
            .chefs(this.chefMapper.mapListReverse(chefEntities)).total(total).build());
}
项目:jee-architecture-domain    文件:ChefServiceImpl.java   
@Override
@Asynchronous
@Transactional
public Future<ResponseChefEvent> updateChef(final UpdateChefEvent event) {

    final ChefEntity chefEntity = this.chefMapper.map(event.getChef(), UpdateChefGroup.class);

    this.chefRepository.update(chefEntity);

    return new AsyncResult<>(ResponseChefEvent.builder().chef(this.chefMapper.map(chefEntity)).build());
}
项目:jee-architecture-domain    文件:GenericMapper.java   
default Future<F> map(final Future<T> from) {
    return Optional.of(from).map(f -> {
        try {
            return new AsyncResult<>(this.map(f.get()));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }).orElse(null);
}
项目:jee-architecture-domain    文件:GenericMapper.java   
default Future<List<T>> mapList(final Future<List<F>> from) {
    return Optional.of(from).map(f -> {
        try {
            return new AsyncResult<>(this.mapList(f.get()));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }).orElse(null);
}
项目:jee-architecture-domain    文件:GenericMapper.java   
default Future<List<F>> mapListReverse(final Future<List<T>> from) {
    return Optional.of(from).map(f -> {
        try {
            return new AsyncResult<>(this.mapListReverse(f.get()));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }).orElse(null);
}
项目:Peking-University-Open-Research-Data-Platform    文件:IndexAllServiceBean.java   
@Asynchronous
public Future<JsonObjectBuilder> indexAllOrSubset(long numPartitions, long partitionId, boolean skipIndexed, boolean previewOnly) {
    JsonObjectBuilder response = Json.createObjectBuilder();
    Future<String> responseFromIndexAllOrSubset = indexAllOrSubset(numPartitions, partitionId, skipIndexed);
    String status = "indexAllOrSubset has begun";
    response.add("responseFromIndexAllOrSubset", status);
    return new AsyncResult<>(response);
}
项目:Peking-University-Open-Research-Data-Platform    文件:SolrIndexServiceBean.java   
@Asynchronous
public Future<String> indexMissing() {
    StringBuilder status = new StringBuilder();
    List<Dataverse> stateOrMissingDataverses = indexService.findStaleOrMissingDataverses();
    int countOfIndexedDataverses = 0;
    for (Dataverse staleOrMissingDataverse : stateOrMissingDataverses) {
        Future<String> response = indexService.indexDataverseInNewTransaction(staleOrMissingDataverse);
        countOfIndexedDataverses++;
    }
    status.append("indexed dataverses: " + countOfIndexedDataverses + ", ");
    List<Dataset> staleOrMissingDatasets = indexService.findStaleOrMissingDatasets();
    int countOfIndexedDatasets = 0;
    for (Dataset staleOrMissingDataset : staleOrMissingDatasets) {
        indexService.indexDatasetInNewTransaction(staleOrMissingDataset);
        countOfIndexedDatasets++;
    }
    status.append("indexed datasets: " + countOfIndexedDatasets + ", ");
    int countOfIndexedPermissions = 0;
    List<Long> dvObjectsWithStaleOrMissingPermissions = findPermissionsInDatabaseButStaleInOrMissingFromSolr();
    for (long dvObjectId : dvObjectsWithStaleOrMissingPermissions) {
        indexPermissionsForOneDvObject(dvObjectId);
        countOfIndexedPermissions++;
    }
    status.append("indexed permissions (DvObject IDs): " + countOfIndexedPermissions);
    logger.info(status.toString());
    return new AsyncResult<>(status.toString());
}
项目:ejb3.1-certification    文件:MessageProcessor.java   
@Asynchronous
public Future<String> executeHardWorkAndSendResponse() {
    try {
        System.out.println("Executing hard work");
        Thread.sleep(5000);
        System.out.println("Ending hard work");
    } catch (InterruptedException ex) {
        Logger.getLogger(MessageProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return new AsyncResult<>("OK");
}
项目:darceo    文件:IntegrityProcessorBean.java   
@Override
@Asynchronous
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Future<Void> processAll() {

    if (waitingForIdentifier != null) {
        logger.warn("Processing started, but processor is waiting for an object. This can cause synchronization problems.");
    }

    IntegrityProcessor proxy = ctx.getBusinessObject(IntegrityProcessor.class);

    boolean finished = false;

    while (!ctx.wasCancelCalled() && !finished) {
        IntegrityProcessingResult result = proxy.processOne();
        switch (result) {
            case PROCESSED:
                finished = false;
                break;
            case PAUSED:
                finished = true;
                break;
            case FINISHED:
                finished = true;
                proxy.finishCycle();
                break;
            default:
                throw new WrdzRuntimeException("Unexpected result: " + result);
        }
    }

    return new AsyncResult<Void>(null);
}
项目:packt-java-ee-7-code-samples    文件:TheatreBooker.java   
@Asynchronous
@Override
public Future<String> bookSeatAsync(int seatId) {
    try {
        Thread.sleep(10000);
        bookSeat(seatId);
        return new AsyncResult<>("Booked seat: " + seatId + ". Money left: " + money);
    } catch (NoSuchSeatException | SeatBookedException | NotEnoughMoneyException | InterruptedException e) {
        return new AsyncResult<>(e.getMessage());
    }
}
项目:packt-java-ee-7-code-samples    文件:TheatreBooker.java   
@Asynchronous
@Override
public Future<String> bookSeatAsync(int seatId) {
    try {
        Thread.sleep(10000);
        bookSeat(seatId);
        return new AsyncResult<>("Booked seat: " + seatId + ". Money left: " + money);
    } catch (NoSuchSeatException | SeatBookedException | NotEnoughMoneyException | InterruptedException e) {
        return new AsyncResult<>(e.getMessage());
    }
}
项目:sinkit-core    文件:CacheBuilderEJB.java   
@Asynchronous
@Override
public Future<Integer> runCacheRebuilding() throws ConcurrentAccessException {

    if (!cacheRebuilding.compareAndSet(false, true)) {
        log.info("Cache rebuilding still in process -> skipping");
        throw new ConcurrentAccessException("Cache rebuilding already in progress...");
    }

    try {
        return new AsyncResult<>(this.rebuildCache());
    } finally {
        cacheRebuilding.set(false);
    }
}
项目:chuidiang-ejemplos    文件:TheSlowWork.java   
@Asynchronous
public Future<Integer> add(int a, int b){
   LOG.info("Adding!");

   try {
      Thread.sleep(Math.round(Math.random()*1500));
   } catch (InterruptedException e) {

   }
   LOG.info("Added!");
   return new AsyncResult<Integer>(a+b);
}
项目:JavaIncrementalParser    文件:MyAsyncBeanClassLevel.java   
public Future<Integer> addNumbers(int n1, int n2) {
    try {
        // simulating a long running query
        Thread.sleep(AWAIT);
    } catch (InterruptedException ex) {
        Logger.getLogger(MyAsyncBeanClassLevel.class.getName()).log(Level.SEVERE, null, ex);
    }
    return new AsyncResult(n1 + n2);
}
项目:JavaIncrementalParser    文件:MyAsyncBeanMethodLevel.java   
@Asynchronous
public Future<Integer> addNumbers(int n1, int n2) {
    try {
        // simulating a long running query
        Thread.sleep(AWAIT);
    } catch (InterruptedException ex) {
        Logger.getLogger(MyAsyncBeanMethodLevel.class.getName()).log(Level.SEVERE, null, ex);
    }
    return new AsyncResult(n1 + n2);
}
项目:java-course-ee    文件:AsyncEJB.java   
@Asynchronous
public Future<String> sayHello() {
    try {
        log.debug("Start sayHello method");
        for (int i = 0; i < 10; i++) {
            Thread.sleep(1000);
            log.debug("Still sleeping");
        }
    } catch (InterruptedException ex) {
    }
    log.debug("Return result");
    return new AsyncResult<String>("përshëndetje");
}
项目:oracle-samples    文件:MailerBean.java   
@Asynchronous
public Future<String> sendMessage(String email) {
    String status;
    try {
        Message message = new MimeMessage(session);
        message.setFrom();
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(email, false));
        message.setSubject("Test message from async example");
        message.setHeader("X-Mailer", "JavaMail");
        DateFormat dateFormatter = DateFormat
                .getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
        Date timeStamp = new Date();
        String messageBody = "This is a test message from the async example "
                + "of the Java EE Tutorial. It was sent on "
                + dateFormatter.format(timeStamp)
                + ".";
        message.setText(messageBody);
        message.setSentDate(timeStamp);
        Transport.send(message);
        status = "Sent";
        logger.log(Level.INFO, "Mail sent to {0}", email);
    } catch (MessagingException ex) {
        logger.severe("Error in sending message.");
        status = "Encountered an error: " + ex.getMessage();
        logger.severe(ex.getMessage());
    }
    return new AsyncResult<>(status);
}
项目:tomee    文件:JobProcessor.java   
@Asynchronous
@Lock(READ)
@AccessTimeout(-1)
public Future<String> addJob(String jobName) {

    // Pretend this job takes a while
    doSomeHeavyLifting();

    // Return our result
    return new AsyncResult<String>(jobName);
}
项目:tomee    文件:AsynchInRoleTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("testB");
}
项目:tomee    文件:AsynchInRoleTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("testB");
}
项目:tomee    文件:AsynchInRoleTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    Assert.assertFalse(sessionContext.wasCancelCalled());
    try {
        Thread.sleep(3000L);
    } catch (final InterruptedException e) {
        //Ignore
    }
    Assert.assertTrue(sessionContext.wasCancelCalled());
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("echoB");
}
项目:tomee    文件:AsynchTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("testB");
}
项目:tomee    文件:AsynchTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("testB");
}
项目:tomee    文件:AsynchTest.java   
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
    Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
    Assert.assertFalse(sessionContext.wasCancelCalled());
    try {
        Thread.sleep(3000L);
    } catch (final InterruptedException e) {
        //Ignore
    }
    Assert.assertTrue(sessionContext.wasCancelCalled());
    lastInvokeMethod = "testB";
    return new AsyncResult<String>("echoB");
}
项目:eap-6.1-quickstarts    文件:AsynchronousAccessBean.java   
@Asynchronous
@Override
public Future<String> longerRunning(long sleepTime) {
    LOGGER.info("Will wait for " + sleepTime + "ms");
    try {
        Thread.sleep(sleepTime);
    } catch (InterruptedException e) {
    }
    LOGGER.info("returning the result");
    return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
项目:eap-6.1-quickstarts    文件:AsynchronousAccessBean.java   
@Override
public Future<String> interfaceAsync(long sleepTime) {
    LOGGER.info("Will wait for " + sleepTime + "ms");
    try {
        Thread.sleep(sleepTime);
    } catch (InterruptedException e) {
    }
    LOGGER.info("returning the result");
    return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
项目:jboss-as-quickstart    文件:AsynchronousAccessBean.java   
@Asynchronous
@Override
public Future<String> longerRunning(long sleepTime) {
    LOGGER.info("Will wait for " + sleepTime + "ms");
    try {
        Thread.sleep(sleepTime);
    } catch (InterruptedException e) {
    }
    LOGGER.info("returning the result");
    return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
项目:jboss-as-quickstart    文件:AsynchronousAccessBean.java   
@Override
public Future<String> interfaceAsync(long sleepTime) {
    LOGGER.info("Will wait for " + sleepTime + "ms");
    try {
        Thread.sleep(sleepTime);
    } catch (InterruptedException e) {
    }
    LOGGER.info("returning the result");
    return new AsyncResult<String>("returning at " + new Date() + ", duration was " + sleepTime + "ms");
}
项目:IBE-Secure-Message    文件:IdentityDescriptionBeanImpl.java   
@Override
    public Future<IdentityDescriptionEntity> changeEncryptionKey(Integer id, String oldKey, String newKey) {
        IdentityDescriptionEntity mod = find(IdentityDescriptionEntity.class, id);

        IdentityDescription data = mod.getIdentityDescription(oldKey.getBytes());
//      data.setCryptionKeyAndIV(keyIV);
        mod.setIdentityDescription(data, newKey.getBytes());
//      mod.setIdentityDescription(data);

        IdentityDescriptionEntity newId = (IdentityDescriptionEntity) update(mod);
        Future<IdentityDescriptionEntity> description = new AsyncResult<IdentityDescriptionEntity>(newId);
//      MemoryUtil.fastSecureBuffers(keyIV0, key0, iv0, keyIV, key, iv);
        return description;
    }
项目:Mastering-Java-EE-Development-with-WildFly    文件:AsyncBean.java   
public Future<Integer> longProcessing(int a, int b) {
    logger.info("the calling thread will waith when the Future.get is excuted");
    return new AsyncResult<Integer>(a * b);
}
项目:training    文件:AsyncEJB.java   
@Asynchronous
public Future<Integer> asyncMethodWithResult() {
    waitSomeTime();
    int response = (int) (Math.random() * 100);
    return new AsyncResult<Integer>(response);
}