FileDocCategorySizeDatePackage
StatefulInstanceInterceptor.javaAPI DocJBoss 4.2.14414Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.stateful

StatefulInstanceInterceptor

public class StatefulInstanceInterceptor extends Object implements org.jboss.aop.advice.Interceptor
Comment
author
Bill Burke
version
$Revision: 57207 $

Fields Summary
Constructors Summary
public StatefulInstanceInterceptor()

   
Methods Summary
public java.lang.StringgetName()

      return null;
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
      Object id = ejb.getId();
      StatefulContainer container = (StatefulContainer) ejb.getAdvisor();
      StatefulBeanContext target = container.getCache().get(id);

      boolean block = container.resolveAnnotation(SerializedConcurrentAccess.class) != null;

      if (block)
      {
         target.getLock().lockInterruptibly();
      }
      else
      {
         synchronized (target)
         {
            if (target.isInInvocation()) throw new ConcurrentAccessException("no concurrent calls on stateful bean '" + container.getName() + "' (EJB3 4.3.13)");
            target.setInInvocation(true);
         }
      }
      ejb.setTargetObject(target.getInstance());
      ejb.setBeanContext(target);
      StatefulBeanContext.currentBean.push(target);
      try
      {
         if (target.isDiscarded()) throw new EJBException("SFSB was discarded by another thread");
         return ejb.invokeNext();
      }
      catch (Exception ex)
      {
         if (isApplicationException(ex.getClass(), container)) throw ex;
         if (ex instanceof RuntimeException
                 || ex instanceof RemoteException)
         {
            container.getCache().remove(id);
            target.setDiscarded(true);
         }
         throw ex;
      }
      finally
      {
         StatefulBeanContext.currentBean.pop();
         synchronized (target)
         {
            target.setInInvocation(false);
            if (!target.isTxSynchronized() && !target.isDiscarded()) container.getCache().finished(target);
            if (block) target.getLock().unlock();
         }
      }
   
public static booleanisApplicationException(java.lang.Class exceptionClass, org.jboss.ejb3.EJBContainer container)

      if (exceptionClass.isAnnotationPresent(ApplicationException.class))
         return true;
      
      AssemblyDescriptor assembly = container.getAssemblyDescriptor();
      if (assembly != null)
      {
         List exceptions = assembly.getApplicationExceptions();
         if (exceptions.size() > 0)
         {
            Iterator exceptionIterator = exceptions.iterator();
            while (exceptionIterator.hasNext())
            {
               org.jboss.ejb3.metamodel.ApplicationException exception = (org.jboss.ejb3.metamodel.ApplicationException)exceptionIterator.next();
               if (exception.getExceptionClass().equals(exceptionClass.getName()))
                  return true;
            }
         }
         
      }
      return false;