User: d_jencks
Date: 02/03/04 21:35:37
Modified: src/main/org/jboss/deployment DeploymentInfo.java
MainDeployer.java
Added: src/main/org/jboss/deployment JARDeployer.java
Removed: src/main/org/jboss/deployment MainDeployerMBean.java
Log:
fix for bug 525445. Added JARDeployer that will only deploy jars or directories
with no WEB-INF directory and no xml files in META-INF. Modified MainDeployer to
require a deployer, and keep a list of packages waiting for a deployer.
MainDeployerMBean is now generated by xdoclet.
Revision Changes Path
1.3 +3 -1 jboss-system/src/main/org/jboss/deployment/DeploymentInfo.java
Index: DeploymentInfo.java
===================================================================
RCS file:
/cvsroot/jboss/jboss-system/src/main/org/jboss/deployment/DeploymentInfo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DeploymentInfo.java 26 Feb 2002 00:22:55 -0000 1.2
+++ DeploymentInfo.java 5 Mar 2002 05:35:37 -0000 1.3
@@ -53,7 +53,9 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Schulze</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Christoph G. Jung</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.2 $ <p>
+ * @version $Revision: 1.3 $ <p>
+ *
+ * @todo implement type-safe enum for status.
*
* <b>20011211 marc fleury:</b>
* <ul>
1.16 +238 -47 jboss-system/src/main/org/jboss/deployment/MainDeployer.java
Index: MainDeployer.java
===================================================================
RCS file:
/cvsroot/jboss/jboss-system/src/main/org/jboss/deployment/MainDeployer.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MainDeployer.java 5 Mar 2002 03:06:57 -0000 1.15
+++ MainDeployer.java 5 Mar 2002 05:35:37 -0000 1.16
@@ -9,20 +9,22 @@
package org.jboss.deployment;
+
+
+
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
@@ -38,38 +40,44 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.system.server.ServerConfig;
import org.jboss.system.server.ServerConfigLocator;
+import org.jboss.util.Counter;
import org.jboss.util.jmx.MBeanProxy;
import org.jboss.util.stream.Streams;
-import org.jboss.util.Counter;
+import java.util.LinkedList;
/**
* The main/primary component for deployment.
+ * MainDeployerMBean is now generated by xdoclet.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.15 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
+ * @version $Revision: 1.16 $
+ * @jmx:mbean name="jboss.system:service=MainDeployer"
+ * extends="org.jboss.system.ServiceMBean"
*/
public class MainDeployer
extends ServiceMBeanSupport
implements MainDeployerMBean
{
/** Deployers **/
- private final Set deployers = new HashSet();
+ private final LinkedList deployers = new LinkedList();
/** A Map of URL -> DeploymentInfo */
private final Map deploymentMap = new HashMap();
- /** A list of all deployments. */
+ /** A list of all deployments that have deployers. */
private final ArrayList deploymentList = new ArrayList();
+ /** A list of all deployments that do not have deployers. */
+ private final List waitingDeployments = new ArrayList();
+
/** an increment for tmp files **/
private final Counter id = Counter.makeSynchronized(new Counter(0));
@@ -105,6 +113,13 @@
super();
}
+ /**
+ * The <code>listDeployed</code> method returns a collection of DeployemtInfo
+ * objects for the currently deployed packages.
+ *
+ * @return a <code>Collection</code> value
+ * @jmx:managed-operation
+ */
public Collection listDeployed()
{
synchronized (deploymentList)
@@ -113,25 +128,88 @@
}
}
+ /**
+ * The <code>listWaitingForDeployer</code> method returns a collection
+ * of the packages that currently have no identified deployer.
+ *
+ * @return a <code>Collection</code> value
+ * @jmx:managed-operation
+ */
+ public Collection listWaitingForDeployer()
+ {
+ synchronized (waitingDeployments)
+ {
+ return new ArrayList(waitingDeployments);
+ }
+ }
+
+ /**
+ * The <code>addDeployer</code> method registers a deployer with the main
deployer.
+ * Any waiting packages are tested to see if the new deployer will deploy them.
+ *
+ * @param deployer a <code>DeployerMBean</code> value
+ * @jmx:managed-operation
+ */
public void addDeployer(final DeployerMBean deployer)
{
if (log.isDebugEnabled()) {
log.debug("Adding deployer: " + deployer);
}
- deployers.add(deployer);
+ synchronized(deployers)
+ {
+ deployers.addFirst(deployer);
+ }
+ synchronized (waitingDeployments)
+ {
+ List copy = new ArrayList(waitingDeployments);
+ waitingDeployments.clear();
+ for (Iterator i = copy.iterator(); i.hasNext();)
+ {
+ try
+ {
+ deploy((DeploymentInfo)i.next());
+ }
+ catch (DeploymentException e)
+ {
+ log.error("DeploymentException while trying to deploy a package with
a new deployer", e);
+ } // end of try-catch
+
+ } // end of for ()
+
+ }
}
+ /**
+ * The <code>removeDeployer</code> method unregisters a deployer with the
MainDeployer.
+ * Currently deployed packages deployed with this deployer are not undeployed.
+ *
+ * @param deployer a <code>DeployerMBean</code> value
+ * @jmx:managed-operation
+ */
public void removeDeployer(final DeployerMBean deployer)
{
if (log.isDebugEnabled()) {
log.debug("Removing deployer: " + deployer);
}
- deployers.remove(deployer);
+ synchronized(deployers)
+ {
+ deployers.remove(deployer);
+ }
}
+ /**
+ * The <code>listDeployers</code> method returns a collection of ObjectNames of
+ * deployers registered with the MainDeployer.
+ *
+ * @return a <code>Collection</code> value
+ * @jmx:managed-operation
+ */
public Collection listDeployers()
{
- return new ArrayList(deployers);
+ synchronized(deployers)
+ {
+ return new ArrayList(deployers);
+ }
}
@@ -143,6 +221,11 @@
return name == null ? OBJECT_NAME : name;
}
+ /**
+ * The <code>createService</code> method is one of the ServiceMBean lifecyle
operations.
+ * (no jmx tag needed from superinterface)
+ * @exception Exception if an error occurs
+ */
protected void createService() throws Exception
{
// watch the deploy directory, it is a set so multiple adds
@@ -163,6 +246,7 @@
* The <code>shutdown</code> method undeploys all deployed packages in
* reverse order of their deployement.
*
+ * @jmx:managed-operation
*/
public void shutdown()
{
@@ -189,6 +273,12 @@
log.info("Undeployed " + deployCounter + " deployed packages");
}
+ /**
+ * The <code>undeploy</code> method undeploys a package identified by a URL
+ *
+ * @param url an <code>URL</code> value
+ * @jmx:managed-operation
+ */
public void undeploy(URL url)
{
try
@@ -206,12 +296,27 @@
}
}
+ /**
+ * The <code>undeploy</code> method undeploys a package identified by a string
+ * representation of a URL.
+ *
+ * @param urlspec a <code>String</code> value
+ * @exception MalformedURLException if an error occurs
+ * @jmx:managed-operation
+ */
public void undeploy(String urlspec) throws MalformedURLException
{
undeploy(new URL(urlspec));
}
+ /**
+ * The <code>undeploy</code> method undeploys a package represented by a
+ * DeploymentInfo object.
+ *
+ * @param di a <code>DeploymentInfo</code> value
+ * @jmx:managed-operation
+ */
public void undeploy(DeploymentInfo di)
{
log.info("Undeploying "+di.url);
@@ -219,6 +324,11 @@
destroy(di);
}
+ /**
+ * The <code>stop</code> method is the first internal step of undeployment
+ *
+ * @param di a <code>DeploymentInfo</code> value
+ */
private void stop(DeploymentInfo di)
{
// First remove all sub-deployments
@@ -248,6 +358,11 @@
}
}
+ /**
+ * The <code>destroy</code> method is the second and final internal undeployment
step.
+ *
+ * @param di a <code>DeploymentInfo</code> value
+ */
private void destroy(DeploymentInfo di)
{
// First remove all sub-deployments
@@ -299,6 +414,14 @@
}
}
+ /**
+ * The <code>deploy</code> method deploys a package identified by a
+ * string representation of a URL.
+ *
+ * @param urlspec a <code>String</code> value
+ * @exception MalformedURLException if an error occurs
+ * @jmx:managed-operation
+ */
public void deploy(String urlspec) throws MalformedURLException
{
URL url;
@@ -313,6 +436,12 @@
deploy(url);
}
+ /**
+ * The <code>deploy</code> method deploys a package identified by a URL
+ *
+ * @param url an <code>URL</code> value
+ * @jmx:managed-operation
+ */
public void deploy(URL url)
{
DeploymentInfo sdi = getDeployment(url);
@@ -331,6 +460,13 @@
}
}
+ /**
+ * The <code>deploy</code> method deploys a package represented by a
DeploymentInfo object.
+ *
+ * @param deployment a <code>DeploymentInfo</code> value
+ * @exception DeploymentException if an error occurs
+ * @jmx:managed-operation
+ */
public void deploy(DeploymentInfo deployment)
throws DeploymentException
{
@@ -340,40 +476,55 @@
return;
}
log.info("Starting deployment of package: " + deployment.url);
- init(deployment);
- create(deployment);
- start(deployment);
- log.info("Successfully completed deployment of package: " + deployment.url);
+ if (init(deployment))
+ {
+ create(deployment);
+ start(deployment);
+ log.info("Successfully completed deployment of package: " +
deployment.url);
+ } // end of if ()
+ else
+ {
+ log.info("Deployment of package: " + deployment.url + " is waiting for an
appropriate deployer.");
+ } // end of else
}
/**
- * The <code>init</code> method is to copy the code if necessary,
+ * The <code>init</code> method is the first internal deployment step.
+ * The tasks are to copy the code if necessary,
* set up classloaders, and identify the deployer for the package.
*
* @param deployment a <code>DeploymentInfo</code> value
* @throws DeploymentException if an error occurs
*/
- private void init(DeploymentInfo deployment) throws DeploymentException
+ private boolean init(DeploymentInfo deployment) throws DeploymentException
{
log.debug("Starting deployment (init step) of package at: " + deployment.url);
try
{
// Create a local copy of that File, the sdi keeps track of the copy
directory
- makeLocalCopy(deployment);
+ if (deployment.localUrl == null)
+ {
+ makeLocalCopy(deployment);
+ // initialize the unified classloaders for this deployment
+ deployment.createClassLoaders();
+ } // end of if ()
- // initialize the unified classloaders for this deployment
- deployment.createClassLoaders();
// What deployer is able to deploy this file
findDeployer(deployment);
- if(deployment.deployer != null)
+ if(deployment.deployer == null)
{
- deployment.deployer.init(deployment);
+ synchronized (waitingDeployments)
+ {
+ waitingDeployments.add(deployment);
+ }
+ return false;
}
-
+ //we have the deployer, continue deployment.
+ deployment.deployer.init(deployment);
// create subdeployments as needed
unpackSubPackages(deployment);
@@ -406,10 +557,12 @@
}
}
}
+ return true;
}
/**
- * The <code>create</code> method should set up all information not
+ * The <code>create</code> method is the second internal deployment step.
+ * It should set up all information not
* requiring other components. for instance, the ejb Container is created,
* and the proxy bound into jndi.
*
@@ -447,7 +600,8 @@
}
/**
- * The <code>start</code> method sets up relationships between components.
+ * The <code>start</code> method is the third and final internal deployment step.
+ * The purpose is to set up relationships between components.
* for instance, ejb links are set up here.
*
* @param deployment a <code>DeploymentInfo</code> value
@@ -485,7 +639,13 @@
}
- public void findDeployer(DeploymentInfo sdi)
+ /**
+ * The <code>findDeployer</code> method attempts to find a deployer for the
DeploymentInfo
+ * supplied as a parameter.
+ *
+ * @param sdi a <code>DeploymentInfo</code> value
+ */
+ private void findDeployer(DeploymentInfo sdi)
{
boolean debug = log.isDebugEnabled();
@@ -496,20 +656,22 @@
// To deploy directories of beans one should just name the directory
// mybean.ear/bla...bla, so that the directory gets picked up by the right
deployer
//
- for (Iterator iterator = deployers.iterator(); iterator.hasNext(); )
+ synchronized(deployers)
{
- DeployerMBean deployer = (DeployerMBean) iterator.next();
- if (deployer.accepts(sdi))
+ for (Iterator iterator = deployers.iterator(); iterator.hasNext(); )
{
- sdi.deployer = deployer;
- if (debug)
+ DeployerMBean deployer = (DeployerMBean) iterator.next();
+ if (deployer.accepts(sdi))
{
- log.debug("using deployer "+deployer);
+ sdi.deployer = deployer;
+ if (debug)
+ {
+ log.debug("using deployer "+deployer);
+ }
+ return;
}
- return;
}
}
-
if (debug)
{
log.debug("No deployer found for url: " + sdi.url);
@@ -670,7 +832,14 @@
}
- public void parseManifestLibraries(DeploymentInfo sdi) throws DeploymentException
+ /**
+ * The <code>parseManifestLibraries</code> method looks into the manifest for
classpath
+ * goo, and tries to deploy referenced packages.
+ *
+ * @param sdi a <code>DeploymentInfo</code> value
+ * @exception DeploymentException if an error occurs
+ */
+ private void parseManifestLibraries(DeploymentInfo sdi) throws
DeploymentException
{
boolean debug = log.isDebugEnabled();
@@ -736,9 +905,9 @@
* @todo FIXME: $JBOSS_HOME/tmp/deploy is not a valid reference.
*
* @return a File object representing the downloaded module
- * @throws IOException
+ * @throws DeploymentException
*/
- public void makeLocalCopy(DeploymentInfo sdi)
+ private void makeLocalCopy(DeploymentInfo sdi)
throws DeploymentException
{
try
@@ -819,17 +988,46 @@
in.close();
}
+ /**
+ * The <code>isDeployed</code> method tells you if a package identified by a
string
+ * representation of a URL is currently deployed.
+ *
+ * @param url a <code>String</code> value
+ * @return a <code>boolean</code> value
+ * @exception MalformedURLException if an error occurs
+ * @jmx:managed-operation
+ */
public boolean isDeployed(String url)
throws MalformedURLException
{
return isDeployed(new URL(url));
}
+ /**
+ * The <code>isDeployed</code> method tells you if a packaged identified by
+ * a URL is deployed.
+ * @todo Implement type-safe enum for di.status.
+ * @param url an <code>URL</code> value
+ * @return a <code>boolean</code> value
+ * @jmx:managed-operation
+ */
public boolean isDeployed(URL url)
{
- return getDeployment(url) != null;
+ DeploymentInfo di = getDeployment(url);
+ if (di == null)
+ {
+ return false;
+ } // end of if ()
+ return "Deployed".equals(di.status);
}
+ /**
+ * The <code>getDeployment</code> method returns the DeploymentInfo
+ * object for the URL supplied.
+ *
+ * @param url an <code>URL</code> value
+ * @return a <code>DeploymentInfo</code> value
+ */
public DeploymentInfo getDeployment(URL url)
{
synchronized (deploymentList)
@@ -838,12 +1036,5 @@
}
}
- public DeploymentInfo removeDeployment(DeploymentInfo di)
- {
- synchronized (deploymentList)
- {
- return (DeploymentInfo) deploymentMap.remove(di.url);
- }
- }
}
1.1 jboss-system/src/main/org/jboss/deployment/JARDeployer.java
Index: JARDeployer.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
*/
package org.jboss.deployment;
import java.io.File;
import java.io.FileFilter;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.jboss.system.ServiceMBeanSupport;
/**
* JARDeployer.java
* This deployer exists to prevent deployment of packages whose deployers are not yet
* deployed. It will accept only jar/zip format files or directories that don't
* have a META-INF directory, or if they do, don't have any .xml files there. It
* assumes any package with a META-INF/*.xml file needs a specialized deployer.
*
* JARDeployerMBean.java is generated by XDoclet.
*
* @todo find a way to scan just the META-INF files, not the whole jar.
*
* Created: Mon Mar 4 12:58:19 2002
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
* @version
* @jmx:mbean name="jboss.system:service=JARDeployer"
* extends="org.jboss.deployment.DeployerMBean"
*/
public class JARDeployer
extends ServiceMBeanSupport
implements JARDeployerMBean
{
public JARDeployer ()
{
}
//ServiceMBeanSupport methods
protected ObjectName getObjectName(MBeanServer server, ObjectName name)
throws javax.management.MalformedObjectNameException
{
return OBJECT_NAME;
}
protected void startService() throws Exception
{
try
{
// Register with the main deployer
server.invoke(
org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"addDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
}
catch (Exception e) {log.error("Could not register with MainDeployer", e);}
log.info("JarDeployer started");
}
protected void stopService()
{
log.info("JARDeployer stopped");
/*
//This can't be run right now since the JARDeployer is started before the
MainDeployer,
//so the MainDeployer is stopped first... so the JARDeployer can't unregister.
try
{
// Unregister with the main deployer
server.invoke(
org.jboss.deployment.MainDeployerMBean.OBJECT_NAME,
"removeDeployer",
new Object[] {this},
new String[] {"org.jboss.deployment.DeployerMBean"});
}
catch (Exception e) {log.error("Could not unregister with MainDeployer", e);}
*/
}
//DeployerMBean implementation
/**
* The <code>accepts</code> method is called by MainDeployer to
* determine which deployer is suitable for a DeploymentInfo.
*
* @todo find a way to scan just the META-INF files, not the whole jar.
*
* @param sdi a <code>DeploymentInfo</code> value
* @return a <code>boolean</code> value
*/
public boolean accepts(DeploymentInfo di)
{
boolean trace = log.isTraceEnabled();
try
{
if (di.isXML)
{
return false;
} // end of if ()
URL wdDir = di.localCl.getResource("WEB-INF/");
if (wdDir != null)
{
return false;
} // end of if ()
URL ddDir = di.localCl.getResource("META-INF/");
if (ddDir == null)
{
log.debug("no META-INF or WEB-INF found, this is for us");
return true;
}
if (ddDir.getProtocol().equals("file"))
{
log.debug("file protocol");
File file = new File(ddDir.getFile());
if (!file.exists())
{
//this is redundant, isn't it?
log.info("file protocol, but file doesn't exist");
return true;
} // end of if ()
File[] entries = file.listFiles(
new FileFilter() {
public boolean accept(File pathname)
{
return pathname.toString().endsWith(".xml");
}
});
log.debug("file protocol, entries.length " + entries.length);
return entries.length == 0;
} // end of if ()
else if (ddDir.getProtocol().equals("jar") ||
ddDir.getProtocol().equals("njar"))
{
//trying to open ddDir as a jarFile seems to result in listing
//the entire contents of the JRE!!!
log.trace("jar or njar protocol: " + ddDir.getProtocol());
JarFile jarFile =null;
String jarURLString = "njar:"+di.localUrl.toString()+"^/";
try
{
URL jarURL = new URL(jarURLString);
URLConnection con = jarURL.openConnection();
JarURLConnection jarConn = (JarURLConnection)con;
jarFile = jarConn.getJarFile();
}
catch (Exception e)
{
log.warn("looking inside jar failed; ignoring", e);
return false;
}
for (Enumeration e = jarFile.entries(); e.hasMoreElements();)
{
JarEntry entry = (JarEntry)e.nextElement();
String name = entry.getName();
if (trace)
{
log.info("looking at entry: " + name);
} // end of if ()
if (name.startsWith("META-INF/") && name.endsWith(".xml"))
{
return false;
} // end of if ()
} // end of for
log.debug("no xmls found");
return true;
} // end of if ()
else
{
log.debug("unrecognized protocol");
} // end of else
return false;
}
catch (Exception e)
{
return false;
}
}
/**
* The <code>init</code> method lets the deployer set a few properties
* of the DeploymentInfo, such as the watch url.
*
* @param sdi a <code>DeploymentInfo</code> value
*/
public void init(DeploymentInfo sdi)
{
}
/**
* Set up the components of the deployment that do not
* refer to other components
*
* @param sdi a <code>DeploymentInfo</code> value
*/
public void create(DeploymentInfo sdi)
{
}
/**
* The <code>start</code> method sets up relationships with other components.
*
* @param sdi a <code>DeploymentInfo</code> value
*/
public void start(DeploymentInfo sdi)
{
}
/**
* The <code>stop</code> method removes relationships between components.
*
* @param sdi a <code>DeploymentInfo</code> value
*/
public void stop(DeploymentInfo sdi)
{
}
/**
* The <code>destroy</code> method removes individual components
*
* @param sdi a <code>DeploymentInfo</code> value
*/
public void destroy(DeploymentInfo sdi)
{
}
}// JARDeployer
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development