Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » resource » deployment » [javadoc | source]
    1   /*
    2    * JBoss, Home of Professional Open Source.
    3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
    4    * as indicated by the @author tags. See the copyright.txt file in the
    5    * distribution for a full listing of individual contributors.
    6    *
    7    * This is free software; you can redistribute it and/or modify it
    8    * under the terms of the GNU Lesser General Public License as
    9    * published by the Free Software Foundation; either version 2.1 of
   10    * the License, or (at your option) any later version.
   11    *
   12    * This software is distributed in the hope that it will be useful,
   13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15    * Lesser General Public License for more details.
   16    *
   17    * You should have received a copy of the GNU Lesser General Public
   18    * License along with this software; if not, write to the Free
   19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21    */
   22   package org.jboss.resource.deployment;
   23   
   24   import java.util.Collection;
   25   import java.util.Iterator;
   26   import java.util.Timer;
   27   
   28   import javax.management.AttributeNotFoundException;
   29   import javax.management.MBeanAttributeInfo;
   30   import javax.management.MBeanException;
   31   import javax.management.MBeanOperationInfo;
   32   import javax.management.MBeanParameterInfo;
   33   import javax.management.ReflectionException;
   34   import javax.resource.spi.ActivationSpec;
   35   import javax.resource.spi.BootstrapContext;
   36   import javax.resource.spi.ResourceAdapter;
   37   import javax.resource.spi.UnavailableException;
   38   import javax.resource.spi.XATerminator;
   39   import javax.resource.spi.endpoint.MessageEndpointFactory;
   40   import javax.resource.spi.work.WorkManager;
   41   
   42   import org.jboss.deployment.DeploymentException;
   43   import org.jboss.deployment.DeploymentInfo;
   44   import org.jboss.resource.metadata.ConfigPropertyMetaData;
   45   import org.jboss.resource.metadata.ConnectorMetaData;
   46   import org.jboss.resource.metadata.DescriptionGroupMetaData;
   47   import org.jboss.resource.metadata.JBossRAMetaData;
   48   import org.jboss.resource.metadata.MessageListenerMetaData;
   49   import org.jboss.resource.metadata.RARDeploymentMetaData;
   50   import org.jboss.system.ServiceDynamicMBeanSupport;
   51   import org.jboss.system.server.ServerConfigUtil;
   52   
   53   /**
   54    * A resource adapter deployment
   55    *
   56    * @author  <a href="adrian@jboss.com">Adrian Brock</a>
   57    * @version $Revision: 71554 $
   58    */
   59   public class RARDeployment extends ServiceDynamicMBeanSupport
   60      implements BootstrapContext
   61   {
   62      /** The deployment info */
   63      protected DeploymentInfo di;
   64      
   65      /** Our deployer */
   66      protected RARDeployer deployer;
   67      
   68      /** The RARDeploymentMetaData */
   69      protected RARDeploymentMetaData rdmd;
   70      
   71      /** The ConnectorMetaData */
   72      protected ConnectorMetaData cmd;
   73      
   74      /** The JBossRAMetaData */
   75      protected JBossRAMetaData ramd;
   76      
   77      /** The resource adapter */
   78      protected ResourceAdapter resourceAdapter;
   79   
   80      /**
   81       * Create a new RAR deployment
   82       * 
   83       * @param di the deployment info
   84       */
   85      public RARDeployment(DeploymentInfo di)
   86      {
   87         this.di = di;
   88         this.deployer = (RARDeployer) di.deployer;
   89         this.rdmd = (RARDeploymentMetaData)di.metaData;
   90         this.cmd = rdmd.getConnectorMetaData();
   91         this.ramd = rdmd.getRaXmlMetaData();
   92         
   93      }
   94      
   95      // Public --------------------------------------------------------
   96   
   97      public Timer createTimer() throws UnavailableException
   98      {
   99         return new Timer(true);
  100      }
  101   
  102      public WorkManager getWorkManager()
  103      {
  104         return deployer.workManager;
  105      }
  106   
  107      public XATerminator getXATerminator()
  108      {
  109         return deployer.xaTerminator;
  110      }
  111      
  112      protected void startService() throws Exception
  113      {
  114         if (cmd.getLicense().getRequired())
  115         {
  116            log.info("Required license terms exist, view META-INF/ra.xml in " + ServerConfigUtil.shortUrlFromServerHome(di.url.toString()));
  117            log.debug("License terms full URL: " + di.url);
  118         }
  119         resourceAdapter = ResourceAdapterFactory.createResourceAdapter(rdmd);
  120         resourceAdapter.start(this);
  121      }
  122      
  123      protected void stopService() throws Exception
  124      {
  125         resourceAdapter.stop();
  126      }
  127      
  128      protected String getInternalDescription()
  129      {
  130         String description = null;
  131         DescriptionGroupMetaData dgmd = cmd.getDescription();
  132         if (dgmd != null)
  133            description = dgmd.getDescription();
  134         if (description == null)
  135            description = "RAR Deployment " + di.url;
  136         return description;
  137      }
  138   
  139      protected MBeanAttributeInfo[] getInternalAttributeInfo()
  140      {
  141         Collection properties = cmd.getProperties();
  142         MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[11+properties.size()];
  143         attrs[0] = new MBeanAttributeInfo("MetaData", ConnectorMetaData.class.getName(), "The meta data", true, false, false);
  144         attrs[1] = new MBeanAttributeInfo("AuthenticationMechanism", String.class.getName(), "The authentication mechanism", true, false, false);
  145         attrs[2] = new MBeanAttributeInfo("EISType", String.class.getName(), "The EIS type", true, false, false);
  146         attrs[3] = new MBeanAttributeInfo("License", String.class.getName(), "The license", true, false, false);
  147         attrs[4] = new MBeanAttributeInfo("RAClass", String.class.getName(), "The resource adapter class", true, false, false);
  148         attrs[5] = new MBeanAttributeInfo("RAVersion", String.class.getName(), "The resource adapter version", true, false, false);
  149         attrs[6] = new MBeanAttributeInfo("TransactionSupport", String.class.getName(), "The transaction support", true, false, false);
  150         attrs[7] = new MBeanAttributeInfo("VendorName", String.class.getName(), "The vendor name", true, false, false);
  151         attrs[8] = new MBeanAttributeInfo("Version", String.class.getName(), "The spec version", true, false, false);
  152         attrs[9] = new MBeanAttributeInfo("ReauthenticationSupport", Boolean.TYPE.getName(), "Whether reauthentication support is supported", true, false, false);
  153         attrs[10] = new MBeanAttributeInfo("ResourceAdapter", ResourceAdapter.class.getName(), "The resource adapter instance", true, false, false);
  154         int n = 11;
  155         for (Iterator i = properties.iterator(); i.hasNext();)
  156         {
  157            ConfigPropertyMetaData cpmd = (ConfigPropertyMetaData) i.next();
  158            attrs[n++] = new MBeanAttributeInfo(cpmd.getName(), cpmd.getType(), cpmd.getDescription().getDescription(), true, false, false);
  159         }
  160         return attrs;
  161      }
  162      
  163      protected Object getInternalAttribute(String attribute)
  164         throws AttributeNotFoundException, MBeanException, ReflectionException
  165      {
  166         if ("MetaData".equals(attribute))
  167            return cmd;
  168         else if ("AuthenticationMechanism".equals(attribute))
  169            return cmd.getAuthenticationMechanism().getAuthenticationMechansimType();
  170         else if ("EISType".equals(attribute))
  171            return cmd.getEISType();
  172         else if ("License".equals(attribute))
  173            return cmd.getLicense().getDescription().getDescription();
  174         else if ("RAClass".equals(attribute))
  175            return cmd.getRAClass();
  176         else if ("RAVersion".equals(attribute))
  177            return cmd.getRAVersion();
  178         else if ("TransactionSupport".equals(attribute))
  179            return cmd.getTransactionSupport();
  180         else if ("VendorName".equals(attribute))
  181            return cmd.getVendorName();
  182         else if ("Version".equals(attribute))
  183            return cmd.getVersion();
  184         else if ("ReauthenticationSupport".equals(attribute))
  185            return new Boolean(cmd.getReauthenticationSupport());
  186         else if ("ResourceAdapter".equals(attribute))
  187            return resourceAdapter;
  188         Object property = cmd.getProperty(attribute);
  189         if (property != null)
  190            return property;
  191         
  192         return super.getInternalAttribute(attribute);
  193      }
  194   
  195      protected MBeanOperationInfo[] getInternalOperationInfo()
  196      {
  197         MBeanOperationInfo[] ops = new MBeanOperationInfo[3];
  198   
  199         MBeanParameterInfo[] createActivationSpecParams = new MBeanParameterInfo[]
  200         {
  201            new MBeanParameterInfo("MessagingType", Class.class.getName(), "The type of the message listener"),
  202            new MBeanParameterInfo("ActivationConfig", Collection.class.getName(), "A collection of activation config properties")
  203         };
  204         ops[0] = new MBeanOperationInfo("createActivationSpec", "Create an activation spec",
  205               createActivationSpecParams, ActivationSpec.class.getName(), MBeanOperationInfo.ACTION);
  206   
  207         MBeanParameterInfo[] activationParams = new MBeanParameterInfo[]
  208         {
  209            new MBeanParameterInfo("MessageEndpointFactory", MessageEndpointFactory.class.getName(), "The message endpoint factory"),
  210            new MBeanParameterInfo("ActivationSpec", ActivationSpec.class.getName(), "The activation spec")
  211         };
  212         ops[1] = new MBeanOperationInfo("endpointActivation", "Active the endpoint",
  213               activationParams, Void.class.getName(), MBeanOperationInfo.ACTION);
  214         ops[2] = new MBeanOperationInfo("endpointDeactivation", "Deactive the endpoint",
  215               activationParams, Void.class.getName(), MBeanOperationInfo.ACTION);
  216   
  217         return ops;
  218      }
  219      
  220      protected Object internalInvoke(String actionName, Object[] params, String[] signature) throws MBeanException,
  221            ReflectionException
  222      {
  223         if ("createActivationSpec".equals(actionName))
  224         {
  225            if (params.length != 2)
  226               throw new IllegalArgumentException("Wrong number of parameters for " + actionName);
  227            Class messagingType = (Class) params[0];
  228            Collection activationConfig = (Collection) params[1];
  229            return createActivationSpec(messagingType, activationConfig);
  230         }
  231         else if ("endpointActivation".equals(actionName))
  232         {
  233            if (params.length != 2)
  234               throw new IllegalArgumentException("Wrong number of parameters for " + actionName);
  235            MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory) params[0];
  236            ActivationSpec activationSpec = (ActivationSpec) params[1];
  237            endpointActivation(messageEndpointFactory, activationSpec);
  238            return null;
  239         }
  240         else if ("endpointDeactivation".equals(actionName))
  241         {
  242            if (params.length != 2)
  243               throw new IllegalArgumentException("Wrong number of parameters for " + actionName);
  244            MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory) params[0];
  245            ActivationSpec activationSpec = (ActivationSpec) params[1];
  246            endpointDeactivation(messageEndpointFactory, activationSpec);
  247            return null;
  248         }
  249         return super.internalInvoke(actionName, params, signature);
  250      }
  251   
  252      protected ActivationSpec createActivationSpec(Class messagingType, Collection activationConfig) throws MBeanException
  253      {
  254         boolean trace = log.isTraceEnabled();
  255         if (trace)
  256            log.trace("CreateActivateSpec rar=" + getServiceName() + " messagingType=" + messagingType.getName() + " activationConfig=" + activationConfig);
  257         
  258         try
  259         {
  260            // Find the meta data
  261            MessageListenerMetaData mlmd = cmd.getMessageListener(messagingType.getName());
  262            if (mlmd == null)
  263               throw new DeploymentException("MessagingType '" + messagingType.getName() + "' not found in resource deployment " + getServiceName());
  264            
  265            return ActivationSpecFactory.createActivationSpec(getServiceName(), messagingType.getName(), activationConfig, mlmd);
  266         }
  267         catch (Exception e)
  268         {
  269            throw new MBeanException(e, "Error in create activation spec " + getServiceName());
  270         }
  271      }
  272   
  273      protected void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException
  274      {
  275         boolean trace = log.isTraceEnabled();
  276         if (trace)
  277            log.trace("EndpointActivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
  278   
  279         try
  280         {
  281            activationSpec.setResourceAdapter(resourceAdapter);
  282            resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
  283         }
  284         catch (Exception e)
  285         {
  286            throw new MBeanException(e, "Error in endpoint activation " + getServiceName());
  287         }
  288      }
  289   
  290      protected void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws MBeanException
  291      {
  292         boolean trace = log.isTraceEnabled();
  293         if (trace)
  294            log.trace("EndpointDeactivation rar=" + getServiceName() + " messagingEndpointFactory=" + messageEndpointFactory + " activationSpec=" + activationSpec);
  295   
  296         try
  297         {
  298            resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
  299         }
  300         catch (Exception e)
  301         {
  302            throw new MBeanException(e, "Error in endpoint deactivation " + getServiceName());
  303         }
  304      }
  305   }

Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » resource » deployment » [javadoc | source]