use of javax.ejb.ConcurrentAccessTimeoutException in project tomee by apache.
the class StatefulConcurrencyTest method testConcurrentMethodCall.
public void testConcurrentMethodCall() throws Exception {
MyLocalBeanImpl.semaphore = new Semaphore(0);
final InitialContext ctx = new InitialContext();
final MyLocalBean bean = (MyLocalBean) ctx.lookup("MyLocalBeanImplLocal");
final MyLocalBean bean2 = (MyLocalBean) ctx.lookup("MyLocalBeanImplLocal");
final CallRentrantThread call = new CallRentrantThread(bean, 3000);
(new Thread(call)).start();
// ensure the call on thread came in
assertTrue(MyLocalBeanImpl.semaphore.tryAcquire(1, 30, TimeUnit.SECONDS));
try {
java.util.logging.Logger.getLogger(this.getClass().getName()).info("Expecting a SEVERE javax.ejb.ConcurrentAccessTimeoutException");
bean2.callRentrant(bean, 0);
fail("Expected exception");
} catch (final Exception e) {
if (e.getCause() instanceof ConcurrentAccessTimeoutException) {
// that's what we want
} else {
throw e;
}
}
}
use of javax.ejb.ConcurrentAccessTimeoutException in project tomee by apache.
the class StatelessInstanceManagerPoolingTest method testStatelessBeanTimeout.
public void testStatelessBeanTimeout() throws Exception {
final InitialContext ctx = new InitialContext();
final Object object = ctx.lookup("CounterBeanLocal");
assertTrue("instanceof counter", object instanceof Counter);
final CountDownLatch timeouts = new CountDownLatch(10);
final CountDownLatch startPistol = new CountDownLatch(1);
final CountDownLatch startingLine = new CountDownLatch(10);
final Counter counter = (Counter) object;
// Do a business method...
final Runnable r = new Runnable() {
public void run() {
try {
counter.race(startingLine, startPistol);
} catch (final ConcurrentAccessTimeoutException ex) {
comment("Leap Start");
timeouts.countDown();
}
}
};
comment("On your mark!");
for (int i = 0; i < 20; i++) {
final Thread t = new Thread(r);
t.start();
}
// Wait for the beans to reach the start line
assertTrue("expected 10 invocations", startingLine.await(3000, TimeUnit.MILLISECONDS));
comment("Get Set!");
// Wait for the other beans timeout
assertTrue("expected 10 timeouts", timeouts.await(3000, TimeUnit.MILLISECONDS));
assertEquals(10, instances.get(), 1.1);
comment("Go!");
// go
startPistol.countDown();
}
use of javax.ejb.ConcurrentAccessTimeoutException in project tomee by apache.
the class SingletonContainer method aquireLock.
private Lock aquireLock(final boolean read, final Duration accessTimeout, final Instance instance, final Method runMethod) {
final Lock lock;
if (read) {
lock = instance.lock.readLock();
} else {
lock = instance.lock.writeLock();
}
final boolean lockAcquired;
if (accessTimeout == null || accessTimeout.getTime() < 0) {
// wait indefinitely for a lock
// noinspection LockAcquiredButNotSafelyReleased
lock.lock();
lockAcquired = true;
} else if (accessTimeout.getTime() == 0) {
// concurrent calls are not allowed, lock only once
lockAcquired = lock.tryLock();
} else {
// try to get a lock within the specified period.
try {
lockAcquired = lock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
} catch (final InterruptedException e) {
throw (ConcurrentAccessTimeoutException) new ConcurrentAccessTimeoutException("Unable to get " + (read ? "read" : "write") + " lock within specified time on '" + runMethod.getName() + "' method for: " + instance.bean.getClass().getName()).initCause(e);
}
}
// Did we acquire the lock to the current execution?
if (!lockAcquired) {
throw new ConcurrentAccessTimeoutException("Unable to get " + (read ? "read" : "write") + " lock on '" + runMethod.getName() + "' method for: " + instance.bean.getClass().getName());
}
return lock;
}
use of javax.ejb.ConcurrentAccessTimeoutException in project tomee by apache.
the class StatelessInstanceManager method getInstance.
/**
* Removes an instance from the pool and returns it for use
* by the container in business methods.
*
* If the pool is at it's limit the StrictPooling flag will
* cause this thread to wait.
*
* If StrictPooling is not enabled this method will create a
* new stateless bean instance performing all required injection
* and callbacks before returning it in a method ready state.
*
* @param callContext ThreadContext
* @return Object
* @throws OpenEJBException
*/
public Instance getInstance(final ThreadContext callContext) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Data data = (Data) beanContext.getContainerData();
Instance instance = null;
try {
final Pool<Instance>.Entry entry = data.poolPop();
if (entry != null) {
instance = entry.get();
instance.setPoolEntry(entry);
}
} catch (final TimeoutException e) {
final String msg = "No instances available in Stateless Session Bean pool. Waited " + data.accessTimeout.toString();
final ConcurrentAccessTimeoutException timeoutException = new ConcurrentAccessTimeoutException(msg);
timeoutException.fillInStackTrace();
throw new ApplicationException(timeoutException);
} catch (final InterruptedException e) {
Thread.interrupted();
throw new OpenEJBException("Unexpected Interruption of current thread: ", e);
}
if (null == instance) {
instance = createInstance(callContext, beanContext);
}
return instance;
}
use of javax.ejb.ConcurrentAccessTimeoutException in project tomee by apache.
the class MdbInstanceManager method getInstance.
/**
* Removes an instance from the pool and returns it for use
* by the container in business methods.
*
* If the pool is at it's limit the StrictPooling flag will
* cause this thread to wait.
*
* If StrictPooling is not enabled this method will create a
* new bean instance performing all required injection
* and callbacks before returning it in a method ready state.
*
* @param callContext ThreadContext
* @return Object
* @throws OpenEJBException
*/
public Instance getInstance(final ThreadContext callContext) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Data data = (Data) beanContext.getContainerData();
Instance instance = null;
try {
final Pool<Instance>.Entry entry = data.poolPop();
if (entry != null) {
instance = entry.get();
instance.setPoolEntry(entry);
}
} catch (final TimeoutException e) {
final String msg = "No instances available in Message Driven Bean pool. Waited " + data.getAccessTimeout().toString();
final ConcurrentAccessTimeoutException timeoutException = new ConcurrentAccessTimeoutException(msg);
timeoutException.fillInStackTrace();
throw new ApplicationException(timeoutException);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new OpenEJBException("Unexpected Interruption of current thread: ", e);
}
if (null == instance) {
instance = createInstance(beanContext);
}
return instance;
}
Aggregations