Search in sources :

Example 1 with Duration

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();
    }
}
Also used : GenericConnectionManager(org.apache.geronimo.connector.outbound.GenericConnectionManager) TransactionManagerImpl(org.apache.geronimo.transaction.manager.TransactionManagerImpl) Duration(org.apache.openejb.util.Duration) Test(org.junit.Test)

Example 2 with Duration

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);
}
Also used : Duration(org.apache.openejb.util.Duration)

Example 3 with Duration

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);
}
Also used : PrintStream(java.io.PrintStream) DaemonThreadFactory(org.apache.openejb.util.DaemonThreadFactory) Duration(org.apache.openejb.util.Duration) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ThreadInfo(java.lang.management.ThreadInfo) ExecutorService(java.util.concurrent.ExecutorService) NamingException(javax.naming.NamingException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Duration

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;
}
Also used : BeanContext(org.apache.openejb.BeanContext) ExceptionType(org.apache.openejb.core.ExceptionType) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) Duration(org.apache.openejb.util.Duration) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) Lock(java.util.concurrent.locks.Lock)

Example 5 with Duration

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;
}
Also used : Duration(org.apache.openejb.util.Duration)

Aggregations

Duration (org.apache.openejb.util.Duration)20 HashMap (java.util.HashMap)6 Map (java.util.Map)5 File (java.io.File)4 NamingException (javax.naming.NamingException)4 OpenEJBException (org.apache.openejb.OpenEJBException)4 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 Properties (java.util.Properties)3 InitialContext (javax.naming.InitialContext)3 BeanContext (org.apache.openejb.BeanContext)3 Calculator (org.apache.openejb.itest.failover.ejb.Calculator)3 StandaloneServer (org.apache.openejb.server.control.StandaloneServer)3 PrintStream (java.io.PrintStream)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 TimeoutException (java.util.concurrent.TimeoutException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2