FileDocCategorySizeDatePackage
ConsumerContainer.javaAPI DocJBoss 4.2.110348Fri Jul 13 20:53:56 BST 2007org.jboss.ejb3.mdb

ConsumerContainer

public class ConsumerContainer extends MessagingContainer
Comment
author
Bill Burke
version
$Revision: 61280 $

Fields Summary
private static final Logger
log
protected Class
messagingType
protected Method
ON_MESSAGE
protected ArrayList
producers
protected static final String
DEFAULT_DESTINATION_TYPE
Default destination type. Used when no message-driven-destination is given in ejb-jar, and a lookup of destinationJNDI from jboss.xml is not successfull. Default value: javax.jms.Topic.
public static final String
CONSUMER_MESSAGE
This is needed because API changed from JBoss 4.0.1sp1 to 4.0.2 TODO remove this after 4.0.2 is out.
Constructors Summary
public ConsumerContainer(String ejbName, org.jboss.aop.AspectManager manager, ClassLoader cl, String beanClassName, Hashtable ctxProperties, org.jboss.ejb3.interceptor.InterceptorInfoRepository interceptorRepository, org.jboss.ejb3.Ejb3Deployment deployment)



           
                               
                             
   
      super(ejbName, manager, cl, beanClassName, ctxProperties, interceptorRepository, deployment);
   
Methods Summary
public org.jboss.aop.joinpoint.InvocationResponsedynamicInvoke(org.jboss.aop.joinpoint.Invocation invocation)

      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
      EJBContainerInvocation newSi = null;
      pushEnc();
      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");
         }
       
         newSi = new EJBContainerInvocation(info);
         newSi.setArguments(si.getArguments());
         newSi.setMetaData(si.getMetaData());
         newSi.setAdvisor(this);

         InvocationResponse response = new InvocationResponse(newSi.invokeNext());
         response.setContextInfo(newSi.getResponseContextInfo());
         return response;
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(oldLoader);
         popEnc();
      }
   
public java.util.MapgetActivationConfigProperties()

      HashMap result = new HashMap();
      Consumer annotation = (Consumer) resolveAnnotation(Consumer.class);
      for (ActivationConfigProperty property : annotation.activationConfig())
      {
         addActivationSpecProperty(result, property);
      }
      
      DefaultActivationSpecs defaultSpecsAnnotation = (DefaultActivationSpecs)resolveAnnotation(DefaultActivationSpecs.class);
      if (defaultSpecsAnnotation != null)
      {
         for (ActivationConfigProperty property : defaultSpecsAnnotation.value())
         {
            addActivationSpecProperty(result, property);
         }
      }
      
      return result;
   
public java.lang.ClassgetMessagingType()

      return javax.jms.MessageListener.class;
   
public org.jboss.aop.MethodInfogetMethodInfo(java.lang.reflect.Method method)

      MethodInfo info = new MethodInfo();
      info.setAdvisor(this);
      info.setAdvisedMethod(method);
      info.setUnadvisedMethod(method);
    
      return info;
   
protected java.lang.reflect.MethodgetOnMessage()

      if (ON_MESSAGE != null)
         return ON_MESSAGE;
      
      try
      {
         final Class arg = Message.class;
         ON_MESSAGE = javax.jms.MessageListener.class.getMethod("onMessage", new Class[]{arg});
      }
      catch (Exception e)
      {
         e.printStackTrace();
         throw new ExceptionInInitializerError(e);
      }

      return ON_MESSAGE;
   
public java.lang.Class[]getProducerInterfaces(org.jboss.ejb3.Container container1)

      Class beanClass = container1.getBeanClass();
      Class[] interfaces = beanClass.getInterfaces();
      if (interfaces.length == 0) throw new RuntimeException("Bean class must implement at least one interface: " + beanClass.getName());
      if (interfaces.length == 1)
      {
         return interfaces;
      }
      ArrayList localInterfaces = new ArrayList();
      for (int i = 0; i < interfaces.length; i++)
      {
         if (interfaces[i].isAnnotationPresent(Producer.class))
         {
            localInterfaces.add(interfaces[i]);
         }
      }
      Producer annotation = (Producer)resolveAnnotation(Producer.class);
      if (annotation != null)
      {
         Class producer = annotation.producer();
         if (producer != null)
            localInterfaces.add(producer);
      }
      
      Producers producersAnnotation = (Producers)resolveAnnotation(Producers.class);
      if (producersAnnotation != null)
      {
         for (Producer producerAnnotation : producersAnnotation.value())
         {
            Class producer = producerAnnotation.producer();
            if (producer != null)
               localInterfaces.add(producer);
         }
      }
      
      if (localInterfaces.size() == 0) return null;
      interfaces = (Class[]) localInterfaces.toArray(new Class[localInterfaces.size()]);
      return interfaces;
   
public java.lang.ObjectlocalInvoke(org.jboss.aop.MethodInfo info, java.lang.Object[] args)

     
      if (info.getAdvisedMethod().equals(getOnMessage()))
      {
         ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
         pushEnc();
         
         try
         {
            Message message = (Message)args[0];
            MethodInvocation invocation = (MethodInvocation) ((ObjectMessage) message).getObject();
            invocation.getMetaData().addMetaData(CONSUMER_MESSAGE, CONSUMER_MESSAGE, message, PayloadKey.TRANSIENT);
            return this.dynamicInvoke(invocation);
         }
         finally
         {
            Thread.currentThread().setContextClassLoader(oldLoader);
            popEnc();
         }
      }
      else
         return super.localInvoke(info, args);
   
protected voidpopulateActivationSpec()

      DefaultActivationSpecs defaultSpecs = (DefaultActivationSpecs) resolveAnnotation(DefaultActivationSpecs.class);
      if (defaultSpecs != null)
      {
         activationSpec.merge(defaultSpecs.value());
      }

      Consumer md = (Consumer) resolveAnnotation(Consumer.class);
      activationSpec.merge(md.activationConfig());
   
protected voidregisterProducers()

      Destination dest = (Destination) getInitialContext().lookup(getDestination());
      Class[] producers = getProducerInterfaces(this);
      MessageProperties props = (MessageProperties) resolveAnnotation(MessageProperties.class);
      if (props == null) props = new MessagePropertiesImpl();
      for (Class producer : producers)
      {
         log.debug("Producer: " + producer.getName());
         ProducerFactory producerFactory = null;
         if (producer.isAnnotationPresent(Local.class))
         {
            producerFactory = new LocalProducerFactory(this, producer, props, dest, getInitialContext(), initialContextProperties);
         }
         else
         {
            producerFactory = new RemoteProducerFactory(this, producer, props, dest, getInitialContext(), initialContextProperties);
         }
         this.producers.add(producerFactory);
         producerFactory.start();
      }
   
public voidstart()
Initialize the container invoker. Sets up a connection, a server session pool and a connection consumer for the configured destination.

Any JMSExceptions produced while initializing will be assumed to be caused due to JMS Provider failure.

throws
Exception Failed to initalize.

      super.start();
      
      registerProducers();
   
public voidstop()

      unregisterProducers();
      super.stop();
   
protected voidunregisterProducers()

      for (ProducerFactory factory : producers)
      {
         factory.stop();
      }