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;
}
}
}
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();
}
Aggregations