FileDocCategorySizeDatePackage
StatelessContainer.javaAPI DocJBoss 4.2.113919Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.stateless

StatelessContainer

public class StatelessContainer extends org.jboss.ejb3.SessionContainer implements org.jboss.ejb3.timerservice.TimedObjectInvoker
Comment
author
Bill Burke
version
$Revision: 61280 $

Fields Summary
private static final Logger
log
protected javax.ejb.TimerService
timerService
Constructors Summary
public StatelessContainer(ClassLoader cl, String beanClassName, String ejbName, org.jboss.aop.AspectManager manager, Hashtable ctxProperties, org.jboss.ejb3.interceptor.InterceptorInfoRepository interceptorRepository, org.jboss.ejb3.Ejb3Deployment deployment)


           
                                
                              
   
      super(cl, beanClassName, ejbName, manager, ctxProperties, interceptorRepository, deployment);
      beanContextClass = StatelessBeanContext.class;
   
Methods Summary
public voidcallTimeout(javax.ejb.Timer timer)

      Method timeout = callbackHandler.getTimeoutCallback();
      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
      Object[] args = {timer};
      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
      try
      {
         AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsFlags.IN_EJB_TIMEOUT);
         try
         {
            MethodInfo info = (MethodInfo) methodInterceptors.get(callbackHandler.getTimeoutCalllbackHash());
            EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info);
            nextInvocation.setAdvisor(this);
            nextInvocation.setArguments(args);
            nextInvocation.invokeNext();
         }
         catch (Throwable throwable)
         {
            if (throwable instanceof Exception) throw (Exception) throwable;
            throw new RuntimeException(throwable);
         }
         finally
         {
            AllowedOperationsAssociation.popInMethodFlag();
         }
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldLoader);
      }
   
public java.lang.ObjectcreateLocalProxy(java.lang.Object id)

      StatelessLocalProxyFactory factory = new StatelessLocalProxyFactory();
      factory.setContainer(this);
      factory.init();

      Object proxy = factory.createProxy();

      return proxy;
   
public java.lang.ObjectcreateRemoteProxy(java.lang.Object id)

      RemoteBinding binding = null;

      RemoteBindings bindings = (RemoteBindings) resolveAnnotation(RemoteBindings.class);
      if (bindings != null)
         binding = bindings.value()[0];
      else
         binding = (RemoteBinding) resolveAnnotation(RemoteBinding.class);

      StatelessRemoteProxyFactory factory = new StatelessRemoteProxyFactory();
      factory.setContainer(this);
      factory.setRemoteBinding(binding);
      factory.init();

      return factory.createProxy();
   
public java.lang.ObjectcreateSession(java.lang.Class[] initTypes, java.lang.Object[] initArgs)

      if((initTypes != null && initTypes.length > 0) || (initArgs != null && initArgs.length > 0))
         throw new IllegalArgumentException("stateless bean create method must take no arguments (EJB3 4.5)");
      // a stateless bean has no sessions
      // TODO: pool stuff
      return null;
   
public org.jboss.aop.joinpoint.InvocationResponsedynamicInvoke(java.lang.Object target, org.jboss.aop.joinpoint.Invocation invocation)

      long start = System.currentTimeMillis();
      
      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
      try
      {
         Thread.currentThread().setContextClassLoader(classloader);
         MethodInvocation si = (MethodInvocation) invocation;
         MethodInfo info = (MethodInfo) methodInterceptors.get(si.getMethodHash());
         if (info == null)
         {
            throw new RuntimeException("Could not resolve beanClass method from proxy call");
         }

         Method unadvisedMethod = info.getUnadvisedMethod();
         try
         {
            invokeStats.callIn();
            
            invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
            Map responseContext = null;
            Object rtn = null;
            if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
            {
               rtn = invokeHomeMethod(info, si);
            }
            else if (info != null && unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
            {
               rtn = invokeEJBObjectMethod(info, si);
            }
            else
            {

               EJBContainerInvocation newSi = null;

               newSi = new EJBContainerInvocation(info);
               newSi.setArguments(si.getArguments());
               newSi.setMetaData(si.getMetaData());
               newSi.setAdvisor(this);
               try
               {
                  rtn = newSi.invokeNext();
                  responseContext = newSi.getResponseContextInfo();
               }
               catch (Throwable throwable)
               {
                  responseContext = newSi.getResponseContextInfo();
                  return marshallException(invocation, throwable, responseContext);
               }
            }

            InvocationResponse response = marshallResponse(invocation, rtn, responseContext);
            return response;
         }
         finally
         {
            if (unadvisedMethod != null)
            {
               long end = System.currentTimeMillis();
               long elapsed = end - start;
               invokeStats.updateStats(unadvisedMethod, elapsed);
            }
            
            invokeStats.callOut();
            
            invokedMethod.pop();
         }
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldLoader);
      }

   
