use of org.apache.openejb.util.Duration in project tomee by apache.
the class GeronimoConnectionManagerFactoryTest method evictionNotAllEquals.
@Test
public void evictionNotAllEquals() throws Exception {
final MyMcf mcf = new MyMcf();
final GeronimoConnectionManagerFactory factory = new GeronimoConnectionManagerFactory();
factory.setValidationInterval(new Duration("1 second"));
factory.setTransactionSupport("local");
factory.setMcf(mcf);
factory.setPooling(true);
factory.setPartitionStrategy("none");
factory.setTransactionManager(new TransactionManagerImpl());
factory.setPoolMinSize(1);
factory.setAllConnectionsEqual(false);
final GenericConnectionManager mgr = factory.create();
mgr.doStart();
try {
mgr.allocateConnection(mcf, new // just to use it
ConnectionRequestInfo() {
});
sleep(2500);
assertTrue(mcf.evicted.get());
assertTrue(mcf.destroyed.get());
} finally {
mgr.doStop();
}
}
use of org.apache.openejb.util.Duration in project tomee by apache.
the class ActiveMQResourceAdapterTest method test.
public void test() throws Exception {
final ActiveMQResourceAdapter resourceAdapter = new ActiveMQResourceAdapter();
resourceAdapter.setServerUrl("vm://localhost?waitForStart=30000&async=false");
final String brokerAddress = NetworkUtil.getLocalAddress("broker:(tcp://", ")?useJmx=false");
resourceAdapter.setBrokerXmlConfig(brokerAddress);
resourceAdapter.setStartupTimeout(new Duration(10, TimeUnit.SECONDS));
// DataSource Default Unmanaged JDBC Database
//
resourceAdapter.start(null);
}
use of org.apache.openejb.util.Duration in project tomee by apache.
the class Assembler method destroyResource.
private void destroyResource(final String name, final String className, final Object inObject) {
Object object;
try {
object = LazyResource.class.isInstance(inObject) && LazyResource.class.cast(inObject).isInitialized() ? LazyResource.class.cast(inObject).getObject() : inObject;
} catch (final NamingException e) {
// in case it impl DestroyableResource
object = inObject;
}
final Collection<Method> preDestroy = null;
if (resourceDestroyTimeout != null) {
final Duration d = new Duration(resourceDestroyTimeout);
final ExecutorService es = Executors.newSingleThreadExecutor(new DaemonThreadFactory("openejb-resource-destruction-" + name));
final Object o = object;
try {
es.submit(new Runnable() {
@Override
public void run() {
doResourceDestruction(name, className, o);
}
}).get(d.getTime(), d.getUnit());
} catch (final InterruptedException e) {
Thread.interrupted();
} catch (final ExecutionException e) {
throw RuntimeException.class.cast(e.getCause());
} catch (final TimeoutException e) {
logger.error("Can't destroy " + name + " in " + resourceDestroyTimeout + ", giving up.", e);
if (threadStackOnTimeout) {
final ThreadInfo[] dump = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false);
final ByteArrayOutputStream writer = new ByteArrayOutputStream();
final PrintStream stream = new PrintStream(writer);
for (final ThreadInfo info : dump) {
stream.println('"' + info.getThreadName() + "\" suspended=" + info.isSuspended() + " state=" + info.getThreadState());
for (final StackTraceElement traceElement : info.getStackTrace()) {
stream.println("\tat " + traceElement);
}
}
logger.info("Dump on " + name + " destruction timeout:\n" + new String(writer.toByteArray()));
}
}
} else {
doResourceDestruction(name, className, object);
}
callPreDestroy(name, object);
removeResourceInfo(name);
}
use of org.apache.openejb.util.Duration in project tomee by apache.
the class SingletonContainer method _invoke.
protected Object _invoke(final Method callMethod, final Method runMethod, final Object[] args, final Instance instance, final ThreadContext callContext, final InterfaceType callType) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Duration accessTimeout = getAccessTimeout(beanContext, runMethod);
final boolean read = javax.ejb.LockType.READ.equals(beanContext.getConcurrencyAttribute(runMethod));
final Lock lock = aquireLock(read, accessTimeout, instance, runMethod);
Object returnValue;
try {
final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, callType), callContext);
returnValue = null;
try {
if (callType == InterfaceType.SERVICE_ENDPOINT) {
callContext.setCurrentOperation(Operation.BUSINESS_WS);
returnValue = invokeWebService(args, beanContext, runMethod, instance);
} else {
final List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, callType == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS, interceptors, instance.interceptors);
returnValue = interceptorStack.invoke(args);
}
} catch (final Throwable e) {
// handle reflection exception
final ExceptionType type = beanContext.getExceptionType(e);
if (type == ExceptionType.SYSTEM) {
/* System Exception ****************************/
// The bean instance is not put into the pool via instanceManager.poolInstance
// and therefore the instance will be garbage collected and destroyed.
// For this reason the discardInstance method of the StatelessInstanceManager
// does nothing.
handleSystemException(txPolicy, e, callContext);
} else {
/* Application Exception ***********************/
handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
}
} finally {
afterInvoke(txPolicy, callContext);
}
} finally {
lock.unlock();
}
return returnValue;
}
use of org.apache.openejb.util.Duration in project tomee by apache.
the class StatelessInstanceManager method getDuration.
private Duration getDuration(final Options options, final String property, final Duration defaultValue, final TimeUnit defaultUnit) {
final String s = options.get(property, defaultValue.toString());
final Duration duration = new Duration(s);
if (duration.getUnit() == null) {
duration.setUnit(defaultUnit);
}
return duration;
}
Aggregations