Search in sources :

Example 16 with ConcurrentAccessTimeoutException

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

the class DistributableCache method get.

@SuppressWarnings("resource")
@Override
public V get(K id) {
    Batcher<Batch> batcher = this.manager.getBatcher();
    boolean transactional = (this.tsr.getTransactionKey() != null);
    // Batch may already be associated with this tx
    Batch existingBatch = transactional ? (Batch) this.tsr.getResource(Batch.class) : null;
    try (BatchContext context = (existingBatch != null) ? batcher.resumeBatch(existingBatch) : null) {
        // Batch is not closed here - it will be closed during release(...) or discard(...)
        Batch batch = batcher.createBatch();
        try {
            // TODO WFLY-14167 Cache lookup timeout should reflect @AccessTimeout of associated bean/invocation
            Bean<K, V> bean = this.manager.findBean(id);
            if (bean == null) {
                batch.close();
                return null;
            }
            V result = bean.acquire();
            result.setCacheContext(batch);
            if (transactional && (existingBatch == null)) {
                // Leverage TSR to propagate Batch reference across calls to Cache.get(...) by different threads for the same tx
                this.tsr.putResource(Batch.class, batch);
            }
            return result;
        } catch (TimeoutException e) {
            batch.close();
            throw new ConcurrentAccessTimeoutException(e.getMessage());
        } catch (RuntimeException | Error e) {
            batch.discard();
            batch.close();
            throw e;
        }
    }
}
Also used : Batch(org.wildfly.clustering.ee.Batch) BatchContext(org.wildfly.clustering.ee.BatchContext) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with ConcurrentAccessTimeoutException

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

the class SingletonConcurrencyInheritanceTestCase method testWriteLockMethodNotOverridden.

@Test
public void testWriteLockMethodNotOverridden() throws Exception {
    final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
    ExecutorService pool = Executors.newSingleThreadExecutor();
    final CountDownLatch latch = new CountDownLatch(2);
    final CountDownLatch entered = new CountDownLatch(1);
    // call a method with a write lock
    // this will block till we hit the latch
    Future<?> future = pool.submit(new Runnable() {

        @Override
        public void run() {
            try {
                singleton.writeLock(latch, entered);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    entered.await();
    try {
        singleton.writeLock(latch, entered);
        throw new RuntimeException("Expecting a concurrency access exception");
    } catch (ConcurrentAccessTimeoutException e) {
    // expected
    }
    latch.countDown();
    future.get();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) Test(org.junit.Test)

Aggregations

ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)17 CountDownLatch (java.util.concurrent.CountDownLatch)7 Test (org.junit.Test)6 ExecutorService (java.util.concurrent.ExecutorService)5 RemoteException (java.rmi.RemoteException)3 TimeoutException (java.util.concurrent.TimeoutException)3 Lock (java.util.concurrent.locks.Lock)3 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)3 ApplicationException (org.apache.openejb.ApplicationException)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 BeanContext (org.apache.openejb.BeanContext)2 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)2 Pool (org.apache.openejb.util.Pool)2 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)2 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 FencedLock (com.hazelcast.cp.lock.FencedLock)1 InvocationInfo (com.sun.ejb.InvocationInfo)1 MethodLockInfo (com.sun.ejb.MethodLockInfo)1