User: mnf999 Date: 02/01/20 07:06:07 Modified: src/main/org/jboss/resource RARDeployer.java Log: New deployer and integration of CL Revision Changes Path 1.17 +169 -154 jbosscx/src/main/org/jboss/resource/RARDeployer.java Index: RARDeployer.java =================================================================== RCS file: /cvsroot/jboss/jbosscx/src/main/org/jboss/resource/RARDeployer.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- RARDeployer.java 2002/01/03 04:00:52 1.16 +++ RARDeployer.java 2002/01/20 15:06:06 1.17 @@ -1,9 +1,9 @@ /* - * JBoss, the OpenSource J2EE webOS - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ +* JBoss, the OpenSource J2EE webOS +* +* Distributable under LGPL license. +* See terms of license at gnu.org. +*/ package org.jboss.resource; @@ -28,233 +28,248 @@ import java.util.jar.JarFile; import javax.management.Notification; import javax.management.ObjectName; -import org.jboss.deployment.DeployerMBeanSupport; +import org.jboss.deployment.DeploymentInfo; import org.jboss.deployment.DeploymentException; -import org.jboss.deployment.ServiceDeploymentInfo; import org.jboss.logging.Logger; import org.jboss.metadata.XmlFileLoader; import org.jboss.system.ServiceLibraries; -import org.jboss.system.URLClassLoader; +import org.jboss.system.ServiceMBeanSupport; +import org.jboss.system.ServiceControllerMBean; +import org.jboss.system.UnifiedClassLoader; import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Service that deploys ".rar" files containing resource adapters. Deploying - * the RAR file is the first step in making the resource adapter available to - * application components; once it is deployed, one or more connection - * factories must be configured and bound into JNDI, a task performed by the - * <code>ConnectionFactoryLoader</code> service. - * - * @author Toby Allsopp ([EMAIL PROTECTED]) - * @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a> - * @version $Revision: 1.16 $ - * @see org.jboss.resource.ConnectionFactoryLoader <p> - * - * <b>Revisions:</b> <p> - * - * <b>20010725 Toby Allsopp (patch from David Jencks)</b> - * <ul> - * <li> Implemented <code>getMetaData</code> so that connection factories - * can be loaded after RAR deployment</li> - * </ul> - * <b>20011219 Marc Fleury</b> - * <ul> - * <li> Make the deployer call create and start on the service it deploys</li> - * </ul> - */ +* Service that deploys ".rar" files containing resource adapters. Deploying +* the RAR file is the first step in making the resource adapter available to +* application components; once it is deployed, one or more connection +* factories must be configured and bound into JNDI, a task performed by the +* <code>ConnectionFactoryLoader</code> service. +* +* @author Toby Allsopp ([EMAIL PROTECTED]) +* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a> +* @version $Revision: 1.17 $ +* @see org.jboss.resource.ConnectionFactoryLoader <p> +* +* <b>Revisions:</b> <p> +* +* <b>20010725 Toby Allsopp (patch from David Jencks)</b> +* <ul> +* <li> Implemented <code>getMetaData</code> so that connection factories +* can be loaded after RAR deployment</li> +* </ul> +* <b>20011219 Marc Fleury</b> +* <ul> +* <li> Make the deployer call create and start on the service it deploys</li> +* </ul> +* <b>20011227 Marc Fleury</b> +* <ul> +* <li> Unification of deployers</li> +* </ul> +* +*/ public class RARDeployer - extends DeployerMBeanSupport - implements RARDeployerMBean +extends ServiceMBeanSupport +implements RARDeployerMBean { private static int nextNum = 0; + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + /** - * The next sequence number to be used in notifications about (un)deployment - */ + * The next sequence number to be used in notifications about (un)deployment + */ private int nextMessageNum = 0; /** - * Gets the DeployableFilter attribute of the RARDeployer object - * - * @return The DeployableFilter value - */ - public FilenameFilter getDeployableFilter() + * Gets the DeployableFilter attribute of the RARDeployer object + * + * @return The DeployableFilter value + */ + public boolean accepts(DeploymentInfo sdi) { - return - new FilenameFilter() - { - /** - * #Description of the Method - * - * @param dir Description of Parameter - * @param filename Description of Parameter - * @return Description of the Returned Value - */ - public boolean accept(File dir, String filename) - { - return filename.endsWith(".rar"); - } - }; + // To be accepted the deployment's root name must end in rar + if (sdi.url.getFile().endsWith("rar")) return true; + + else return false; } + // RARDeployerMBean implementation ------------------------------- - // DeployerMBeanSupport overrides --------------------------------- + // DeployerMBean overrides --------------------------------- /** - * Gets the Name attribute of the RARDeployer object - * - * @return The Name value - */ + * Gets the Name attribute of the RARDeployer object + * + * @return The Name value + */ public String getName() { return "RARDeployer"; } - - /** - * The <code>deploy</code> method deploys a rar at the given url. - * - * @param url The <code>URL</code> location of the rar to deploy. - * @return an <code>Object</code> to identify this deployment. - * @exception IOException if an error occurs - * @exception DeploymentException if an error occurs - */ - protected Object deploy(URL url) - throws IOException, DeploymentException + public void init(DeploymentInfo rdi) + throws DeploymentException { - getLog().info("Attempting to deploy RAR at '" + url + "'"); - RarDeploymentInfo rdi = new RarDeploymentInfo(url); - - File localCopy = getLocalCopy(url, rdi); - URL localUrl =localCopy.toURL(); - extractPackages(localUrl, rdi); - URL ddUrl = null; - for (Iterator i = rdi.getXmlUrls().iterator(); i.hasNext();) + try { - URL xml = (URL)i.next(); - if (xml.getFile().endsWith("META-INF/ra.xml")) + URL raUrl = rdi.localCl.getResource("META-INF/ra.xml"); + + Document dd = XmlFileLoader.getDocument(raUrl); + + Element root = dd.getDocumentElement(); + + RARMetaData metadata = new RARMetaData(); + metadata.importXml(root); + + metadata.setClassLoader(rdi.ucl); + rdi.metaData = metadata; + + // resolve the watch + if (rdi.url.getProtocol().startsWith("http")) { - ddUrl = xml; - break; + // We watch the top only, no directory support + rdi.watch = rdi.url; } - } - - if (ddUrl == null) - { - throw new DeploymentException("No deployment descriptor " + - "('META-INF/ra.xml') found in alleged " + - "resource adapter at '" + url + "'"); + + else if(rdi.url.getProtocol().startsWith("file")) + { + + File file = new File (rdi.url.getFile()); + + // If not directory we watch the package + if (!file.isDirectory()) rdi.watch = rdi.url; + + // If directory we watch the xml files + else rdi.watch = new URL(rdi.url, "META-INF/application.xml"); + } } - - Document dd = XmlFileLoader.getDocument(ddUrl); - - Element root = dd.getDocumentElement(); - - RARMetaData metadata = new RARMetaData(); - metadata.importXml(root); - - // Create a class loader that can load classes from any JARs - // inside the RAR. extractPackages found the JARs. - - - // Ok, now we have the URLs of the JARs contained in the RAR we - // can create a classloader that loads classes from them - // Note, we're using the jboss system classloader so the rar - // will be universally available without unavailable interface - // problems! - // We use the original (uncopied) url as the id key. - ClassLoader cl = rdi.createClassLoader(); - metadata.setClassLoader(cl); + catch (Exception e) {throw new DeploymentException("problem with init in RARDeployer ", e);} + + } + + /** + * The <code>deploy</code> method deploys a rar at the given url. + * + * @param url The <code>URL</code> location of the rar to deploy. + * @return an <code>Object</code> to identify this deployment. + * @exception IOException if an error occurs + * @exception DeploymentException if an error occurs + */ + public void deploy(DeploymentInfo rdi) + throws DeploymentException + { + getLog().info("Attempting to deploy RAR at '" + rdi.url + "'"); - // set up the RARDeployment mbean for dependency management. - try - { - ObjectName deploymentName = new ObjectName("jboss.jca:service=RARDeployment,name=" + metadata.getDisplayName()); - getServer().createMBean("org.jboss.resource.RARDeployment", + try { + RARMetaData metaData = (RARMetaData) rdi.metaData; + + //set up the RARDeployment mbean for dependency management. + ObjectName deploymentName = new ObjectName("JCA:service=RARDeployment,name=" + metaData.getDisplayName()); + server.createMBean("org.jboss.resource.RARDeployment", deploymentName, - new Object[] {metadata}, + new Object[] {metaData}, new String[] {"org.jboss.resource.RARMetaData"}); - getServer().invoke( + server.invoke( getServiceControllerName(), "create", new Object[] {deploymentName}, new String[] {"javax.management.ObjectName"}); - getServer().invoke( + server.invoke( getServiceControllerName(), "start", new Object[] {deploymentName}, new String[] {"javax.management.ObjectName"}); - + } catch (Exception e) { + e.printStackTrace(); + log.error(e); throw new DeploymentException("Problem making RARDeployment MBean", e); } // end of try-catch - - rdi.metadata = metadata; - return rdi; + } - protected void undeploy(URL url, Object o) - throws DeploymentException + public void undeploy(DeploymentInfo rdi) + throws DeploymentException { - getLog().info("Undeploying RAR at '" + url + "'"); + log.info("Undeploying RAR at '" + rdi.url + "'"); - RarDeploymentInfo rdi = (RarDeploymentInfo)o; + RARMetaData metadata = (RARMetaData) rdi.metaData; - if (rdi == null) - { - throw new DeploymentException("There doesn't appear to be a RAR " + - "deployed at '" + url + "'"); - } - - RARMetaData metadata = rdi.metadata; try { ObjectName deploymentName = new ObjectName("jboss.jca:service=RARDeployment,name=" + metadata.getDisplayName()); log.info("About to undeploy RARDeploymentMBean, objectname: " + deploymentName); getServer().invoke(getServiceControllerName(), - "undeploy", + "stop", new Object[] {deploymentName}, new String[] {"javax.management.ObjectName"}); - + + getServer().invoke(getServiceControllerName(), + "destroy", + new Object[] {deploymentName}, + new String[] {"javax.management.ObjectName"}); + + getServer().invoke(getServiceControllerName(), + "remove", + new Object[] {deploymentName}, + new String[] {"javax.management.ObjectName"}); } catch (Exception e) { log.error("Problem undeploying RARDeployment MBean", e); throw new DeploymentException("Problem undeploying RARDeployment MBean", e); - } + } // end of try-catch - // unregister the classloader from the system libraries. - // this is the org.jboss.system.URLClassLoader. - URLClassLoader cl = (URLClassLoader)metadata.getClassLoader(); + metadata.setClassLoader(null); + } + + public void startService() + { try { - ServiceLibraries.getLibraries().removeClassLoader(cl); + // Register with the main deployer + server.invoke( + new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME), + "addDeployer", + new Object[] {this}, + new String[] {"org.jboss.deployment.DeployerMBean"}); } - catch (Exception e) - { - log.error("problem removing classloader " + cl, e); - } - metadata.setClassLoader(null); - - // Remove the temporary copy - rdi.cleanup(getLog()); - + catch (Exception e) {log.error("Could not register with MainDeployer", e);} } + - private static class RarDeploymentInfo extends ServiceDeploymentInfo + public void stopService() { - public RARMetaData metadata; - - public RarDeploymentInfo(URL key) + try { - super(key); + // Register with the main deployer + server.invoke( + new ObjectName(org.jboss.deployment.MainDeployerMBean.OBJECT_NAME), + "removeDeployer", + new Object[] {this}, + new String[] {"org.jboss.deployment.DeployerMBean"}); } + catch (Exception e) {log.error("Could not register with MainDeployer", e);} + } + + + private ObjectName getServiceControllerName() + throws DeploymentException + { + try { return new ObjectName(ServiceControllerMBean.OBJECT_NAME);} + + catch (Exception e) {throw new DeploymentException ("Couldn't get the ObjectName for the ServiceControllerMBean");} } + // Inner classes ------------------------------------------------- }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
