Author: xuhaihong
Date: Sun Dec 11 14:21:07 2011
New Revision: 1213003
URL: http://svn.apache.org/viewvc?rev=1213003&view=rev
Log:
GERONIMO-6228 Jar resource and getRealPath cache should not be cleaned while uninstalling
embedded WAB in EBA
Modified:
geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
Modified: geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java?rev=1213003&r1=1213002&r2=1213003&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
(original)
+++ geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Sun Dec 11 14:21:07 2011
@@ -399,7 +399,7 @@ public class ApplicationGBean implements
try {
bundle.uninstall();
} catch (Exception e) {
- e.printStackTrace();
+ LOG.error("Fail to uninstall", e);
}
}
applicationBundles.clear();
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java?rev=1213003&r1=1213002&r2=1213003&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Sun Dec 11 14:21:07 2011
@@ -219,22 +219,18 @@ public class TomcatModuleBuilder extends
if (specDDUrl == null) {
webApp = new WebApp();
} else {
+ InputStream in = null;
try {
specDD = JarUtils.readAll(specDDUrl);
-
- InputStream in = specDDUrl.openStream();
- try {
- webApp = (WebApp) JaxbJavaee.unmarshalJavaee(WebApp.class, in);
- } finally {
- in.close();
- }
-
+ in = specDDUrl.openStream();
+ webApp = (WebApp) JaxbJavaee.unmarshalJavaee(WebApp.class, in);
} catch (Exception e) {
throw new DeploymentException("Error reading web.xml for " + bundle.getSymbolicName(),
e);
+ } finally {
+ IOUtils.close(in);
}
}
- AbstractName earName = null;
String targetPath = ".";
boolean standAlone = true;
@@ -251,13 +247,8 @@ public class TomcatModuleBuilder extends
idBuilder.resolve(environment, bundle.getSymbolicName(), "wab");
- AbstractName moduleName;
- if (earName == null) {
- earName = naming.createRootName(environment.getConfigId(), NameFactory.NULL,
NameFactory.J2EE_APPLICATION);
- moduleName = naming.createChildName(earName, environment.getConfigId().toString(),
NameFactory.WEB_MODULE);
- } else {
- moduleName = naming.createChildName(earName, targetPath, NameFactory.WEB_MODULE);
- }
+ AbstractName earName = naming.createRootName(environment.getConfigId(), NameFactory.NULL,
NameFactory.J2EE_APPLICATION);
+ AbstractName moduleName = naming.createChildName(earName, environment.getConfigId().toString(),
NameFactory.WEB_MODULE);
String name = webApp.getModuleName();
if (name == null) {
@@ -288,24 +279,24 @@ public class TomcatModuleBuilder extends
// on the J2ee management object
specDD = JarUtils.readAll(specDDUrl);
- InputStream in = null;
// firstly validate the DD xml file, if it is defined by a schema.
if (identifySpecDDSchemaVersion(specDD) >= 2.4f){
- in = specDDUrl.openStream();
+ InputStream in = null;
try {
+ in = specDDUrl.openStream();
JaxbJavaee.validateJavaee(JavaeeSchema.WEB_APP_3_0, in);
} catch (Exception e) {
throw new DeploymentException("Error validate web.xml for " + targetPath,
e);
} finally {
- if (in != null)
- IOUtils.close(in);
+ IOUtils.close(in);
}
}
// we found web.xml, if it won't parse that's an error.
- in = specDDUrl.openStream();
+ InputStream in = null;
try {
+ in = specDDUrl.openStream();
webApp = (WebApp) JaxbJavaee.unmarshalJavaee(WebApp.class, in);
} catch (Exception e) {
// Output the target path in the error to make it clearer to the user which
webapp
@@ -313,8 +304,7 @@ public class TomcatModuleBuilder extends
// value such as C:\geronimo-1.1\var\temp\geronimo-deploymentUtil22826.tmpdir
throw new DeploymentException("Error unmarshal web.xml for " + targetPath,
e);
} finally {
- if (in != null)
- IOUtils.close(in);
+ IOUtils.close(in);
}
} catch (Exception e) {
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=1213003&r1=1213002&r2=1213003&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Sun Dec 11 14:21:07 2011
@@ -829,7 +829,7 @@ public class GeronimoStandardContext ext
return;
}
TomcatDeploymentWatcher tomcatDeploymentWatcher = (TomcatDeploymentWatcher) bundleContext.getService(tomcatDeploymentWatcherReference);
- tomcatDeploymentWatcher.deleteOnUndeployed(tomcatWebAppContext.getAbstractName(),
tempDirectory);
+ tomcatDeploymentWatcher.deleteOnUndeployed(bundle, tomcatWebAppContext.getAbstractName(),
tempDirectory);
} catch (Exception e) {
logger.warn("Unable to add temporary directory " + tempDirectory + "to the Tomcat
deployment watcher, that folder will not be delete on the undeployment", e);
} finally {
Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java?rev=1213003&r1=1213002&r2=1213003&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
Sun Dec 11 14:21:07 2011
@@ -18,33 +18,124 @@
package org.apache.geronimo.tomcat;
import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.annotation.GBean;
import org.apache.geronimo.gbean.annotation.OsgiService;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
import org.apache.geronimo.kernel.config.DeploymentWatcher;
+import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
+import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.util.FileUtils;
+import org.apache.geronimo.osgi.web.WebApplicationUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
*/
@GBean
@OsgiService
-public class TomcatDeploymentWatcher implements DeploymentWatcher {
+public class TomcatDeploymentWatcher implements DeploymentWatcher, GBeanLifecycle, SynchronousBundleListener
{
- private Map<AbstractName, File> abstractNameTempDirectoryMap = new ConcurrentHashMap<AbstractName,
File>();
+ private static final Logger logger = LoggerFactory.getLogger(TomcatDeploymentWatcher.class);
+
+ private final Map<AbstractName, File> abstractNameCleanUpDirectoryMap = new ConcurrentHashMap<AbstractName,
File>();
+
+ private final Map<Artifact, long[]> ebaArtifactApplicationContentBundleIdsMap =
new ConcurrentHashMap<Artifact, long[]>();
+
+ private final Set<Long> embeddedWABBundleIds = Collections.synchronizedSet(new
HashSet<Long>());
+
+ private final Kernel kernel;
+
+ private final Map<Long, File> wabBundleIdCleanUpDirectoryMap = new ConcurrentHashMap<Long,
File>();
+
+ private final BundleContext bundleContext;
+
+ private final LifecycleListener ebaLifecycleListener = new EBALifecycleListener();
+
+ public TomcatDeploymentWatcher(@ParamSpecial(type = SpecialAttributeType.kernel) Kernel
kernel, @ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext)
{
+ this.kernel = kernel;
+ this.bundleContext = bundleContext;
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event) {
+ Bundle bundle = event.getBundle();
+ Long bundleId = event.getBundle().getBundleId();
+ if (event.getType() == Bundle.UNINSTALLED && WebApplicationUtils.isWebApplicationBundle(bundle)
&& !embeddedWABBundleIds.contains(bundleId)) {
+ File cleanUpDirectory = wabBundleIdCleanUpDirectoryMap.remove(bundleId);
+ if (cleanUpDirectory != null) {
+ FileUtils.recursiveDelete(cleanUpDirectory);
+ }
+ }
+ }
+
+ public void deleteOnUndeployed(Bundle bundle, AbstractName abName, File cleanUpDirectory)
{
+ if (WebApplicationUtils.isWebApplicationBundle(bundle)) {
+ wabBundleIdCleanUpDirectoryMap.put(bundle.getBundleId(), cleanUpDirectory);
+ } else {
+ abstractNameCleanUpDirectoryMap.put(abName, cleanUpDirectory);
+ }
+ }
@Override
public void deployed(Artifact artifact) {
}
@Override
+ public void doFail() {
+ try {
+ doStop();
+ } catch (Exception e) {
+ }
+ }
+
+ @Override
+ public void doStart() throws Exception {
+ kernel.getLifecycleMonitor().addLifecycleListener(ebaLifecycleListener, new AbstractNameQuery("org.apache.geronimo.aries.ApplicationGBean"));
+ bundleContext.addBundleListener(this);
+ }
+
+ @Override
+ public void doStop() throws Exception {
+ kernel.getLifecycleMonitor().removeLifecycleListener(ebaLifecycleListener);
+ bundleContext.removeBundleListener(this);
+ }
+
+ @Override
public void undeployed(Artifact artifact) {
- for (Iterator<Map.Entry<AbstractName, File>> it = abstractNameTempDirectoryMap.entrySet().iterator();
it.hasNext();) {
+ //a. EBA Bundle
+ long[] applicationBundleIds = ebaArtifactApplicationContentBundleIdsMap.remove(artifact);
+ if (applicationBundleIds != null) {
+ for (long applicationBundleId : applicationBundleIds) {
+ File cleanUpDirectory = wabBundleIdCleanUpDirectoryMap.remove(applicationBundleId);
+ if (cleanUpDirectory != null) {
+ embeddedWABBundleIds.remove(applicationBundleId);
+ FileUtils.recursiveDelete(cleanUpDirectory);
+ }
+ }
+ return;
+ }
+ //b. Common Application
+ for (Iterator<Map.Entry<AbstractName, File>> it = abstractNameCleanUpDirectoryMap.entrySet().iterator();
it.hasNext();) {
Map.Entry<AbstractName, File> entry = it.next();
if (entry.getKey().getArtifact().equals(artifact)) {
FileUtils.recursiveDelete(entry.getValue());
@@ -53,7 +144,23 @@ public class TomcatDeploymentWatcher imp
}
}
- public void deleteOnUndeployed(AbstractName abName, File tempDirectory) {
- abstractNameTempDirectoryMap.put(abName, tempDirectory);
+ private class EBALifecycleListener extends LifecycleAdapter {
+
+ @Override
+ public void running(AbstractName abName) {
+ try {
+ long[] applicationContentBundleIds = (long[]) kernel.getAttribute(abName,
"applicationContentBundleIds");
+ for (long applicationContentBundleId : applicationContentBundleIds) {
+ embeddedWABBundleIds.add(applicationContentBundleId);
+ }
+ ebaArtifactApplicationContentBundleIdsMap.put(abName.getArtifact(), applicationContentBundleIds);
+ } catch (GBeanNotFoundException e) {
+ logger.error("Unable to find application content bundle Ids from GBean "
+ abName, e);
+ } catch (NoSuchAttributeException e) {
+ logger.error("Unable to find application content bundle Ids from GBean "
+ abName, e);
+ } catch (Exception e) {
+ logger.error("Unable to find application content bundle Ids from GBean "
+ abName, e);
+ }
+ }
}
}
|