User: user57
Date: 02/02/05 17:58:43
Modified: src/main/org/jboss/system Server.java ServerMBean.java
ServiceCreator.java
Log:
o changed a few info's to debugs
o added exitOnShutdown flag to Server, which when set to true will call
System.exit and when false will only invoke the shutdown hook.
o exposed exit() to compliment the halt() exposure
o added exit(int) and halt(int) to expose a bit more control to the admin
console.
o By default exitOnShutdown will be false, but Main will always set it to
true after creation of the Server object, since it is the controlling
entity (Server is embeded inside of it).
Revision Changes Path
1.8 +88 -13 jboss/src/main/org/jboss/system/Server.java
Index: Server.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/Server.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Server.java 2002/02/06 00:42:33 1.7
+++ Server.java 2002/02/06 01:58:43 1.8
@@ -32,7 +32,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class Server
implements ServerMBean
@@ -52,7 +52,13 @@
/** When the server was started. */
private final Date started;
-
+
+ /** The JVM shutdown hook */
+ private final ShutdownHook shutdownHook;
+
+ /** Exit on shutdown flag. */
+ private boolean exitOnShutdown = false;
+
/**
* Creates a new instance of Server.
*
@@ -145,9 +151,9 @@
}
// Install the shutdown hook
+ shutdownHook = new ShutdownHook(controllerName);
try {
- ShutdownHook hook = new ShutdownHook(controllerName);
- Runtime.getRuntime().addShutdownHook(hook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
log.debug("Shutdown hook added");
}
catch (Exception e) {
@@ -245,37 +251,106 @@
UnifiedClassLoader loader = new UnifiedClassLoader(url);
}
}
+
+ /**
+ * Enable or disable exiting the JVM when {@link #shutdown} is called.
+ * If enabled, then shutdown calls {@link #exit}. If disabled, then
+ * only the shutdown hook will be run.
+ *
+ * @param flag True to enable calling exit on shutdown.
+ */
+ public void setExitOnShutdown(final boolean flag) {
+ exitOnShutdown = flag;
+ }
+
+ /**
+ * Get the current value of the exit on shutdown flag. Default value is
+ * false, though it will be set to true when bootstrapped with
+ * {@link org.jboss.Main}.
+ *
+ * @return The current value of the exit on shutdown flag.
+ */
+ public boolean getExitOnShutdown() {
+ return exitOnShutdown;
+ }
+
+ /**
+ * Shutdown the server and run shutdown hooks. If the exit on shutdown
+ * flag is true, then {@link exit} is called, else only the shutdown hook
+ * is run.
+ */
+ public void shutdown() {
+ final Server server = this;
+
+ log.info("Shutting down");
+ if (log.isDebugEnabled()) {
+ log.debug("exitOnShutdown: " + exitOnShutdown);
+ }
+
+ if (exitOnShutdown) {
+ server.exit(0);
+ }
+ else {
+ // start in new thread to give positive
+ // feedback to requesting client of success.
+ new Thread() {
+ public void run() {
+ // just run the hook, don't call System.exit, as we may
+ // be embeded in a vm that would not like that very much
+ shutdownHook.run();
+ }
+ }.start();
+ }
+ }
/**
- * Shutdown the server, virtual machine and run shutdown hooks.
+ * Shutdown the server, the JVM and run shutdown hooks.
*
- * @throws Exception Failed to shutdown.
+ * @param exitcode The exit code returned to the operating system.
*/
- public void shutdown() throws Exception {
- // start in new thread so that we might have a chance to gice positive
+ public void exit(final int exitcode) {
+ // start in new thread so that we might have a chance to give positive
// feed back to requesting client of success.
new Thread() {
public void run() {
- log.info("Shutting down");
- System.exit(0); // This will execute the shutdown hook
+ log.info("Shutting down the JVM now!");
+ Runtime.getRuntime().exit(exitcode);
}
}.start();
}
+ /**
+ * Shutdown the server, the JVM and run shutdown hooks. Exits with
+ * code 1.
+ */
+ public void exit() {
+ exit(1);
+ }
+
/**
* Forcibly terminates the currently running Java virtual machine.
+ *
+ * @param exitcode The exit code returned to the operating system.
*/
- public void halt() {
- // start in new thread so that we might have a chance to gice positive
+ public void halt(final int exitcode) {
+ // start in new thread so that we might have a chance to give positive
// feed back to requesting client of success.
new Thread() {
public void run() {
System.err.println("Halting the system now!");
- Runtime.getRuntime().halt(0);
+ Runtime.getRuntime().halt(exitcode);
}
}.start();
}
+ /**
+ * Forcibly terminates the currently running Java virtual machine.
+ * Exits with code 1.
+ */
+ public void halt() {
+ halt(1);
+ }
+
///////////////////////////////////////////////////////////////////////////
// Runtime Access //
1.3 +44 -5 jboss/src/main/org/jboss/system/ServerMBean.java
Index: ServerMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServerMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServerMBean.java 2002/01/04 00:18:52 1.2
+++ ServerMBean.java 2002/02/06 01:58:43 1.3
@@ -14,7 +14,7 @@
* The JMX MBean interface for the <tt>Server</tt> component.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public interface ServerMBean
{
@@ -22,16 +22,55 @@
// Should eventually expose init, start & stop to allow admin clients
// to manage the state of the server dynamically.
//
-
+
+ /**
+ * Enable or disable exiting the JVM when {@link #shutdown} is called.
+ * If enabled, then shutdown calls {@link #exit}. If disabled, then
+ * only the shutdown hook will be run.
+ *
+ * @param flag True to enable calling exit on shutdown.
+ */
+ void setExitOnShutdown(boolean flag);
+
+ /**
+ * Get the current value of the exit on shutdown flag. Default value is
+ * false, though it will be set to true when bootstrapped with
+ * {@link org.jboss.Main}.
+ *
+ * @return The current value of the exit on shutdown flag.
+ */
+ boolean getExitOnShutdown();
+
+ /**
+ * Shutdown the server and run shutdown hooks. If the exit on shutdown
+ * flag is true, then {@link exit} is called, else only the shutdown hook
+ * is run.
+ */
+ void shutdown();
+
/**
- * Shutdown the server.
+ * Shutdown the server, the JVM and run shutdown hooks.
*
- * @throws Exception Failed to shutdown.
+ * @param exitcode The exit code returned to the operating system.
*/
- void shutdown() throws Exception;
+ void exit(int exitcode);
+
+ /**
+ * Shutdown the server, the JVM and run shutdown hooks. Exits with
+ * code 1.
+ */
+ void exit();
/**
* Forcibly terminates the currently running Java virtual machine.
+ *
+ * @param exitcode The exit code returned to the operating system.
+ */
+ void halt(int exitcode);
+
+ /**
+ * Forcibly terminates the currently running Java virtual machine.
+ * Exits with code 1.
*/
void halt();
1.12 +4 -2 jboss/src/main/org/jboss/system/ServiceCreator.java
Index: ServiceCreator.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceCreator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ServiceCreator.java 2002/01/20 15:19:38 1.11
+++ ServiceCreator.java 2002/02/06 01:58:43 1.12
@@ -25,7 +25,7 @@
* @see Service
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*
* <p><b>Revisions:</b>
* <p><b>2001/08/03 marcf </b>
@@ -90,7 +90,9 @@
// Create the MBean instance
try
{
- log.info("code "+code);
+ if (debug) {
+ log.debug("code: " + code);
+ }
ObjectInstance instance = server.createMBean(code,
name,
loader,
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development