javax.ejb.SessionBean Java Examples

The following examples show how to use javax.ejb.SessionBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatefulContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void afterLoad(final Instance instance) throws SystemException, ApplicationException {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(instance.beanContext, instance.primaryKey, Operation.ACTIVATE);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method remove = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbActivate") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.ACTIVATE, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();
    } catch (final Throwable callbackException) {
        discardInstance(threadContext.getPrimaryKey(), instance);
        EjbTransactionUtil.handleSystemException(threadContext.getTransactionPolicy(), callbackException, threadContext);
    } finally {
        ThreadContext.exit(oldContext);
    }
}
 
Example #2
Source File: StatefulContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeStore(final Instance instance) {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(beanContext, instance.primaryKey, Operation.PASSIVATE);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method passivate = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbPassivate") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, passivate, Operation.PASSIVATE, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();

    } catch (final Throwable e) {
        logger.error("An unexpected exception occured while invoking the ejbPassivate method on the Stateful SessionBean instance", e);
    } finally {
        ThreadContext.exit(oldContext);
    }
}
 
Example #3
Source File: StatefulContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void timedOut(final Instance instance) {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(beanContext, instance.primaryKey, Operation.PRE_DESTROY);
    threadContext.setCurrentAllowedStates(null);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method remove = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbRemove") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();
    } catch (final Throwable e) {
        logger.error("An unexpected exception occured while invoking the ejbRemove method on the timed-out Stateful SessionBean instance", e);
    } finally {
        logger.info("Removing the timed-out stateful session bean instance " + instance.primaryKey);
        ThreadContext.exit(oldContext);
    }
}
 
Example #4
Source File: ManagedContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void afterLoad(final Instance instance) throws SystemException, ApplicationException {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(instance.beanContext, instance.primaryKey, Operation.ACTIVATE);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method remove = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbActivate") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.ACTIVATE, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();
    } catch (final Throwable callbackException) {
        discardInstance(threadContext);
        EjbTransactionUtil.handleSystemException(threadContext.getTransactionPolicy(), callbackException, threadContext);
    } finally {
        ThreadContext.exit(oldContext);
    }
}
 
Example #5
Source File: ManagedContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeStore(final Instance instance) {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(beanContext, instance.primaryKey, Operation.PASSIVATE);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method passivate = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbPassivate") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, passivate, Operation.PASSIVATE, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();

    } catch (final Throwable e) {
        logger.error("An unexpected exception occured while invoking the ejbPassivate method on the Stateful SessionBean instance", e);
    } finally {
        ThreadContext.exit(oldContext);
    }
}
 
Example #6
Source File: ManagedContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void timedOut(final Instance instance) {
    final BeanContext beanContext = instance.beanContext;

    final ThreadContext threadContext = new ThreadContext(beanContext, instance.primaryKey, Operation.PRE_DESTROY);
    threadContext.setCurrentAllowedStates(null);
    final ThreadContext oldContext = ThreadContext.enter(threadContext);
    try {
        final Method remove = instance.bean instanceof SessionBean ? SessionBean.class.getMethod("ejbRemove") : null;

        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);

        interceptorStack.invoke();
    } catch (final Throwable e) {
        logger.error("An unexpected exception occured while invoking the ejbRemove method on the timed-out Stateful SessionBean instance", e);
    } finally {
        logger.info("Removing the timed-out stateful session bean instance " + instance.primaryKey);
        ThreadContext.exit(oldContext);
    }
}