User: user57
Date: 02/03/01 00:29:57
Modified: src/main/org/jboss/deployment MainDeployer.java
MainDeployerMBean.java
Added: src/main/org/jboss/deployment DeploymentSorter.java
Log:
o Seperated deployment "scanning" from MainDeployer
o Adding DeploymentScanner APIs + default local directory based scanner
o Moved common deployment sorting into DeploymentSorter (a temporary hack)
o Added default scanner at the top of jboss-service.xml, which scans in
a deploy/ directory under the server's home (aka server/default/deploy)
Revision Changes Path
1.13 +41 -443 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MainDeployer.java 28 Feb 2002 07:55:49 -0000 1.12
+++ MainDeployer.java 1 Mar 2002 08:29:57 -0000 1.13
@@ -1,24 +1,28 @@
-/*
- * 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.deployment;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
+
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;
@@ -34,48 +38,36 @@
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.ServerConfigImplMBean;
import org.jboss.util.jmx.MBeanProxy;
/**
- * MainDeployer
- *
* Takes a series of URL to watch, detects changes and calls the appropriate
Deployers
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
*/
public class MainDeployer
extends ServiceMBeanSupport
- implements MainDeployerMBean, Runnable
+ implements MainDeployerMBean
{
/** Deployers **/
private final Set deployers = new HashSet();
- /** Scanned Directories **/
- private final ArrayList directories = new ArrayList();
-
/** I always feel like somebody is watching me, contains DeploymentInfo **/
private final Map deployments = new HashMap();
private final ArrayList deploymentsList = new ArrayList();
- /** Thread running **/
- private boolean running = false;
-
- /** period of scanning **/
- private int period = 5000;
-
/** an increment for tmp files **/
private int id = 0;
- /** Given a flat set of files, this is the order of deployment **/
- private String[] order = { "sar", "service.xml", "rar", "jar", "war", "wsr",
"ear", "zip" };
-
/** The temporary directory for deployments. */
private File tempDir;
@@ -84,97 +76,19 @@
private File tempNativeDir;
- /** The home directory (for dealing with relative file names). */
- private File homeDir;
-
- /** The server home directory (for deploy dir). */
- private File serverHomeDir;
+ private DeploymentSorter sorter = new DeploymentSorter();
/**
- * variables <code>nativePrefix</code> and <code>nativeSuffix</code> hold the
- * prefix and suffix of native libraries on this system. They are determined by
- * examining the result of System.mapLibraryName("XxX").
- *
+ * Holds the native library <em>prefix</em> for this system.
+ * Determined by examining the result of System.mapLibraryName("XxX").
*/
private String nativePrefix;
- private String nativeSuffix;
-
- public void setPeriod(int period) {
- this.period = period;
- }
-
- public int getPeriod()
- {
- return period;
- }
-
-
- public boolean getScan()
- {
- return running;
- }
-
- public void setScan(boolean scan)
- {
- running = scan;
- }
- /**
- * Directory get set logic, these are "scanning" directories
- * on the local filesystem
+ /**
+ * Holds the native library <em>suffix</em> for this system.
+ * Determined by examining the result of System.mapLibraryName("XxX").
*/
- public void setDirectories(String urlList) throws MalformedURLException
- {
- StringTokenizer urls = new StringTokenizer(urlList, ",");
-
- // Add URLs to list
- while (urls.hasMoreTokens())
- {
- addDirectory(urls.nextToken().trim()) ;
- }
- }
-
- public void addDirectory(String url) throws MalformedURLException
- {
- // We are dealing with a relative path URL
- if (!( url.startsWith("file:") || url.startsWith("http:"))) {
- addDirectory(new URL(homeDir.toURL(), url));
- }
- else {
- addDirectory(new URL(url));
- }
- }
-
- public void addDirectory(URL url) {
- if (!directories.contains(url)) {
- directories.add(url);
-
- log.debug("Added directory scan "+url);
- }
- }
-
- public void removeDirectory(String url) throws MalformedURLException
- {
- // We are dealing with a relative path URL
- if (!(url.startsWith("file:") || url.startsWith("http:"))) {
- removeDirectory(new URL(homeDir.toURL(), url));
- }
- else {
- removeDirectory(new URL(url));
- }
- }
-
- public void removeDirectory(URL url)
- {
- int index = directories.lastIndexOf(url);
- if (index != -1) {
- directories.remove(index);
-
- if (log.isDebugEnabled()) {
- log.debug("Removed directory scan " + url);
- }
- }
- }
+ private String nativeSuffix;
public Collection listDeployed()
{
@@ -203,69 +117,28 @@
// ServiceMBeanSupport overrides ---------------------------------
- /**
- * Gets the ObjectName attribute of the MainDeployer object
- *
- * @param server Description of Parameter
- * @param name Description of Parameter
- * @return The ObjectName value
- * @exception MalformedObjectNameException Description of Exception
- */
protected ObjectName getObjectName(MBeanServer server, ObjectName name)
throws MalformedObjectNameException
{
- this.server = server;
return name == null ? OBJECT_NAME : name;
}
- protected void createService()
- throws Exception
+ protected void createService() throws Exception
{
// watch the deploy directory, it is a set so multiple adds
// (start/stop) only one entry is present
// get the temporary directory to use
- tempDir = new
File((File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir"),
- "deploy");
-
- tempNativeDir = new
File((File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir"),
- "native");
-
- //used in isWatched
- tempDirString = tempDir.toURL().toString();
- // get the home directory
- homeDir = (File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME,
"HomeDir");
+ File serverTempDir = (File)
+ server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "ServerTempDir");
- // get the server home directory
- serverHomeDir = (File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME,
"ServerHomeDir");
+ tempDir = new File(serverTempDir, "deploy");
+ tempNativeDir = new File(serverTempDir, "native");
- // Watch in our standard directory.
- File file = new File(serverHomeDir, "deploy");
- addDirectory(file.toURL());
- }
-
- /**
- * Get the local state data directory from the server configuration.
- */
- protected void startService()
- throws Exception
- {
- //just so we can time startup...
- scan();
-
- // Start auto deploy thread
- running = true;
-
- // Kick off the thread
- new Thread(this, "MainDeployer").start();
+ // used in isWatched
+ tempDirString = tempDir.toURL().toString();
}
- protected void stopService()
- {
- // Stop auto deploy thread
- running = false;
- }
-
/**
* The <code>shutdown</code> method undeploys all deployed packages in
* reverse order of their deployement.
@@ -273,11 +146,11 @@
*/
public void shutdown()
{
- running = false;
- //if we shutdown in the middle of a scan, it still might be possible that we
try to redeploy
- //things we are busy killing...
+ // if we shutdown in the middle of a scan, it still might be possible that we
try to redeploy
+ // things we are busy killing...
int deployCounter = 0;
- //undeploy everything in sight
+
+ // undeploy everything in sight
List copyDeployments = new ArrayList(deploymentsList);
for (ListIterator i = copyDeployments.listIterator(copyDeployments.size());
i.hasPrevious(); )
{
@@ -289,74 +162,13 @@
catch (Exception e)
{
log.info("exception trying to undeploy during shutdown: ", e);
- } // end of try-catch
-
- } // end of for ()
- log.info("Undeployed " + deployCounter + " deployed packages");
- }
-
- /**
- * Main processing method for the MainDeployer object
- */
- public void run()
- {
- do
- {
- // Sleep
- try
- {
- Thread.sleep(period);
- }
- catch (Exception e)
- {
- log.debug("interrupted");
}
- scan();
- }
- while (running);
- }
-
- public void scan()
- {
- // Scan directories for new deployments
- for (Iterator newDeployments = scanNew().listIterator();
newDeployments.hasNext();)
- {
- URL deployable = (URL) newDeployments.next();
- try
- {
- deploy(deployable);
- }
- catch (Throwable t)
- {
- log.error("Could not deploy: " + deployable, t);
- } // end of try-catch
}
- // Undeploy the removed ones
- for (Iterator removed = scanRemoved().listIterator(); removed.hasNext();)
- {
- DeploymentInfo di = (DeploymentInfo) removed.next();
- // if the url is a file that doesn't exist, it was removed -> undeploy
- undeploy(di);
- }
-
- // Undeploy and redeploy the modified ones
- for (Iterator modified = scanModified().listIterator(); modified.hasNext();)
- {
- DeploymentInfo di = (DeploymentInfo) modified.next();
- undeploy(di);
- try
- {
- deploy(di);
- }
- catch (Throwable t)
- {
- log.error("Could not deploy: " + di.url, t);
- } // end of try-catch
- }
+ log.info("Undeployed " + deployCounter + " deployed packages");
}
-
+
public void undeploy(String url)
{
try
@@ -405,10 +217,6 @@
di.deployer.stop(di);
}
}
- catch (Exception e)
- {
- log.error("Undeployment failed: " + di.url, e);
- }
catch (Throwable t)
{
log.error("Undeployment failed: " + di.url, t);
@@ -533,7 +341,7 @@
* set up classloaders, and identify the deployer for the package.
*
* @param deployment a <code>DeploymentInfo</code> value
- * @exception DeploymentException if an error occurs
+ * @throws DeploymentException if an error occurs
*/
private void init(DeploymentInfo deployment) throws DeploymentException
{
@@ -559,7 +367,7 @@
// create subdeployments as needed
unpackSubPackages(deployment);
log.debug("found " + deployment.subDeployments.size() + " subpackages of "
+ deployment.url);
- for (Iterator lt =
sortDeployments(deployment.subDeployments).listIterator(); lt.hasNext();)
+ for (Iterator lt = sorter.sort(deployment.subDeployments).listIterator();
lt.hasNext();)
{
init((DeploymentInfo) lt.next());
}
@@ -595,14 +403,14 @@
* and the proxy bound into jndi.
*
* @param deployment a <code>DeploymentInfo</code> value
- * @exception DeploymentException if an error occurs
+ * @throws DeploymentException if an error occurs
*/
private void create(DeploymentInfo deployment) throws DeploymentException
{
log.debug("create step for deployment " + deployment.url);
try
{
- for (Iterator lt =
sortDeployments(deployment.subDeployments).listIterator(); lt.hasNext();)
+ for (Iterator lt = sorter.sort(deployment.subDeployments).listIterator();
lt.hasNext();)
{
create((DeploymentInfo) lt.next());
}
@@ -630,14 +438,14 @@
* for instance, ejb links are set up here.
*
* @param deployment a <code>DeploymentInfo</code> value
- * @exception DeploymentException if an error occurs
+ * @throws DeploymentException if an error occurs
*/
private void start(DeploymentInfo deployment) throws DeploymentException
{
log.debug("start step for deployment " + deployment.url);
try
{
- for (Iterator lt =
sortDeployments(deployment.subDeployments).listIterator(); lt.hasNext();)
+ for (Iterator lt = sorter.sort(deployment.subDeployments).listIterator();
lt.hasNext();)
{
start((DeploymentInfo) lt.next());
}
@@ -662,7 +470,6 @@
}
-
public void findDeployer(DeploymentInfo sdi)
{
boolean debug = log.isDebugEnabled();
@@ -693,165 +500,6 @@
}
}
-
- /**
- * ScanNew scans the directories that are given to it and returns a
- * Set with the new deployments
- */
- protected ArrayList scanNew()
- {
- try
- {
- HashSet newDeployments = new HashSet();
- boolean trace = log.isTraceEnabled();
-
- // Scan directories
- for (Iterator iterator = directories.listIterator(); iterator.hasNext();)
- {
- File dir = new File(((URL) iterator.next()).getFile());
- if (!dir.exists()) {
- log.warn("Skipping non-existant directory: " + dir);
- continue;
- }
-
- if (trace)
- {
- log.trace("Scanning directory: " + dir);
- }
-
- File[] files = dir.listFiles();
- if (files == null)
- {
- log.error("we have a problem null files in directory; should not
happen");
- continue;
- }
-
- for (int i = 0; i < files.length; i++)
- {
- if( trace )
- {
- log.trace("Checking deployment file: "+files[i]);
- }
- // It is a new file
- if (!isDeployed(files[i].toURL()))
- {
- newDeployments.add(files[i].toURL());
- }
- }
- }
-
- return sortURLs(newDeployments);
- }
- catch (Exception e)
- {
- log.error("operation failed", e);
- return null;
- }
- }
-
- /**
- * scans the existing deployments and return a
- * Set with the removed deployments
- */
- protected List scanRemoved()
- {
- HashSet removed = new HashSet();
-
- if (log.isTraceEnabled())
- {
- log.trace("Scanning installed deployments");
- }
- // People already deployed, scan for modifications
- synchronized (deploymentsList)
- {
- for (Iterator it = deploymentsList.listIterator(); it.hasNext(); )
- {
- DeploymentInfo deployment = (DeploymentInfo) it.next();
- if (deployment.url.getProtocol().startsWith("file"))
- {
- File theFile = new File(deployment.url.getFile());
- if (!theFile.exists())
- {
- removed.add(deployment);
- }
-
- } // end of if ()
- else
- {
- try
- {
- deployment.url.openConnection();
- }
- catch (java.io.IOException ioe)
- {
- removed.add(deployment);
- } // end of try-catch
- }
- }
- }
- return sortDeployments(removed);
- }
-
- /**
- * scanModified scans the existing deployments and return a
- * Set with the modified deployments
- */
- protected ArrayList scanModified()
- {
- HashSet modified = new HashSet();
-
- if (log.isTraceEnabled())
- {
- log.trace("Scanning installed deployments");
- }
- // People already deployed, scan for modifications
- synchronized (deploymentsList)
- {
- for (Iterator it = deploymentsList.listIterator(); it.hasNext(); )
- {
- DeploymentInfo deployment = (DeploymentInfo) it.next();
-
- long lastModified = 0;
-
- // if noone told us what to watch, we'll look for something...
- if (deployment.watch == null)
- {
- deployment.watch = deployment.url;
- }
- // Get lastModified of file from file system
- if (deployment.watch.getProtocol().startsWith("file"))
- {
- File theFile = new File(deployment.watch.getFile());
- if (theFile.exists())
- {
- lastModified = theFile.lastModified();
- }
- }
-
- // Use URL connection to get lastModified on http
- else
- {
- try
- {
- lastModified =
deployment.watch.openConnection().getLastModified();
- }
- catch (java.io.IOException ioe)
- {
- //ignored, watch is missing.
- } // end of try-catch
- }
-
- // Check the record in the DeploymentInfo against the physical one
- if (deployment.lastDeployed < lastModified)
- {
- modified.add(deployment);
- }
- }
- }
- return sortDeployments(modified);
- }
-
-
/**
* extractPackages
*
@@ -1177,56 +825,6 @@
out.close();
in.close();
- }
-
- public ArrayList sortURLs(Set urls)
- {
- ArrayList list = new ArrayList(urls.size());
-
- for (int i = 0 ; i < order.length ; i++)
- {
- for (Iterator it = urls.iterator(); it.hasNext();)
- {
- URL url = (URL) it.next();
-
- if (url.toString().endsWith(order[i]))
- {
- list.add(url); it.remove();
- }
- }
- }
-
- // Unknown types deployed at the end
- list.addAll(urls);
-
- return list;
- }
-
- public ArrayList sortDeployments(Set urls)
- {
- //sort a copy, so we don't kill the original!
- ArrayList list = new ArrayList(urls.size());
- Set copy = new HashSet(urls);
- for (int i = 0 ; i < order.length ; i++)
- {
- for (Iterator it = copy.iterator(); it.hasNext();)
- {
- DeploymentInfo di = (DeploymentInfo) it.next();
-
- if (di.url.toString().endsWith(order[i]))
- {
- list.add(di); it.remove();
- }
- }
- }
-
- // Unknown types deployed at the end
- list.addAll(copy);
- if (log.isTraceEnabled())
- {
- log.trace("about to do something with: " + list);
- } // end of if ()
- return list;
}
public boolean isDeployed(String url)
1.3 +11 -27
jboss-system/src/main/org/jboss/deployment/MainDeployerMBean.java
Index: MainDeployerMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jboss-system/src/main/org/jboss/deployment/MainDeployerMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MainDeployerMBean.java 26 Feb 2002 05:15:02 -0000 1.2
+++ MainDeployerMBean.java 1 Mar 2002 08:29:57 -0000 1.3
@@ -28,14 +28,15 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Toby Allsopp</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.2 $
- * <p><b>20011223 marc fleury:</b>
- * <ul>
- * <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
- * <li>add/Removedeployer, dynamically add a new deployer
- * <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
- * <li>Rewrite
- * </ul>
+ * @version <tt>$Revision: 1.3 $</tt>
+ *
+ * <p><b>20011223 marc fleury:</b>
+ * <ul>
+ * <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
+ * <li>add/Removedeployer, dynamically add a new deployer
+ * <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
+ * <li>Rewrite
+ * </ul>
*/
public interface MainDeployerMBean
extends ServiceMBean
@@ -47,19 +48,8 @@
/** individual URLs for dynamically deploying **/
void deploy(String URL);
void undeploy(String URL);
-
- void deploy(DeploymentInfo sdi)
- throws DeploymentException;
-
- public void undeploy(DeploymentInfo sdi)
- throws DeploymentException;
-
-
- /** Dynamically add directories to scan **/
- void addDirectory(String url) throws MalformedURLException;
- void addDirectory(URL url);
- void removeDirectory(String url) throws MalformedURLException;
- void removeDirectory(URL url);
+ void deploy(DeploymentInfo sdi) throws DeploymentException;
+ public void undeploy(DeploymentInfo sdi) throws DeploymentException;
/** Add the capacity to dynamically add a deployer to the list **/
void addDeployer(DeployerMBean deployer);
@@ -70,12 +60,6 @@
Collection listDeployers();
- /** Get set scan-period**/
- void setScan( boolean scan);
- boolean getScan();
- void setPeriod(int period);
- int getPeriod();
-
/** undeploys all packages **/
void shutdown();
}
1.1 jboss-system/src/main/org/jboss/deployment/DeploymentSorter.java
Index: DeploymentSorter.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.deployment;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.File; // HACK
import org.jboss.util.NullArgumentException;
/**
* A helper class for sorting deployments.
*
* @version <tt>$Revision: 1.1 $</tt>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
*/
public class DeploymentSorter
{
/** The default order for sorting deployments. */
public static final String[] DEFAULT_SUFFIX_ORDER = {
"sar", "service.xml", "rar", "jar", "war", "wsr", "ear", "zip"
};
protected String[] suffixOrder;
public DeploymentSorter(String[] suffixOrder)
{
if (suffixOrder == null)
throw new NullArgumentException("suffixOrder");
this.suffixOrder = suffixOrder;
}
public DeploymentSorter()
{
this(DEFAULT_SUFFIX_ORDER);
}
/**
* Returns a sorted list given the set of deployments based on {@link
#suffixOrder}.
*/
public List sort(final Set deployments)
{
//sort a copy, so we don't kill the original!
ArrayList list = new ArrayList(deployments.size());
Set copy = new HashSet(deployments);
for (int i = 0 ; i < suffixOrder.length ; i++)
{
for (Iterator it = copy.iterator(); it.hasNext();)
{
DeploymentInfo di = (DeploymentInfo)it.next();
if (di.url.toString().endsWith(suffixOrder[i]))
{
list.add(di);
it.remove();
}
}
}
// Unknown types deployed at the end
list.addAll(copy);
return list;
}
/**
* Returns a sorted list given the set of files based on {@link #suffixOrder}.
*
* <p>HACK, does not belong here, sould use collection framework for sorting
* this as well as deployments... for now this was simplest
*/
public List sortFiles(Set files)
{
ArrayList list = new ArrayList(files.size());
for (int i = 0 ; i < suffixOrder.length ; i++)
{
for (Iterator it = files.iterator(); it.hasNext();)
{
File file = (File)it.next();
if (file.toString().endsWith(suffixOrder[i]))
{
list.add(file);
it.remove();
}
}
}
// Unknown types deployed at the end
list.addAll(files);
return list;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development