You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/05/10 20:05:04 UTC
svn commit: r942833 - in
/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main:
Bootstrapper.java FrameworkLauncher.java
Author: gawor
Date: Mon May 10 18:05:04 2010
New Revision: 942833
URL: http://svn.apache.org/viewvc?rev=942833&view=rev
Log:
GERONIMO-5287: Ensure the instance cache directory is removed after the framework is fully stopped.
Modified:
geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
Modified: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java?rev=942833&r1=942832&r2=942833&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java Mon May 10 18:05:04 2010
@@ -45,14 +45,16 @@ public class Bootstrapper extends Framew
public int execute(Object opaque) {
try {
launch();
- } catch (Exception e) {
+ } catch (Throwable e) {
+ System.err.println("Error launching framework: " + e);
+ destroy(false);
return -1;
}
Main geronimoMain = getMain();
if (geronimoMain == null) {
System.err.println("Main not found");
- stop(false);
+ destroy(false);
return -1;
}
@@ -63,10 +65,10 @@ public class Bootstrapper extends Framew
ClassLoader newTCCL = geronimoMain.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newTCCL);
exitCode = geronimoMain.execute(opaque);
- stop(waitForStop);
+ destroy(waitForStop);
} catch (Throwable e) {
- e.printStackTrace();
- stop(false);
+ System.err.println("Error in Main: " + e);
+ destroy(false);
} finally {
Thread.currentThread().setContextClassLoader(oldTCCL);
}
@@ -76,26 +78,18 @@ public class Bootstrapper extends Framew
public Main getMain() {
ServiceTracker tracker = new ServiceTracker(getFramework().getBundleContext(), Main.class.getName(), null);
- tracker.open();
-
+ tracker.open();
Main geronimoMain = null;
try {
- geronimoMain = (Main) tracker.waitForService(1000 * 60);
+ return (Main) tracker.waitForService(1000 * 60);
+ } catch (InterruptedException e) {
+ // ignore
+ } finally {
tracker.close();
- } catch (Exception e) {
- e.printStackTrace();
}
return geronimoMain;
}
-
- public void stop(boolean await) {
- try {
- destroy(await);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
+
@Override
protected List<BundleInfo> loadStartupProperties(Properties startupProps, List<File> bundleDirs) {
List<BundleInfo> startList = super.loadStartupProperties(startupProps, bundleDirs);
Modified: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java?rev=942833&r1=942832&r2=942833&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java Mon May 10 18:05:04 2010
@@ -38,6 +38,7 @@ import java.util.logging.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.launch.Framework;
@@ -86,6 +87,7 @@ public class FrameworkLauncher {
private ServerInfo serverInfo;
private File geronimoHome;
private File geronimoBase;
+ private File cacheDirectory;
private Properties configProps = null;
private Framework framework = null;
@@ -134,8 +136,14 @@ public class FrameworkLauncher {
defaultStartLevel = Integer.parseInt(configProps.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
configProps.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "1");
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ FrameworkLauncher.this.destroy(false);
+ }
+ });
+
// Start up the OSGI framework
-
ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class);
FrameworkFactory factory = loader.iterator().next();
framework = factory.newFramework(new StringMap(configProps, false));
@@ -148,10 +156,23 @@ public class FrameworkLauncher {
startBundles(startList);
}
- public void destroy(boolean await) throws Exception {
+ public void destroy(boolean await) {
+ try {
+ destroyFramework(await);
+ } catch (Exception e) {
+ System.err.println("Error stopping framework: " + e);
+ }
+
+ if (uniqueInstance && cacheDirectory != null) {
+ Utils.recursiveDelete(cacheDirectory);
+ }
+ }
+
+ private void destroyFramework(boolean await) throws BundleException, InterruptedException {
if (framework == null) {
return;
}
+
if (await) {
while (true) {
FrameworkEvent event = framework.waitForStop(0);
@@ -160,39 +181,32 @@ public class FrameworkLauncher {
}
}
}
-
if (framework.getState() == Bundle.ACTIVE) {
framework.stop();
+ framework.waitForStop(0);
}
}
-
+
public Framework getFramework() {
return framework;
}
-
+
private void setFrameworkStorage(Properties configProps) throws IOException {
if (configProps.getProperty(Constants.FRAMEWORK_STORAGE) != null) {
return;
}
- final File storage;
if (uniqueInstance) {
File var = new File(geronimoBase, "var");
File tmpFile = File.createTempFile("instance-", "", var);
- storage = new File(var, tmpFile.getName() + "-cache");
+ cacheDirectory = new File(var, tmpFile.getName() + "-cache");
tmpFile.delete();
- // register shutdown hook to remove the instance's cache directory
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- Utils.recursiveDelete(storage);
- }
- });
} else {
- storage = new File(geronimoBase, "var/cache");
+ cacheDirectory = new File(geronimoBase, "var/cache");
}
- storage.mkdirs();
- configProps.setProperty(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());
+ cacheDirectory.mkdirs();
+ configProps.setProperty(Constants.FRAMEWORK_STORAGE, cacheDirectory.getAbsolutePath());
}
private static void processSecurityProperties(Properties m_configProps) {