User: schulze
Date: 00/11/02 14:37:58
Modified: src/main/org/jboss/ejb AutoDeployer.java
ContainerFactory.java
Log:
Changed the AutoDeployer to call the J2eeDeployer to deploy applications,
furthermore are now .war and .ear files allowed.
Also I tried to fix the racecondition between the autodeployer thread and the copy
thread (on OS level).
Removed Manifest/ClassPath evauation and creating temp file from ContainerFactory
(is now in J2eeDeployer)
Revision Changes Path
1.8 +37 -12 jboss/src/main/org/jboss/ejb/AutoDeployer.java
Index: AutoDeployer.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/AutoDeployer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AutoDeployer.java 2000/10/24 19:52:12 1.7
+++ AutoDeployer.java 2000/11/02 22:37:57 1.8
@@ -24,7 +24,9 @@
import org.jboss.logging.Log;
import org.jboss.util.MBeanProxy;
import org.jboss.util.ServiceMBeanSupport;
+import org.jboss.deployment.J2eeDeployerMBean;
+
/**
* The AutoDeployer is used to automatically deploy EJB-jars.
* It can be used on either .jar or .xml files. The AutoDeployer can
@@ -38,7 +40,7 @@
*
* @see ContainerFactory
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class AutoDeployer
extends ServiceMBeanSupport
@@ -90,7 +92,7 @@
File urlFile = new File(url);
if (urlFile.exists() && urlFile.isDirectory())
{
- File metaFile = new File(urlFile, "META-INF/ejb-jar.xml");
+ File metaFile = new File(urlFile,
"META-INF"+File.separator+"ejb-jar.xml");
if (metaFile.exists()) // It's unpackaged
{
try
@@ -116,9 +118,12 @@
} else if (urlFile.exists()) // It's a file
{
// Check if it's a JAR or zip
- if (!(url.endsWith(".jar") || url.endsWith(".zip")))
+ if (!(url.endsWith(".jar") ||
+ url.endsWith(".ear") ||
+ url.endsWith(".war") ||
+ url.endsWith(".zip")))
continue; // Was not a JAR or zip - skip it...
-
+
try
{
watchedURLs.add(new
Deployment(urlFile.getCanonicalFile().toURL()));
@@ -130,9 +135,12 @@
} else // It's a real URL (probably http:)
{
// Check if it's a JAR or zip
- if (!(url.endsWith(".jar") || url.endsWith(".zip")))
+ if (!(url.endsWith(".jar") ||
+ url.endsWith(".ear") ||
+ url.endsWith(".war") ||
+ url.endsWith(".zip")))
continue; // Was not a JAR or zip - skip it...
-
+
try
{
watchedURLs.add(new Deployment(new URL(url)));
@@ -166,11 +174,14 @@
for (int idx = 0; idx < files.length; idx++)
{
URL fileUrl = files[idx].toURL();
-
- // Check if it's a JAR or zip
- if (!(fileUrl.getFile().endsWith(".jar") ||
fileUrl.getFile().endsWith(".zip")))
+
+ // Check if it's a JAR or zip or ear or war
+ if (!(fileUrl.getFile().endsWith(".jar") ||
+ fileUrl.getFile().endsWith(".ear") ||
+ fileUrl.getFile().endsWith(".war") ||
+ fileUrl.getFile().endsWith(".zip")))
continue; // Was not a JAR or zip - skip it...
-
+
if (deployedURLs.get(fileUrl) == null)
{
// This file has not been seen
before
@@ -228,6 +239,18 @@
// Check old timestamp -- always deploy if first check
if ((deployment.lastModified == 0) || (deployment.lastModified < lm))
{
+ // in case of file first check if it is really completely copied
+ // (check file size wait 1 second and compare new with old file
size)
+ long size = new File(deployment.watch.getFile()).length ();
+ try {
+ Thread.currentThread().sleep (1000L);
+ } catch (InterruptedException _ie) {}
+ if (size != new File(deployment.watch.getFile()).length ())
+ {
+ log.log (deployment.url+" is not yet ready for deploy...");
+ continue;
+ }
+
log.log("Auto deploy of "+deployment.url);
deployment.lastModified = lm;
try
@@ -269,7 +292,7 @@
throws Exception
{
// Save JMX name of ContainerFactory
- factoryName = new ObjectName(ContainerFactoryMBean.OBJECT_NAME);
+ factoryName = new ObjectName(J2eeDeployerMBean.OBJECT_NAME);
}
protected void startService()
@@ -342,7 +365,9 @@
throws MalformedURLException
{
this.url = url;
- if (url.getFile().endsWith(".jar"))
+ if (url.getFile().endsWith(".jar") ||
+ url.getFile().endsWith(".ear") ||
+ url.getFile().endsWith(".war"))
watch = url;
else
watch = new URL(url, "META-INF/ejb-jar.xml");
1.54 +11 -90 jboss/src/main/org/jboss/ejb/ContainerFactory.java
Index: ContainerFactory.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/ContainerFactory.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- ContainerFactory.java 2000/10/27 09:50:14 1.53
+++ ContainerFactory.java 2000/11/02 22:37:57 1.54
@@ -76,7 +76,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
*
-* @version $Revision: 1.53 $
+* @version $Revision: 1.54 $
*/
public class ContainerFactory
extends org.jboss.util.ServiceMBeanSupport
@@ -137,6 +137,7 @@
*/
public void initService()
{
+/*
URL tmpFile = getClass().getResource("/tmp.properties");
if (tmpFile != null)
{
@@ -162,6 +163,7 @@
{
log.debug("Using the systems temporary directory");
}
+*/
}
/**
@@ -296,99 +298,17 @@
log.log("Deploying:"+url);
// URL's to put in classloader
- URL[] urls;
+ URL[] urls = new URL[] { url };
// save the name of the jar before copying -> undeploy with the same name
URL origUrl = url;
- // copy the jar file to prevent locking - redeploy failure
- if (url.getProtocol().startsWith("file") && !url.getFile().endsWith("/"))
- {
-
- File jarFile = new File(url.getFile());
- File tmp;
- if (tmpDir == null)
- {
- tmp = File.createTempFile("tmpejbjar",".jar");
- }
- else
- {
- tmp = File.createTempFile("tmpejbjar",".jar", tmpDir);
- }
- tmp.deleteOnExit();
- FileInputStream fin = new FileInputStream(jarFile);
- byte[] bytes = new byte[(int)jarFile.length()];
- fin.read(bytes);
- FileOutputStream fout = new FileOutputStream(tmp);
- fout.write(bytes);
- fin.close();
- fout.close();
-
- // Get the URL's from the deployments Class-Path: manifest file.
- // These should be added to the classloader
- JarFile jar = new JarFile(tmp);
- Manifest mf = jar.getManifest();
- ArrayList urlList = new ArrayList();
- if (mf != null)
- {
- Attributes attributes = mf.getMainAttributes();
- String classPath = attributes.getValue(Attributes.Name.CLASS_PATH);
- if (classPath != null)
- {
- StringTokenizer classPathTokens = new StringTokenizer(classPath,
" ");
- while (classPathTokens.hasMoreTokens())
- {
- String classPathEntry = classPathTokens.nextToken();
- try
- {
-
- URL u;
- File dir;
-
- // Extension to "Class-Path:" format: dir/*
- // add jar files in the dir to the classpath
- if (classPathEntry.endsWith("/*"))
- {
- classPathEntry = classPathEntry.substring(0,
classPathEntry.length() - 1);
- dir = new File((new URL(url, classPathEntry)).getFile());
- String[] files = dir.list();
- for (int i = 0; i < files.length; i++)
- {
- if (files[i].endsWith(".jar") ||
files[i].endsWith(".zip"))
- {
- urlList.add(new URL(dir.toURL(), files[i]));
- log.debug("Added " + dir + File.separator +
files[i]);
- }
- }
- }
- else
- {
- urlList.add(new URL(url, classPathEntry));
- log.debug("Added "+ classPathEntry);
- }
- } catch (MalformedURLException e)
- {
- log.error("Could not add " + classPathEntry);
- }
- }
- }
- }
-
- // Add URL to tmp file
- url = tmp.toURL();
- urlList.add(url);
-
- urls = new URL[urlList.size()];
- urls = (URL[])urlList.toArray(urls);
- }
- else
- {
- urls = new URL[] { url };
- }
- // Create the ClassLoader for this application
- // TODO : the ClassLoader should come from the JMX manager if we want to
be able to share it (tomcat)
- ClassLoader cl = new URLClassLoader(urls,
Thread.currentThread().getContextClassLoader());
+ // create a classloader that to access the metadata
+ // this one dont has the contextclassloader as parent
+ // in case of the contextclassloader has a ejb package in its
+ //classpath the metadata of this package would be used.
+ ClassLoader cl = new URLClassLoader(urls);
// Create a file loader with which to load the files
XmlFileLoader efm = new XmlFileLoader();
@@ -398,8 +318,9 @@
// Load XML
ApplicationMetaData metaData = efm.load();
-
+ // create the _real_ classloader for this app
+ cl = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader
());
// Check validity
Log.setLog(new Log("Verifier"));