FileDocCategorySizeDatePackage
JBossMessageEndpointFactory.javaAPI DocJBoss 4.2.110815Fri Jul 13 20:53:56 BST 2007org.jboss.ejb3.mdb.inflow

JBossMessageEndpointFactory

public class JBossMessageEndpointFactory extends Object implements javax.resource.spi.endpoint.MessageEndpointFactory
EJBProxyFactory for inflow message driven beans
version
$Revision: 60233 $
author
William DeCoste
author
Bill Burke

Fields Summary
private static final Logger
log
protected boolean
trace
Whether trace is enabled
protected org.jboss.ejb3.mdb.MessagingContainer
container
Our container
protected HashMap
properties
The activation properties
protected Class
messagingTypeClass
The messaging type class
protected String
resourceAdapterName
The resource adapter name
protected ObjectName
resourceAdapterObjectName
protected javax.resource.spi.ActivationSpec
activationSpec
The activation spec
protected Class[]
interfaces
The interfaces
protected EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
nextProxyId
The next proxy id
protected String[]
createActivationSpecSig
The signature for createActivationSpec
protected String[]
activationSig
The signature for activate/deactivateEndpint
Constructors Summary
public JBossMessageEndpointFactory()

              
         
   // Constructors --------------------------------------------------
   
    
   
   
Methods Summary
protected voidactivate()
Activate

throws
DeploymentException for any error

   
      Object[] params = new Object[] { this, activationSpec };
      try
      {
         KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "endpointActivation", params, activationSig);
      }
      catch (Throwable t)
      {
         t = JMXExceptionDecoder.decode(t);
         DeploymentException.rethrowAsDeploymentException("Endpoint activation failed ra=" + resourceAdapterObjectName + 
               " activationSpec=" + activationSpec, t);
      }
   
protected voidcreateActivationSpec()
Create the activation spec

throws
DeploymentException for any error

      properties = new HashMap(container.getActivationConfigProperties());
         
      Object[] params = new Object[] 
      {
         messagingTypeClass,
         properties.values()
      };
    
      try
      {
         activationSpec = (ActivationSpec) KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "createActivationSpec", params, createActivationSpecSig);
      }
      catch (Throwable t)
      {
         t = JMXExceptionDecoder.decode(t);
         DeploymentException.rethrowAsDeploymentException("Unable to create activation spec ra=" + resourceAdapterObjectName + 
               " messaging-type=" + messagingTypeClass.getName() + " properties=" + container.getActivationConfigProperties(), t);
      }
   
public javax.resource.spi.endpoint.MessageEndpointcreateEndpoint(javax.transaction.xa.XAResource resource)

   
      trace = log.isTraceEnabled(); 
      
      if (trace)
         log.trace("createEndpoint " + this + " xaResource=" + resource);
          
      MessageEndpoint endpoint = createProxy(resource);
        
      if (trace)
         log.trace("Created endpoint " + endpoint + " from " + this);

      return endpoint;
   
protected javax.resource.spi.endpoint.MessageEndpointcreateProxy(javax.transaction.xa.XAResource resource)

      try 
      {
         Class proxyClass = java.lang.reflect.Proxy.getProxyClass(container.getBeanClass().getClassLoader(), interfaces);
            
         final Class[] constructorParams = {InvocationHandler.class};
         java.lang.reflect.Constructor proxyConstructor = proxyClass.getConstructor(constructorParams);
         
         MessageInflowLocalProxy proxy = new MessageInflowLocalProxy(container);
         proxy.setXaResource(resource);
         proxy.setMessageEndpointFactory(this);
         
         Object[] args = {proxy};
         MessageEndpoint endpoint = (MessageEndpoint)proxyConstructor.newInstance(args);
         return endpoint;
         
      } catch (Exception e)
      {
         e.printStackTrace();
         return null;
      }
   
protected voiddeactivate()
Deactivate

      Object[] params = new Object[] { this, activationSpec };
      try
      {
         KernelAbstractionFactory.getInstance().invoke(resourceAdapterObjectName, "endpointDeactivation", params, activationSig);
      }
      catch (Throwable t)
      {
         t = JMXExceptionDecoder.decode(t);
         log.warn("Endpoint activation failed ra=" + resourceAdapterObjectName + 
               " activationSpec=" + activationSpec, t);
      }
   
public org.jboss.ejb3.mdb.MessagingContainergetContainer()
Get the message driven container

return
the container

      return container;
   
public booleanisDeliveryTransacted(java.lang.reflect.Method method)

      TransactionManagementType mtype = TxUtil.getTransactionManagementType(container);
      if (mtype == javax.ejb.TransactionManagementType.BEAN) return false;


      TransactionAttribute attr = (TransactionAttribute)container.resolveAnnotation(method, TransactionAttribute.class);
      if (attr == null)
      {
         attr =(TransactionAttribute)container.resolveAnnotation(TransactionAttribute.class);
      }
      TransactionAttributeType type = TransactionAttributeType.REQUIRED;
      if (attr != null) type = attr.value();
      return type == javax.ejb.TransactionAttributeType.REQUIRED;
   
protected voidresolveMessageListener()
Resolve message listener class

throws
DeploymentException for any error

      messagingTypeClass = container.getMessagingType();
   
protected voidresolveResourceAdapter()

      try
      {
         resourceAdapterObjectName = new ObjectName("jboss.jca:service=RARDeployment,name='" + resourceAdapterName + "'");
         // todo register with kernel and push dependencies to kernel
      }
      catch (MalformedObjectNameException e)
      {
         throw new RuntimeException(e);
      }
   
protected voidresolveResourceAdapterName()
Resolve the resource adapter name

return
the resource adapter name
throws
DeploymentException for any error

      resourceAdapterName = container.getResourceAdaptorName();
   
public voidsetContainer(org.jboss.ejb3.Container container)
Set the container for which this is an invoker to.

param
container The container for which this is an invoker to.

      this.container = (MessagingContainer) container;
   
public voidstart()

      // Resolve the message listener
      resolveMessageListener();
      resolveResourceAdapterName();
      // Resolve the resource adapter
      resolveResourceAdapter();
      // Create the activation config
      createActivationSpec();
      // Set up proxy parameters
      // Set the interfaces
      interfaces = new Class[] { MessageEndpoint.class, messagingTypeClass};
      // Activate
      activate();
   
public voidstop()

      // Deactivate
      deactivate();
   
public java.lang.StringtoString()
Return a string representation of the current config state.

      StringBuffer buffer = new StringBuffer(100);
      buffer.append(super.toString());
      buffer.append("{ resourceAdapter=").append(resourceAdapterName);
      buffer.append(", messagingType=").append(container.getMessagingType());
      buffer.append(", ejbName=").append(container.getEjbName());
      buffer.append(", activationConfig=").append(properties.values());
      buffer.append(", activationSpec=").append(activationSpec);
      buffer.append("}");
      return buffer.toString();