[jboss-cvs] JBossAS SVN: r88764 - in branches/Branch_5_x_BootstrapLegacyRemoval: tomcat/src/main/org/jboss/web/tomcat/service/deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 12 13:42:26 EDT 2009
Author: ALRubinger
Date: 2009-05-12 13:42:26 -0400 (Tue, 12 May 2009)
New Revision: 88764
Modified:
branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/Main.java
branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/SecurityActions.java
branches/Branch_5_x_BootstrapLegacyRemoval/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
Log:
[JBAS-6856] Add a Shutdown Hook and correct the Tomcat Service to use new SPI
Modified: branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/Main.java
===================================================================
--- branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/Main.java 2009-05-12 17:31:00 UTC (rev 88763)
+++ branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/Main.java 2009-05-12 17:42:26 UTC (rev 88764)
@@ -45,6 +45,7 @@
import org.jboss.bootstrap.spi.as.config.JBossASConfigurationInitializer;
import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
import org.jboss.bootstrap.spi.factory.ServerFactory;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
import org.jboss.bootstrap.spi.server.Server;
/**
@@ -149,7 +150,7 @@
* AS SPI upon the application classpath, with references to
* classes on child ClassLoaders, leading to NCDFE. So just use
* the minimal SPI set and load everything via reflection
- * using the URLCLs we create the boot libraries.
+ * using the URLCLs we create which reference the boot libraries.
*/
private Server<?, ?> server;
@@ -371,6 +372,9 @@
// Set JBOSS_HOME and properties
config.properties(props).jbossHome(jbossHome);
+
+ // Make a shutdown hook
+ SecurityActions.addShutdownHook(new ShutdownHook(server));
try
{
@@ -845,5 +849,58 @@
}
}
+
+ /**
+ * ShutdownHook
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision$
+ */
+ private static class ShutdownHook extends Thread
+ {
+ // Underlying server instance
+ private Server<?, ?> server;
+
+ /**
+ * Constructor
+ *
+ * @param server
+ */
+ public ShutdownHook(final Server<?, ?> server)
+ {
+ this.server = server;
+ }
+
+ /**
+ * Shuts down the server if running
+ */
+ @Override
+ public void run()
+ {
+ // If we have a server
+ if (server != null)
+ {
+ // Log out
+ System.out.println("Posting Shutdown Request to the server...");
+
+ // If we're started or starting
+ final LifecycleState currentState = server.getState();
+ if (currentState.equals(LifecycleState.STARTED) || currentState.equals(LifecycleState.STARTING))
+ {
+ try
+ {
+ // Shutdown
+ server.shutdown();
+ }
+ // In case of any Exception thrown up the chain, let us know
+ catch (final Exception e)
+ {
+ throw new RuntimeException("Exception encountered in shutting down the server", e);
+ }
+ }
+ }
+ }
+ }
+
}
Modified: branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/SecurityActions.java
===================================================================
--- branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/SecurityActions.java 2009-05-12 17:31:00 UTC (rev 88763)
+++ branches/Branch_5_x_BootstrapLegacyRemoval/main/src/main/org/jboss/SecurityActions.java 2009-05-12 17:42:26 UTC (rev 88764)
@@ -128,4 +128,22 @@
};
});
}
+
+ /**
+ * Adds the specified shutdown hook
+ *
+ * @param shutdownHook
+ */
+ static void addShutdownHook(final Thread shutdownHook)
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ return null;
+ }
+ });
+
+ }
}
Modified: branches/Branch_5_x_BootstrapLegacyRemoval/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- branches/Branch_5_x_BootstrapLegacyRemoval/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2009-05-12 17:31:00 UTC (rev 88763)
+++ branches/Branch_5_x_BootstrapLegacyRemoval/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2009-05-12 17:42:26 UTC (rev 88764)
@@ -449,8 +449,9 @@
throw new IllegalStateException("Must set TomcatDeployer before stopping");
// Hot undeploy
- Boolean inShutdown = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "InShutdown");
- if (inShutdown.booleanValue() == false)
+ final LifecycleState currentState = (LifecycleState) server.getAttribute(ServerImplMBean.OBJECT_NAME, "State");
+ boolean inShutdown = currentState.equals(LifecycleState.STOPPING);
+ if (inShutdown == false)
{
log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, stopping connectors now");
More information about the jboss-cvs-commits
mailing list