public java.lang.ObjectgetBusinessObject(org.jboss.ejb3.BeanContext ctx, java.lang.Class intf)

      try
      {
         String jndiName = ProxyFactoryHelper.getJndiName(this, intf);
         if (jndiName == null) throw new IllegalStateException("Cannot find BusinessObject for interface: " + intf.getName());
         return getInitialContext().lookup(ProxyFactoryHelper.getJndiName(this, intf));
      }
      catch (NamingException e)
      {
         throw new RuntimeException("failed to invoke getBusinessObject", e);
      }
   
public javax.ejb.TimerServicegetTimerService()

      return timerService;
   
public javax.ejb.TimerServicegetTimerService(java.lang.Object pKey)

      assert timerService != null : "Timer Service not yet initialized";
      return timerService;
   
protected java.lang.ObjectinvokeEJBObjectMethod(org.jboss.aop.MethodInfo info, org.jboss.aop.joinpoint.MethodInvocation invocation)

      Method unadvisedMethod = info.getUnadvisedMethod();
      if (unadvisedMethod.getName().equals("getHandle"))
      {
         StatelessHandleImpl handle = null;
         RemoteBinding remoteBindingAnnotation = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
         if (remoteBindingAnnotation != null)
            handle = new StatelessHandleImpl(remoteBindingAnnotation.jndiBinding());

         return handle;
      }
      else if (unadvisedMethod.getName().equals("remove"))
      {
         return null;
      }
      else if (unadvisedMethod.getName().equals("getEJBHome"))
      {
         HomeHandleImpl homeHandle = null;

         RemoteBinding remoteBindingAnnotation = (RemoteBinding) resolveAnnotation(RemoteBinding.class);
         if (remoteBindingAnnotation != null)
            homeHandle = new HomeHandleImpl(ProxyFactoryHelper.getHomeJndiName(this));

         return homeHandle.getEJBHome();
      }
      else if (unadvisedMethod.getName().equals("getPrimaryKey"))
      {
         return null;
      }
      else if (unadvisedMethod.getName().equals("isIdentical"))
      {
         return false;
      }
      else
      {
         return null;
      }
   
protected java.lang.ObjectinvokeHomeMethod(org.jboss.aop.MethodInfo info, org.jboss.aop.joinpoint.MethodInvocation invocation)

      Method unadvisedMethod = info.getUnadvisedMethod();
      if (unadvisedMethod.getName().equals("create"))
      {
         return createRemoteProxy(null);
      }
      else // remove
      {
         return null;
      }
   
private java.lang.ObjectinvokeLocalHomeMethod(org.jboss.aop.MethodInfo info, java.lang.Object[] args)

      Method unadvisedMethod = info.getUnadvisedMethod();
      if (unadvisedMethod.getName().equals("create"))
      {
         return createLocalProxy(null);
      }
      else // remove
      {
         return null;
      }
   
public java.lang.ObjectlocalInvoke(java.lang.reflect.Method method, java.lang.Object[] args, org.jboss.aspects.asynch.FutureHolder provider, org.jboss.ejb3.BeanContextLifecycleCallback callback)

      long start = System.currentTimeMillis();
      
      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
      try
      {
         MethodInfo info = getMethodInfo(method);
         Method unadvisedMethod = info.getUnadvisedMethod();

         try
         {
            invokeStats.callIn();
            
            invokedMethod.push(new InvokedMethod(true, unadvisedMethod));

            if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
            {
               return invokeLocalHomeMethod(info, args);
            }

            EJBContainerInvocation<StatelessContainer, StatelessBeanContext> nextInvocation = new EJBContainerInvocation<StatelessContainer, StatelessBeanContext>(info);
            nextInvocation.setAdvisor(this);
            nextInvocation.setArguments(args);
            nextInvocation.setContextCallback(callback);

            ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
            return nextInvocation.invokeNext();
         }
         finally
         {
            if (unadvisedMethod != null)
            {
               long end = System.currentTimeMillis();
               long elapsed = end - start;
               invokeStats.updateStats(unadvisedMethod, elapsed);
            }
            
            invokeStats.callOut();
            
            invokedMethod.pop();
         }
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldLoader);
      }
   
public java.lang.ObjectlocalInvoke(java.lang.reflect.Method method, java.lang.Object[] args)
Performs a synchronous local invocation

      return localInvoke(method, args, null);
   
public java.lang.ObjectlocalInvoke(java.lang.reflect.Method method, java.lang.Object[] args, org.jboss.aspects.asynch.FutureHolder provider)
Performs a synchronous or asynchronous local invocation

param
provider If null a synchronous invocation, otherwise an asynchronous

      return localInvoke(method, args, provider, null);
   
protected voidremoveHandle(javax.ejb.Handle handle)

      throw new RuntimeException("NYI");
   
public voidstart()

      try
      {
         super.start();
         
         timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
         
         TimerServiceFactory.getInstance().restoreTimerService(timerService);
      }
      catch (Exception e)
      {
         try
         {
            stop();
         }
         catch (Exception ignore)
         {
            log.debug("Failed to cleanup after start() failure", ignore);
         }
         throw e;
      }
   
public voidstop()

      if (timerService != null)
      {
         TimerServiceFactory.getInstance().removeTimerService(timerService);
         timerService = null;
      }
      
      super.stop();