User: user57  
  Date: 01/06/20 17:25:54

  Modified:    src/main/org/jboss/ejb MessageDrivenContainer.java
  Log:
   o Changed MessageDrivenContainer.init() to not hide the stack of thrown
     exceptions, but logs them and rethrows.  Tidy'd up some tabs and
     changes some // comments to javadoc.
   o Changed JMSContainerInvoker to use a TransactionManager instead of a
     TxManager, since all it does it call tm.getTransaction().  This
     prevents a ClassCastException when a different TM is used (like Tyrex).
  
  Revision  Changes    Path
  1.8       +163 -148  jboss/src/main/org/jboss/ejb/MessageDrivenContainer.java
  
  Index: MessageDrivenContainer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/MessageDrivenContainer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MessageDrivenContainer.java       2001/06/18 20:01:21     1.7
  +++ MessageDrivenContainer.java       2001/06/21 00:25:54     1.8
  @@ -1,9 +1,9 @@
   /*
  -* jBoss, the OpenSource EJB server
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * jBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.ejb;
   
   import java.lang.reflect.InvocationTargetException;
  @@ -20,34 +20,41 @@
   import javax.ejb.CreateException;
   import javax.ejb.RemoveException;
   import javax.ejb.EJBException;
  -import org.jboss.logging.Logger;
   
  +import org.jboss.logging.Logger;
   
   /**
  -*   MessageDrivenContainer, based on the StatelessSessionContainer
  -*
  -*   @see <related>
  -*   @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
  -*   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  -*   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*   @author <a href="mailto:[EMAIL PROTECTED]";>Daniel OConnor</a>
  -*   @version $Revision: 1.7 $
  -*    extends StatelessSessionContainer
  -*/
  + * MessageDrivenContainer, based on the StatelessSessionContainer.
  + *
  + * @see StatelessSessionContainer
  + * 
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel OConnor</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.8 $
  + */
   public class MessageDrivenContainer
  -extends Container
  +    extends Container
       implements ContainerInvokerContainer, InstancePoolContainer
   {
  -    // These are the mappings between the remote interface methods and the bean 
methods
  +    /**
  +     * These are the mappings between the remote interface methods
  +     * and the bean methods.
  +     */
       protected Map beanMapping;
   
  -    // This is the container invoker for this container
  +    /** This is the container invoker for this container. */
       protected ContainerInvoker containerInvoker;
   
  -    // This is the instancepool that is to be used
  +    /** This is the instancepool that is to be used. */
       protected InstancePool instancePool;
   
  -    // This is the first interceptor in the chain. The last interceptor must be 
provided by the container itself
  +    /**
  +     * This is the first interceptor in the chain.
  +     * The last interceptor must be provided by the container itself.
  +     */
       protected Interceptor interceptor;
   
       // Static --------------------------------------------------------
  @@ -55,6 +62,7 @@
       // Constructors --------------------------------------------------
   
       // Public --------------------------------------------------------
  +    
       public void setContainerInvoker(ContainerInvoker ci)
       {
           if (ci == null)
  @@ -68,19 +76,19 @@
       {
           return containerInvoker;
       }
  -
  +    
       public LocalContainerInvoker getLocalContainerInvoker()
       {
  -       return localContainerInvoker;
  +        return localContainerInvoker;
       }
   
       public void setInstancePool(InstancePool ip)
       {
  -       if (ip == null)
  -        throw new IllegalArgumentException("Null pool");
  +        if (ip == null)
  +            throw new IllegalArgumentException("Null pool");
   
  -       this.instancePool = ip;
  -       ip.setContainer(this);
  +        this.instancePool = ip;
  +        ip.setContainer(this);
       }
   
       public InstancePool getInstancePool()
  @@ -90,20 +98,18 @@
   
       public void addInterceptor(Interceptor in)
       {
  -       if (interceptor == null)
  -       {
  -          interceptor = in;
  -       } else
  -       {
  -
  -          Interceptor current = interceptor;
  -          while ( current.getNext() != null)
  -          {
  -             current = current.getNext();
  -          }
  +        if (interceptor == null) {
  +            interceptor = in;
  +        }
  +        else {
  +            Interceptor current = interceptor;
   
  -          current.setNext(in);
  -       }
  +            while (current.getNext() != null) {
  +                current = current.getNext();
  +            }
  +
  +            current.setNext(in);
  +        }
       }
   
       public Interceptor getInterceptor()
  @@ -111,7 +117,8 @@
           return interceptor;
       }
   
  -    /* ContainerInvokerContainer - not needed, should we skip inherit this
  +    /**
  +     * ContainerInvokerContainer - not needed, should we skip inherit this
        * or just throw Error??
        */
       public Class getHomeClass()
  @@ -134,44 +141,43 @@
          throw new Error("LocalHomeClass not valid for MessageDriven beans");
       }
   
  -
       // Container implementation - overridden here ----------------------
  -    public void init()
  -        throws Exception
  +    
  +    public void init() throws Exception
       {
  -     try {
  -        // Associate thread with classloader
  -        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  -        Thread.currentThread().setContextClassLoader(getClassLoader());
  -
  -        // Call default init
  -        super.init();
  -
  -        // Map the bean methods
  -        setupBeanMapping();
  +        try {
  +            // Associate thread with classloader
  +            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  +            Thread.currentThread().setContextClassLoader(getClassLoader());
  +
  +            // Call default init
  +            super.init();
  +
  +            // Map the bean methods
  +            setupBeanMapping();
  +
  +            // Initialize pool
  +            instancePool.init();
  +
  +            // Init container invoker
  +            containerInvoker.init();
  +
  +            // Initialize the interceptor by calling the chain
  +            Interceptor in = interceptor;
  +            while (in != null) {
  +                in.setContainer(this);
  +                in.init();
  +                in = in.getNext();
  +            }
   
  -        // Initialize pool
  -        instancePool.init();
  -
  -        // Init container invoker
  -        containerInvoker.init();
  -
  -        // Initialize the interceptor by calling the chain
  -        Interceptor in = interceptor;
  -        while (in != null)
  -        {
  -           in.setContainer(this);
  -           in.init();
  -           in = in.getNext();
  +            // Reset classloader
  +            Thread.currentThread().setContextClassLoader(oldCl);
           }
  -
  -        // Reset classloader
  -        Thread.currentThread().setContextClassLoader(oldCl);
  -     }catch(Throwable ex) {
  -         Logger.error("Serious error in init: " + ex);
  -         //DEBUG ex.printStackTrace();
  -         throw new Exception(ex.toString());
  -     }
  +        catch (Exception e) {
  +             Logger.error("Serious error in init: " + e);
  +            Logger.exception(e);
  +            throw e;
  +        }
       }
   
       public void start()
  @@ -259,23 +265,17 @@
       public Object invokeHome(MethodInvocation mi)
           throws Exception
       {
  -     throw new Error("invokeHome not valid for MessageDriven beans");
  +        throw new Error("invokeHome not valid for MessageDriven beans");
           //return getInterceptor().invokeHome(mi);
       }
   
  -     /**
  -    *   This method does invocation interpositioning of tx and security,
  -    *   retrieves the instance from an object table, and invokes the method
  -    *   on the particular instance
  -    *
  -    * @param   id
  -    * @param   m
  -    * @param   args
  -    * @return
  -    * @exception   Exception
  -    */
  +    /**
  +     * This method does invocation interpositioning of tx and security,
  +     * retrieves the instance from an object table, and invokes the method
  +     * on the particular instance
  +     */
       public Object invoke(MethodInvocation mi)
  -    throws Exception
  +        throws Exception
       {
           // Invoke through interceptors
           return getInterceptor().invoke(mi);
  @@ -283,24 +283,25 @@
   
   
       // EJBHome implementation ----------------------------------------
  +    
       public EJBObject createHome()
           throws java.rmi.RemoteException, CreateException
       {
  -     throw new Error("createHome not valid for MessageDriven beans");
  +        throw new Error("createHome not valid for MessageDriven beans");
       }
   
   
       public void removeHome(Handle handle)
           throws java.rmi.RemoteException, RemoveException
       {
  -     throw new Error("removeHome not valid for MessageDriven beans");
  +        throw new Error("removeHome not valid for MessageDriven beans");
           // TODO
       }
   
       public void removeHome(Object primaryKey)
           throws java.rmi.RemoteException, RemoveException
       {
  -     throw new Error("removeHome not valid for MessageDriven beans");
  +        throw new Error("removeHome not valid for MessageDriven beans");
           // TODO
       }
   
  @@ -309,7 +310,7 @@
       {
           // TODO
           //return null;
  -     throw new Error("getEJBMetaDataHome not valid for MessageDriven beans");
  +        throw new Error("getEJBMetaDataHome not valid for MessageDriven beans");
       }
   
       public HomeHandle getHomeHandleHome()
  @@ -317,39 +318,42 @@
       {
           // TODO
           //return null;
  -     throw new Error("getHomeHandleHome not valid for MessageDriven beans");
  +        throw new Error("getHomeHandleHome not valid for MessageDriven beans");
       }
   
       protected void setupBeanMapping()
           throws NoSuchMethodException
       {
           Map map = new HashMap();
  -     /*
  -      * Here we should have a way of looking up wich message class
  -      * the MessageDriven bean implements, by doing this we might
  -      * be able to use other MOM systems, aka XmlBlaser. TODO!
  -      */
  -     String msgInterface = "javax.jms.MessageListener";
  -     String msgMethod = "onMessage";
  +        
  +        //
  +        // Here we should have a way of looking up wich message class
  +        // the MessageDriven bean implements, by doing this we might
  +        // be able to use other MOM systems, aka XmlBlaser. TODO!
  +        //
  +        
  +        String msgInterface = "javax.jms.MessageListener";
  +        String msgMethod = "onMessage";
           String msgArgument = "javax.jms.Message";
  -     // Get the method
  -     Class msgInterfaceClass = null;
  -     Class argumentClass = null;
  -     try {
  -         msgInterfaceClass = Class.forName(msgInterface);
  -         argumentClass = Class.forName(msgArgument);
  -     } catch(ClassNotFoundException ex) {
  -         Logger.error("Could not get the classes for message interface" + 
msgInterface);
  -         // Hackish
  -         throw new NoSuchMethodException("Could not get the classes for message 
interface" + msgInterface + ": " + ex);
  -     }
  -     Method m = msgInterfaceClass.getMethod(msgMethod, new Class[] {argumentClass});
  -     // Implemented by bean
  -     map.put(m, beanClass.getMethod(m.getName(), m.getParameterTypes()));
  -     //DEBUG Logger.debug("Mapped "+m.getName()+" "+m.hashCode()+"to "+map.get(m));
  -
  -
  -     beanMapping = map;
  +        
  +        // Get the method
  +        Class msgInterfaceClass = null;
  +        Class argumentClass = null;
  +        
  +        try {
  +            msgInterfaceClass = Class.forName(msgInterface);
  +            argumentClass = Class.forName(msgArgument);
  +        } catch (ClassNotFoundException ex) {
  +            Logger.error("Could not get the classes for message interface" + 
msgInterface);
  +            // Hackish
  +            throw new NoSuchMethodException("Could not get the classes for message 
interface" + msgInterface + ": " + ex);
  +        }
  +        
  +        Method m = msgInterfaceClass.getMethod(msgMethod, new Class[] 
{argumentClass});
  +        // Implemented by bean
  +        map.put(m, beanClass.getMethod(m.getName(), m.getParameterTypes()));
  +        //DEBUG Logger.debug("Mapped "+m.getName()+" "+m.hashCode()+"to 
"+map.get(m));
  +        beanMapping = map;
       }
   
       Interceptor createContainerInterceptor()
  @@ -359,7 +363,7 @@
   
       // This is the last step before invocation - all interceptors are done
       class ContainerInterceptor
  -    implements Interceptor
  +        implements Interceptor
       {
           public void setContainer(Container con) {}
   
  @@ -377,44 +381,55 @@
               throw new Error("invokeHome not valid for MessageDriven beans");
           }
   
  -     /*
  -      * FIXME Design problem, who will do the acknowledging for
  -      * beans with bean managed transaction?? Probably best done in the
  -      * listener "proxys"
  -      */
  +        /**
  +         * FIXME Design problem, who will do the acknowledging for
  +         * beans with bean managed transaction?? Probably best done in the
  +         * listener "proxys"
  +         */
           public Object invoke(MethodInvocation mi)
               throws Exception
           {
  -            //wire the transaction on the context, this is how the instance 
remember the tx
  -             if (mi.getEnterpriseContext().getTransaction() == null) 
mi.getEnterpriseContext().setTransaction(mi.getTransaction());
  +            // wire the transaction on the context,
  +            // this is how the instance remember the tx
  +            if (mi.getEnterpriseContext().getTransaction() == null) {
  +                mi.getEnterpriseContext().setTransaction(mi.getTransaction());
  +            }
   
               // Get method and instance to invoke upon
               Method m = (Method)beanMapping.get(mi.getMethod());
   
   
  -         // we have a method that needs to be done by a bean instance
  +            // we have a method that needs to be done by a bean instance
               {
  -             // Invoke and handle exceptions
  -             try
  -                {
  -                 return m.invoke(mi.getEnterpriseContext().getInstance(), 
mi.getArguments());
  -                } catch (IllegalAccessException e)
  -                 {
  -                     // Throw this as a bean exception...(?)
  -                     throw new EJBException(e);
  -                 } catch (InvocationTargetException e)
  -                     {
  -                         Throwable ex = e.getTargetException();
  -                         if (ex instanceof EJBException)
  -                             throw (EJBException)ex;
  -                         else if (ex instanceof RuntimeException)
  -                             throw new EJBException((Exception)ex); // Transform 
runtime exception into what a bean *should* have thrown
  -                         else if (ex instanceof Exception)
  -                             throw (Exception)ex;
  -                         else
  -                             throw (Error)ex;
  -                     }
  -         }
  +                // Invoke and handle exceptions
  +                try {
  +                 return m.invoke(mi.getEnterpriseContext().getInstance(),
  +                                    mi.getArguments());
  +                }
  +                catch (IllegalAccessException e) {
  +                    // Throw this as a bean exception...(?)
  +                    throw new EJBException(e);
  +                }
  +                catch (InvocationTargetException e) {
  +                    Throwable ex = e.getTargetException();
  +                    if (ex instanceof EJBException) {
  +                        throw (EJBException)ex;
  +                    }
  +                    else if (ex instanceof RuntimeException) {
  +                        // Transform runtime exception into what a
  +                        // bean *should* have thrown
  +                        throw new EJBException((Exception)ex);
  +                    }
  +                    else if (ex instanceof Exception) {
  +                        throw (Exception)ex;
  +                    }
  +                    else {
  +                        // TODO: this could break if a Throwable
  +                        // (not an Error) is thrown.
  +                        throw (Error)ex;
  +                    }
  +                }
  +            }
           }
       }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to