AddToSystemProperty(extensionDirs, extensionDirsFromManifest, geronimoInstallDirectory);
ClassLoader classLoader = Daemon.class.getClassLoader();
// create the kernel
final Kernel kernel = KernelFactory.newInstance().createKernel("geronimo");
// boot the kernel
try {
kernel.boot();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
throw new AssertionError();
}
// add our shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread("Geronimo shutdown thread") {
public void run() {
System.out.println("\rServer shutdown begun ");
kernel.shutdown();
System.out.println("Server shutdown completed");
}
});
// load this configuration
InputStream in = classLoader.getResourceAsStream("META-INF/config.ser");
try {
ConfigurationUtil.loadBootstrapConfiguration(kernel, in, classLoader);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
// ignored
}
}
}
monitor.systemStarted(kernel);
AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());
if (configs.isEmpty()) {
// --override wasn't used (nothing explicit), see what was running before
Set configLists = kernel.listGBeans(query);
for (Iterator i = configLists.iterator(); i.hasNext();) {
AbstractName configListName = (AbstractName) i.next();
try {
configs.addAll((List) kernel.invoke(configListName, "restore"));
} catch (IOException e) {
System.err.println("Unable to restore last known configurations");
e.printStackTrace();
kernel.shutdown();
System.exit(1);
throw new AssertionError();
}
}
}
monitor.foundModules((Artifact[]) configs.toArray(new Artifact[configs.size()]));
// load the rest of the configurations
try {
ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
try {
for (Iterator i = configs.iterator(); i.hasNext();) {
Artifact configID = (Artifact) i.next();
monitor.moduleLoading(configID);
configurationManager.loadConfiguration(configID);
monitor.moduleLoaded(configID);
monitor.moduleStarting(configID);
configurationManager.startConfiguration(configID);
monitor.moduleStarted(configID);
}
} finally {
ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
}
} catch (Exception e) {
//Exception caught when starting configurations, starting kernel shutdown
monitor.serverStartFailed(e);
try {
kernel.shutdown();
} catch (Exception e1) {
System.err.println("Exception caught during kernel shutdown");
e1.printStackTrace();
}
System.exit(1);
throw new AssertionError();
}
// Tell every persistent configuration list that the kernel is now fully started
Set configLists = kernel.listGBeans(query);
for (Iterator i = configLists.iterator(); i.hasNext();) {
AbstractName configListName = (AbstractName) i.next();
kernel.setAttribute(configListName, "kernelFullyStarted", Boolean.TRUE);
}
// Startup sequence is finished
monitor.startupFinished();
monitor = null;
// capture this thread until the kernel is ready to exit
while (kernel.isRunning()) {
try {
synchronized (kernel) {
kernel.wait();
}
} catch (InterruptedException e) {
// continue
}
}