Search in sources :

Example 1 with AsyncResult

use of javax.ejb.AsyncResult in project wildfly by wildfly.

the class SecuredStatelessBean method method.

@RolesAllowed("allowed")
public Future<Boolean> method() throws InterruptedException, ExecutionException {
    try {
        if (!startLatch.await(5, TimeUnit.SECONDS)) {
            throw new RuntimeException("Invocation was not asynchronous");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    SecuredStatelessLocal localSearchedBean = null;
    try {
        Context context = new InitialContext();
        localSearchedBean = (SecuredStatelessLocal) context.lookup("java:module/" + SecuredStatelessBean.class.getSimpleName() + "!" + SecuredStatelessLocal.class.getName());
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    final CountDownLatch latchLocal = new CountDownLatch(1);
    final Future<Boolean> future = localSearchedBean.localSecured(latchLocal);
    latchLocal.countDown();
    boolean result = future.get();
    Assert.assertTrue(result);
    return new AsyncResult<Boolean>(true);
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NamingException(javax.naming.NamingException) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(javax.ejb.AsyncResult) InitialContext(javax.naming.InitialContext) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 2 with AsyncResult

use of javax.ejb.AsyncResult in project wildfly by wildfly.

the class AsyncBeanRemote method futureMethod.

@Override
public Future<Boolean> futureMethod() throws InterruptedException, ExecutionException {
    AsyncBean.futureMethodCalled = false;
    final CountDownLatch latch = new CountDownLatch(1);
    final Future<Boolean> future = asyncBean.futureMethod(latch);
    latch.countDown();
    return new AsyncResult<Boolean>(future.get());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AsyncResult(javax.ejb.AsyncResult)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 AsyncResult (javax.ejb.AsyncResult)2 RolesAllowed (javax.annotation.security.RolesAllowed)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1