[jboss-cvs] jboss-ejb3/src/main/org/jboss/ejb3/mdb ...

Bill DeCoste bdecoste at jboss.com
Mon Jul 24 17:28:28 EDT 2006


  User: bdecoste
  Date: 06/07/24 17:28:28

  Modified:    src/main/org/jboss/ejb3/mdb        MDB.java
                        MessagingContainer.java ConsumerContainer.java
  Removed:     src/main/org/jboss/ejb3/mdb        MDBConfig.java
                        MessageDrivenConfigProperties.java
                        MessageInflowLocalProxy.java DLQHandler.java
  Log:
  MDB cleanup, standalone test for standard testcases, fixed class level @Resources jndi env bindings
  
  Revision  Changes    Path
  1.45      +1 -2      jboss-ejb3/src/main/org/jboss/ejb3/mdb/MDB.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MDB.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-ejb3/src/main/org/jboss/ejb3/mdb/MDB.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -b -r1.44 -r1.45
  --- MDB.java	30 Jun 2006 19:23:44 -0000	1.44
  +++ MDB.java	24 Jul 2006 21:28:28 -0000	1.45
  @@ -23,7 +23,6 @@
   
   import org.jboss.annotation.ejb.AcknowledgementMode;
   import org.jboss.annotation.ejb.DefaultActivationSpecs;
  -import org.jboss.annotation.ejb.MessageDrivenConfig;
   import org.jboss.annotation.ejb.ResourceAdapter;
   import org.jboss.aop.AspectManager;
   import org.jboss.aop.MethodInfo;
  @@ -57,7 +56,7 @@
    * Comment
    *
    * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  - * @version $Revision: 1.44 $
  + * @version $Revision: 1.45 $
    */
   public class MDB extends MessagingContainer 
   {
  
  
  
  1.2       +166 -160  jboss-ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MessagingContainer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- MessagingContainer.java	30 Jun 2006 19:23:44 -0000	1.1
  +++ MessagingContainer.java	24 Jul 2006 21:28:28 -0000	1.2
  @@ -23,7 +23,6 @@
   
   import org.jboss.annotation.ejb.AcknowledgementMode;
   import org.jboss.annotation.ejb.DefaultActivationSpecs;
  -import org.jboss.annotation.ejb.MessageDrivenConfig;
   import org.jboss.annotation.ejb.ResourceAdapter;
   import org.jboss.aop.AspectManager;
   import org.jboss.aop.MethodInfo;
  @@ -48,26 +47,23 @@
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import javax.naming.Context;
  +import javax.naming.InitialContext;
   import javax.naming.NamingException;
   import java.lang.reflect.Field;
   import java.lang.reflect.Method;
   import java.util.*;
   
   /**
  - * @version <tt>$Revision: 1.1 $</tt>
  + * @version <tt>$Revision: 1.2 $</tt>
    * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
    */
   public abstract class MessagingContainer extends EJBContainer implements TimedObjectInvoker
   {
      private static final Logger log = Logger.getLogger(MessagingContainer.class);
      
  -   protected static final String JMS_ADAPTOR = "jms-ra.rar";
  -   
      protected TimerService timerService;
      protected ActivationSpec activationSpec = new ActivationSpec();
      protected JBossMessageEndpointFactory messageEndpointFactory;
  -   protected MessageDrivenConfigProperties mdbConfigProps = new MessageDrivenConfigProperties();
  -   protected MDBConfig config;
   
      /**
       * Default destination type. Used when no message-driven-destination is given
  @@ -153,10 +149,6 @@
   
         populateActivationSpec();
         
  -      populateMDBConfigProperties();
  -
  -      config = MDBConfig.createMDBConfig(activationSpec, mdbConfigProps);
  -
         innerStart();
   
         timerService = TimerServiceFactory.createTimerService(this.getObjectName(), this);
  @@ -164,13 +156,6 @@
         startProxies();
      }
      
  -   protected void populateMDBConfigProperties()
  -   {
  -      MessageDrivenConfig config = (MessageDrivenConfig) resolveAnnotation(MessageDrivenConfig.class);
  -      if (config != null)   
  -         mdbConfigProps.merge(config.mdbConfig());
  -   }
  -
      protected void innerStart() throws Exception
      {
         log.debug("Initializing");
  @@ -200,10 +185,145 @@
   
      protected void startProxies() throws Exception
      {
  -      if (messageEndpointFactory != null)
  -      {
            messageEndpointFactory.start();
         }
  +
  +   /**
  +    * Parse the JNDI suffix from the given JNDI name.
  +    *
  +    * @param jndiname     The JNDI name used to lookup the destination.
  +    * @param defautSuffix Description of Parameter
  +    * @return The parsed suffix or the defaultSuffix
  +    */
  +   protected String parseJndiSuffix(final String jndiname,
  +                                    final String defautSuffix)
  +   {
  +      // jndiSuffix is merely the name that the user has given the MDB.
  +      // since the jndi name contains the message type I have to split
  +      // at the "/" if there is no slash then I use the entire jndi name...
  +      String jndiSuffix = "";
  +
  +      if (jndiname != null)
  +      {
  +         int indexOfSlash = jndiname.indexOf("/");
  +         if (indexOfSlash != -1)
  +         {
  +            jndiSuffix = jndiname.substring(indexOfSlash + 1);
  +         }
  +         else
  +         {
  +            jndiSuffix = jndiname;
  +         }
  +      }
  +      else
  +      {
  +         // if the jndi name from jboss.xml is null then lets use the ejbName
  +         jndiSuffix = defautSuffix;
  +      }
  +
  +      return jndiSuffix;
  +   }
  +
  +   public Object localInvoke(Method method, Object[] args) throws Throwable
  +   {
  +      MethodInfo info = getMethodInfo(method);
  +      if (info == null)
  +      {
  +         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
  +      }
  +      return localInvoke(info, args);
  +
  +   }
  +
  +   public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
  +   {     
  +      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
  +      ThreadLocalENCFactory.push(enc);
  +      try
  +      {
  +         Interceptor[] aspects = info.getInterceptors();
  +         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
  +         nextInvocation.setAdvisor(this);
  +         nextInvocation.setArguments(args);
  +         return nextInvocation.invokeNext();
  +      }
  +      finally
  +      {
  +         Thread.currentThread().setContextClassLoader(oldLoader);
  +         ThreadLocalENCFactory.pop();
  +      }
  +   }
  +
  +   public TimerService getTimerService()
  +   {
  +      return timerService;
  +   }
  +
  +   public void callTimeout(Timer timer) throws Exception
  +   {
  +      Method timeout = callbackHandler.getTimeoutCallback();
  +      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
  +      Object[] args = {timer};
  +      try
  +      {
  +         localInvoke(timeout, args);
  +      }
  +      catch (Throwable throwable)
  +      {
  +         if (throwable instanceof Exception) throw (Exception) throwable;
  +         throw new RuntimeException(throwable);
  +      }
  +   }
  +
  +
  +   public void stop() throws Exception
  +   {
  +      if (timerService != null)
  +      {
  +         TimerServiceFactory.removeTimerService(timerService);
  +      }
  +
  +      stopProxies();
  +   }
  +
  +   protected void stopProxies() throws Exception
  +   {
  +      messageEndpointFactory.stop();
  +   }
  +
  +   public void destroy() throws Exception
  +   {
  +   }
  +   
  +   // ********* JMS Specific
  +   
  +   protected static final String JMS_ADAPTOR = "jms-ra.rar";
  +   protected static final String DESTINATION = "destination";
  +   protected static final String DESTINATION_TYPE = "destinationType";
  +   protected static final String PROVIDER_ADAPTER_JNDI = "providerAdapterJNDI";
  +   
  +   protected String getProviderAdapterJNDI()
  +   {
  +      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(PROVIDER_ADAPTER_JNDI);
  +      if (property != null)
  +         return property.getValue();
  +      return "java:/DefaultJMSProvider";
  +   }
  +   
  +   protected String getDestination()
  +   {
  +      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(DESTINATION);
  +      if (property != null)
  +         return property.getValue();
  +      return null;
  +   }
  +   
  +   protected String getDestinationType()
  +   {
  +      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(DESTINATION_TYPE);
  +      if (property != null)
  +         return property.getValue();
  +      return null;
      }
   
      protected void jmsCreate() throws Exception
  @@ -223,15 +343,14 @@
            throw new RuntimeException("Failed to get the root context");
         }
   
  -      String destinationType = config.getDestinationType();
  -
         // Unfortunately the destination is optional, so if we do not have one
         // here we have to look it up if we have a destinationJNDI, else give it
         // a default.
  +      String destinationType = getDestinationType();
         if (destinationType == null)
         {
            log.warn("No message-driven-destination given; using; guessing type");
  -         destinationType = getDestinationType(context, config.getDestination());
  +         destinationType = getDestinationType(context, getDestination());
         }
   
         if ("javax.jms.Topic".equals(destinationType))
  @@ -258,7 +377,7 @@
         log.debug("Got destination type Queue for " + ejbName);
   
         // Get the JNDI suffix of the destination
  -      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
  +      String jndiSuffix = parseJndiSuffix(getDestination(), ejbName);
         log.debug("jndiSuffix: " + jndiSuffix);
   
         // lookup or create the destination queue
  @@ -266,19 +385,18 @@
         try
         {
            // First we try the specified queue
  -         if (config.getDestination() != null)
  -            queue = (Queue) context.lookup(config.getDestination());
  +         if (getDestination() != null)
  +            queue = (Queue) context.lookup(getDestination());
         }
         catch (NamingException e)
         {
  -         log.warn("Could not find the queue destination-jndi-name=" + config.getDestination());
  +         log.warn("Could not find the queue destination-jndi-name=" + getDestination());
         }
         catch (ClassCastException e)
         {
  -         throw new DeploymentException("Expected a Queue destination-jndi-name=" + config.getDestination());
  +         throw new DeploymentException("Expected a Queue destination-jndi-name=" + getDestination());
         }
   
  -      // FIXME: This is not portable, only works for JBossMQ
         if (queue == null)
            queue = (Queue) createDestination(Queue.class,
                    context,
  @@ -292,7 +410,7 @@
         log.debug("Got destination type Topic for " + ejbName);
   
         // Get the JNDI suffix of the destination
  -      String jndiSuffix = parseJndiSuffix(config.getDestination(), ejbName);
  +      String jndiSuffix = parseJndiSuffix(getDestination(), ejbName);
         log.debug("jndiSuffix: " + jndiSuffix);
   
         // lookup or create the destination topic
  @@ -300,19 +418,18 @@
         try
         {
            // First we try the specified topic
  -         if (config.getDestination() != null)
  -            topic = (Topic) context.lookup(config.getDestination());
  +         if (getDestination() != null)
  +            topic = (Topic) context.lookup(getDestination());
         }
         catch (NamingException e)
         {
  -         log.warn("Could not find the topic destination-jndi-name=" + config.getDestination());
  +         log.warn("Could not find the topic destination-jndi-name=" + getDestination());
         }
         catch (ClassCastException e)
         {
  -         throw new DeploymentException("Expected a Topic destination-jndi-name=" + config.getDestination());
  +         throw new DeploymentException("Expected a Topic destination-jndi-name=" + getDestination());
         }
   
  -      // FIXME: This is not portable, only works for JBossMQ
         if (topic == null)
            topic = (Topic) createDestination(Topic.class,
                    context,
  @@ -363,21 +480,6 @@
         }
      }
      
  -   protected String getDestination()
  -   {
  -      String result = null;
  -      MessageDriven annotation = (MessageDriven) resolveAnnotation(MessageDriven.class);
  -      for (ActivationConfigProperty property : annotation.activationConfig())
  -      {
  -         if (property.propertyName().equals("destination"))
  -         {
  -            return property.propertyValue();
  -         }
  -      }
  -
  -      return result;
  -   }
  -   
      protected void createTemporaryDestination(Class type, String jndiSuffix) throws Exception
      {
         //
  @@ -387,15 +489,18 @@
         // very, very unportable).
         //
   
  -      MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
  +      // MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
         
         String methodName;
  +      String destinationContext;
         if (type == Topic.class)
         {
  +         destinationContext = "topic";
            methodName = "createTopic";
         }
         else if (type == Queue.class)
         {
  +         destinationContext = "queue";
            methodName = "createQueue";
         }
         else
  @@ -407,48 +512,23 @@
         
         ObjectName destinationManagerName = new ObjectName("jboss.mq:service=DestinationManager");
         
  +      ServiceServer server = ServiceServerFactory.getInstance();
         // invoke the server to create the destination
  -      server.invoke(destinationManagerName,
  +      Object result = server.invoke(destinationManagerName,
                 methodName,
                 new Object[]{jndiSuffix},
                 new String[]{"java.lang.String"});
   
  -   }
  -
  -   /**
  -    * Parse the JNDI suffix from the given JNDI name.
  -    *
  -    * @param jndiname     The JNDI name used to lookup the destination.
  -    * @param defautSuffix Description of Parameter
  -    * @return The parsed suffix or the defaultSuffix
  -    */
  -   protected String parseJndiSuffix(final String jndiname,
  -                                    final String defautSuffix)
  -   {
  -      // jndiSuffix is merely the name that the user has given the MDB.
  -      // since the jndi name contains the message type I have to split
  -      // at the "/" if there is no slash then I use the entire jndi name...
  -      String jndiSuffix = "";
  -
  -      if (jndiname != null)
  -      {
  -         int indexOfSlash = jndiname.indexOf("/");
  -         if (indexOfSlash != -1)
  -         {
  -            jndiSuffix = jndiname.substring(indexOfSlash + 1);
  -         }
  -         else
  +      InitialContext jndiContext = InitialContextFactory.getInitialContext();
  +      String binding = destinationContext + "/" + jndiSuffix;
  +      try
            {
  -            jndiSuffix = jndiname;
  -         }
  +         jndiContext.lookup(binding);
         }
  -      else
  +      catch (NamingException e)
         {
  -         // if the jndi name from jboss.xml is null then lets use the ejbName
  -         jndiSuffix = defautSuffix;
  +         jndiContext.bind(binding, result);
         }
  -
  -      return jndiSuffix;
      }
   
      /**
  @@ -461,7 +541,7 @@
      {
         Context context = getInitialContext();
         //todo make this pluggable
  -      String providerAdapterJNDI = config.getProviderAdapterJNDI();
  +      String providerAdapterJNDI = getProviderAdapterJNDI();
         try
         {
            log.debug("Looking up provider adapter: " + providerAdapterJNDI);
  @@ -518,78 +598,4 @@
   
         return destType;
      }
  -
  -   public Object localInvoke(Method method, Object[] args) throws Throwable
  -   {
  -      MethodInfo info = getMethodInfo(method);
  -      if (info == null)
  -      {
  -         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
  -      }
  -      return localInvoke(info, args);
  -
  -   }
  -
  -   public Object localInvoke(MethodInfo info, Object[] args) throws Throwable
  -   {     
  -      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
  -      ThreadLocalENCFactory.push(enc);
  -      try
  -      {
  -         Interceptor[] aspects = info.getInterceptors();
  -         EJBContainerInvocation nextInvocation = new EJBContainerInvocation(info, aspects);
  -         nextInvocation.setAdvisor(this);
  -         nextInvocation.setArguments(args);
  -         return nextInvocation.invokeNext();
  -      }
  -      finally
  -      {
  -         Thread.currentThread().setContextClassLoader(oldLoader);
  -         ThreadLocalENCFactory.pop();
  -      }
  -   }
  -
  -   public TimerService getTimerService()
  -   {
  -      return timerService;
  -   }
  -
  -   public void callTimeout(Timer timer) throws Exception
  -   {
  -      Method timeout = callbackHandler.getTimeoutCallback();
  -      if (timeout == null) throw new EJBException("No method has been annotated with @Timeout");
  -      Object[] args = {timer};
  -      try
  -      {
  -         localInvoke(timeout, args);
  -      }
  -      catch (Throwable throwable)
  -      {
  -         if (throwable instanceof Exception) throw (Exception) throwable;
  -         throw new RuntimeException(throwable);
  -      }
  -   }
  -
  -
  -   public void stop() throws Exception
  -   {
  -      if (timerService != null)
  -      {
  -         TimerServiceFactory.removeTimerService(timerService);
  -      }
  -
  -      stopProxies();
  -   }
  -
  -   protected void stopProxies() throws Exception
  -   {
  -      if (messageEndpointFactory != null)
  -      {
  -         messageEndpointFactory.stop();
  -      }
  -   }
  -
  -   public void destroy() throws Exception
  -   {
  -   }
   }
  
  
  
  1.37      +3 -3      jboss-ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConsumerContainer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- ConsumerContainer.java	30 Jun 2006 19:23:44 -0000	1.36
  +++ ConsumerContainer.java	24 Jul 2006 21:28:28 -0000	1.37
  @@ -61,7 +61,6 @@
   import org.jboss.annotation.ejb.DefaultActivationSpecs;
   import org.jboss.annotation.ejb.Durability;
   import org.jboss.annotation.ejb.Local;
  -import org.jboss.annotation.ejb.MessageDrivenConfig;
   import org.jboss.annotation.ejb.MessageProperties;
   import org.jboss.annotation.ejb.MessagePropertiesImpl;
   import org.jboss.annotation.ejb.Producer;
  @@ -97,7 +96,7 @@
    * Comment
    *
    * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  - * @version $Revision: 1.36 $
  + * @version $Revision: 1.37 $
    */
   public class ConsumerContainer extends MessagingContainer
   {
  @@ -301,7 +300,8 @@
   
      protected void registerProducers() throws Exception
      {
  -      Destination dest = (Destination) getInitialContext().lookup(config.getDestination());
  +      log.info("!!! registerProducers " + getDestination());
  +      Destination dest = (Destination) getInitialContext().lookup(getDestination());
         Class[] producers = getProducerInterfaces(this);
         MessageProperties props = (MessageProperties) resolveAnnotation(MessageProperties.class);
         if (props == null) props = new MessagePropertiesImpl();
  
  
  



More information about the jboss-cvs-commits mailing list