Java 类javax.ejb.SessionBean 实例源码
项目:tomee
文件:StatefulContainer.java
@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);
}
}
项目:tomee
文件:StatefulContainer.java
@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);
}
}
项目:tomee
文件:StatefulContainer.java
@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);
}
}
项目:tomee
文件:ManagedContainer.java
@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);
}
}
项目:tomee
文件:ManagedContainer.java
@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);
}
}
项目:tomee
文件:ManagedContainer.java
@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);
}
}
项目:ROAD
文件:UserBean.java
public void logout()
{
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.invalidateSession();
ec.redirect(Utlities.getContextRoot() + "/login/");
} catch (IOException e) {
Logger.getLogger(SessionBean.class.getName()).log(Level.SEVERE, null, e);
}
}
项目:ROAD
文件:UserBean.java
public void logout()
{
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.invalidateSession();
ec.redirect(Utilities.getContextRoot() + "/login/");
} catch (IOException e) {
Logger.getLogger(SessionBean.class.getName()).log(Level.SEVERE, null, e);
}
}
项目:ROAD
文件:UserBean.java
/**
* Logout a user, then redirect to the login page.
*/
public void logout()
{
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.invalidateSession();
ec.redirect(Utilities.getContextRoot() + "/login/");
} catch (IOException e) {
Logger.getLogger(SessionBean.class.getName()).log(Level.SEVERE, null, e);
}
}
项目:tomee
文件:SingletonInstanceManager.java
private Instance createInstance(final ThreadContext callContext, final BeanContext beanContext) throws ApplicationException {
try {
initializeDependencies(beanContext);
final InstanceContext context = beanContext.newInstance();
if (context.getBean() instanceof SessionBean) {
final Operation originalOperation = callContext.getCurrentOperation();
try {
callContext.setCurrentOperation(Operation.CREATE);
final Method create = beanContext.getCreateMethod();
final InterceptorStack ejbCreate = new InterceptorStack(context.getBean(), create, Operation.CREATE, new ArrayList<InterceptorData>(), new HashMap());
ejbCreate.invoke();
} finally {
callContext.setCurrentOperation(originalOperation);
}
}
final ReadWriteLock lock;
if (beanContext.isBeanManagedConcurrency()) {
// Bean-Managed Concurrency
lock = new BeanManagedLock();
} else {
// Container-Managed Concurrency
lock = new ReentrantReadWriteLock();
}
return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext(), lock);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final String t = "The bean instance " + beanContext.getDeploymentID() + " threw a system exception:" + e;
logger.error(t, e);
throw new ApplicationException(new NoSuchEJBException("Singleton failed to initialize").initCause(e));
}
}