User: user57
Date: 02/03/02 00:40:36
Modified: src/main/org/jboss/deployment MainDeployer.java
Log:
o Changed deployments to deploymentMap for clarity, deploymentsList to
deploymentList for consistency.
o Using Counter helper object instead of handrolled
o Using Streams helper instead of handrolled
o Cleaned up parent file detection
Revision Changes Path
1.14 +94 -108 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MainDeployer.java 1 Mar 2002 08:29:57 -0000 1.13
+++ MainDeployer.java 2 Mar 2002 08:40:36 -0000 1.14
@@ -12,8 +12,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-
+import java.io.BufferedOutputStream;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -44,15 +44,18 @@
import javax.management.ObjectName;
import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.system.server.ServerConfigImplMBean;
+import org.jboss.system.server.ServerConfig;
+import org.jboss.system.server.ServerConfigLocator;
import org.jboss.util.jmx.MBeanProxy;
+import org.jboss.util.stream.Streams;
+import org.jboss.util.Counter;
/**
- * Takes a series of URL to watch, detects changes and calls the appropriate
Deployers
+ * The main/primary component for deployment.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public class MainDeployer
extends ServiceMBeanSupport
@@ -61,23 +64,27 @@
/** Deployers **/
private final Set deployers = new HashSet();
- /** I always feel like somebody is watching me, contains DeploymentInfo **/
- private final Map deployments = new HashMap();
- private final ArrayList deploymentsList = new ArrayList();
+ /** A Map of URL -> DeploymentInfo */
+ private final Map deploymentMap = new HashMap();
+
+ /** A list of all deployments. */
+ private final ArrayList deploymentList = new ArrayList();
/** an increment for tmp files **/
- private int id = 0;
+ private final Counter id = Counter.makeSynchronized(new Counter(0));
+ /** A helper for sorting deployments. */
+ private final DeploymentSorter sorter = new DeploymentSorter();
+
/** The temporary directory for deployments. */
private File tempDir;
/** The string naming the tempDir **/
private String tempDirString;
+ /** The temporary directory where native libs are unpacked. */
private File tempNativeDir;
- private DeploymentSorter sorter = new DeploymentSorter();
-
/**
* Holds the native library <em>prefix</em> for this system.
* Determined by examining the result of System.mapLibraryName("XxX").
@@ -90,22 +97,35 @@
*/
private String nativeSuffix;
+ /**
+ * Explict no-args contsructor for JMX.
+ */
+ public MainDeployer()
+ {
+ super();
+ }
+
public Collection listDeployed()
{
- synchronized (deploymentsList)
+ synchronized (deploymentList)
{
- return new ArrayList(deploymentsList);
+ return new ArrayList(deploymentList);
}
}
- public void addDeployer(DeployerMBean deployer)
+ public void addDeployer(final DeployerMBean deployer)
{
- log.info("adding deployer: " + deployer);
+ if (log.isDebugEnabled()) {
+ log.debug("Adding deployer: " + deployer);
+ }
deployers.add(deployer);
}
- public void removeDeployer(DeployerMBean deployer)
+ public void removeDeployer(final DeployerMBean deployer)
{
+ if (log.isDebugEnabled()) {
+ log.debug("Removing deployer: " + deployer);
+ }
deployers.remove(deployer);
}
@@ -129,11 +149,11 @@
// (start/stop) only one entry is present
// get the temporary directory to use
- File serverTempDir = (File)
- server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "ServerTempDir");
+ ServerConfig config = ServerConfigLocator.locate();
+ File basedir = config.getServerTempDir();
- tempDir = new File(serverTempDir, "deploy");
- tempNativeDir = new File(serverTempDir, "native");
+ tempDir = new File(basedir, "deploy");
+ tempNativeDir = new File(basedir, "native");
// used in isWatched
tempDirString = tempDir.toURL().toString();
@@ -151,7 +171,7 @@
int deployCounter = 0;
// undeploy everything in sight
- List copyDeployments = new ArrayList(deploymentsList);
+ List copyDeployments = new ArrayList(deploymentList);
for (ListIterator i = copyDeployments.listIterator(copyDeployments.size());
i.hasPrevious(); )
{
try
@@ -161,7 +181,7 @@
}
catch (Exception e)
{
- log.info("exception trying to undeploy during shutdown: ", e);
+ log.info("exception trying to undeploy during shutdown", e);
}
}
@@ -169,11 +189,11 @@
log.info("Undeployed " + deployCounter + " deployed packages");
}
- public void undeploy(String url)
+ public void undeploy(URL url)
{
try
{
- DeploymentInfo sdi = getDeployment(new URL(url));
+ DeploymentInfo sdi = getDeployment(url);
if (sdi!= null)
{
@@ -185,6 +205,11 @@
log.error("Couldn't undeploy url " + url, e);
}
}
+
+ public void undeploy(String urlspec) throws MalformedURLException
+ {
+ undeploy(new URL(urlspec));
+ }
public void undeploy(DeploymentInfo di)
@@ -203,7 +228,7 @@
if (log.isDebugEnabled())
{
- log.debug("UNDEPLOYMENT OF SUB "+sub.url);
+ log.debug("Stopping sub deployment: "+sub.url);
}
stop(sub);
}
@@ -232,7 +257,7 @@
if (log.isDebugEnabled())
{
- log.debug("UNDEPLOYMENT OF SUB "+sub.url);
+ log.debug("Destroying sub deployment: "+sub.url);
}
destroy(sub);
}
@@ -246,23 +271,20 @@
di.deployer.destroy(di);
}
}
- catch (Exception e)
- {
- log.error("Undeployment failed: " + di.url, e);
- }
catch (Throwable t)
{
log.error("Undeployment failed: " + di.url, t);
}
+
try
{
// remove from local maps
- synchronized (deploymentsList)
+ synchronized (deploymentList)
{
- deployments.remove(di.url);
- if (deploymentsList.lastIndexOf(di) != -1)
+ deploymentMap.remove(di.url);
+ if (deploymentList.lastIndexOf(di) != -1)
{
- deploymentsList.remove(deploymentsList.lastIndexOf(di));
+ deploymentList.remove(deploymentList.lastIndexOf(di));
}
}
// Nuke my stuff, this includes the class loader
@@ -271,35 +293,24 @@
log.info("Undeployed "+di.url);
}
- catch (Exception e)
- {
- log.error("Undeployment cleanup failed: " + di.url, e);
- }
catch (Throwable t)
{
log.error("Undeployment cleanup failed: " + di.url, t);
}
}
- public void deploy(String url)
+ public void deploy(String urlspec) throws MalformedURLException
{
- // Just format it correctly
- try
- {
- // if no protocol, assume file based and prepend protocol
- if (! url.startsWith("http") && ! url.startsWith("file"))
- {
- deploy(new URL("file:"+url));
- }
- else
- {
- deploy(new URL(url));
- }
+ URL url;
+ try {
+ url = new URL(urlspec);
}
- catch (Exception e)
- {
- log.error("Problem with URL "+url, e);
+ catch (MalformedURLException e) {
+ File file = new File(urlspec);
+ url = file.toURL();
}
+
+ deploy(url);
}
public void deploy(URL url)
@@ -376,21 +387,21 @@
catch (Exception e)
{
throw new DeploymentException("exception in init of " + deployment.url, e);
- } // end of try-catch
+ }
finally
{
// whether you do it or not, for the autodeployer
deployment.lastDeployed = System.currentTimeMillis();
- synchronized (deploymentsList)
+ synchronized (deploymentList)
{
//watch it, it will be picked up as modified below, deployments is a
map duplicates are ok
- deployments.put(deployment.url, deployment);
+ deploymentMap.put(deployment.url, deployment);
// Do we watch it? Watch only urls outside our copy directory.
if (!inLocalCopyDir(deployment.url))
{
- deploymentsList.add(deployment);
+ deploymentList.add(deployment);
log.debug("Watching new file: " + deployment.url);
}
}
@@ -494,9 +505,10 @@
return;
}
}
- if (debug)
+
+ if (debug)
{
- log.debug("NO DEPLOYER for url "+sdi.url);
+ log.debug("No deployer found for url: " + sdi.url);
}
}
@@ -649,10 +661,7 @@
} // end of if ()
-
-
} // end of else
-
}
}
@@ -719,6 +728,9 @@
* Downloads the jar file or directory the src URL points to.
* In case of directory it becomes packed to a jar file.
*
+ * @todo Add support for Directory copying over.
+ * @todo FIXME: $JBOSS_HOME/tmp/deploy is not a valid reference.
+ *
* @return a File object representing the downloaded module
* @throws IOException
*/
@@ -729,12 +741,11 @@
{
if (sdi.url.getProtocol().equals("file") && sdi.isDirectory)
{
- // FIXME TODO add support for Directory copying over
+ // TODO add support for Directory copying over
sdi.localUrl = sdi.url;
return;
- // FIXME TODO add support for Directory copying over
}
// Are we already in the localCopyDir?
@@ -745,17 +756,18 @@
}
else
{
- //remove windows : from c:\nowhere. There must be a better way to do
this...
+ // remove windows : from c:\nowhere. There must be a better way to do
this...
StringBuffer path = new StringBuffer(sdi.url.getFile());
for (int i = path.length() - 1; i > -1; i--)
{
if (path.charAt(i) == ':')
{
path.deleteCharAt(i);
- } // end of if ()
- } // end of for ()
+ }
+ }
+
String shortName = DeploymentInfo.getShortName(path.toString());
- path.append("/").append(getNextID()).append(".").append(shortName);
+ path.append("/").append(id.increment()).append(".").append(shortName);
sdi.localUrl = new File(tempDir, path.toString()).toURL();
copy(sdi.url, sdi.localUrl);
}
@@ -764,6 +776,9 @@
{
log.error("Could not make local copy for "+sdi.url.toString(), e);
log.error("if you have just upgraded jboss versions, please delete");
+
+ // FIXME
+
log.error(" everything in the $JBOSS_HOME/tmp/deploy and try again");
}
}
@@ -780,49 +795,22 @@
return urlTest.startsWith(tempDirString, i);
}
- protected void copy(InputStream in, OutputStream out)
- throws IOException
- {
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) > 0)
- {
- out.write(buffer, 0, read);
- }
- }
-
- protected void copy (URL _src, URL _dest) throws IOException
+ protected void copy(URL _src, URL _dest) throws IOException
{
if (!_dest.getProtocol().equals("file"))
throw new IllegalArgumentException
("only file: protocol is allowed as destination!");
- InputStream in;
- OutputStream out;
-
- String s = _dest.getFile();
- File dir = new File(s.substring (0, s.lastIndexOf("/")));
+ File file = new File(_dest.getFile());
+ File dir = file.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
- in = _src.openStream();
- out = new FileOutputStream(s);
-
- byte[] buffer = new byte[1024];
-
- int read;
- while (true)
- {
- read = in.read(buffer);
- if (read == -1)
- break;
-
- out.write(buffer, 0, read);
- }
-
+ InputStream in = new BufferedInputStream(_src.openStream());
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
+ Streams.copy(in, out);
out.flush();
-
out.close();
in.close();
}
@@ -840,20 +828,18 @@
public DeploymentInfo getDeployment(URL url)
{
- synchronized (deploymentsList)
+ synchronized (deploymentList)
{
- return (DeploymentInfo) deployments.get(url);
+ return (DeploymentInfo) deploymentMap.get(url);
}
}
public DeploymentInfo removeDeployment(DeploymentInfo di)
{
- synchronized (deploymentsList)
+ synchronized (deploymentList)
{
- return (DeploymentInfo) deployments.remove(di.url);
+ return (DeploymentInfo) deploymentMap.remove(di.url);
}
}
-
- private synchronized int getNextID() { return id++;}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development