User: user57
Date: 02/02/05 16:42:33
Modified: src/main/org/jboss/system Server.java
Log:
o catching & logging exceptions thrown when adding a shutdown hook
o added gaurds around debug calls (for minor speed increase, since this
uses the bootstrap logger fluff).
Revision Changes Path
1.7 +71 -176 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Server.java 2002/01/30 23:53:23 1.6
+++ Server.java 2002/02/06 00:42:33 1.7
@@ -1,9 +1,9 @@
/*
-* JBoss, the OpenSource J2EE webOS
-*
-* Distributable under LGPL license.
-* See terms of license at gnu.org.
-*/
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.system;
@@ -28,17 +28,18 @@
import org.jboss.Version;
/**
-* The main container component of a JBoss server instance.
-*
-* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
-* @version $Revision: 1.6 $
-*/
+ * The main container component of a JBoss server instance.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.7 $
+ */
public class Server
-implements ServerMBean
+ implements ServerMBean
{
/** Class logger */
- private static final BootstrapLogger log =
BootstrapLogger.getLogger(Server.class);
+ private static final BootstrapLogger log =
+ BootstrapLogger.getLogger(Server.class);
/** Container for version information. */
private final Version version = Version.getInstance();
@@ -53,18 +54,22 @@
private final Date started;
/**
- * Creates a new instance of Server.
- *
- * @param config The basic configuration of the server instance.
- *
- * @throws Exception Failed to initialize server instance.
- */
+ * Creates a new instance of Server.
+ *
+ * @param config The basic configuration of the server instance.
+ *
+ * @throws Exception Failed to initialize server instance.
+ */
public Server(final ServerConfig config) throws Exception {
if (config == null)
throw new IllegalArgumentException("config is null");
+ boolean debug = log.isDebugEnabled();
+
this.config = config;
- log.debug("Using config: " + config);
+ if (debug) {
+ log.debug("Using config: " + config);
+ }
log.info("JBoss (MX MicroKernel) " +
version + " [" + version.getName() + "]");
@@ -75,10 +80,14 @@
// Create the MBeanServer
server = MBeanServerFactory.createMBeanServer(config.getDomain());
- log.debug("Created MBeanServer: " + server);
+ if (debug) {
+ log.debug("Created MBeanServer: " + server);
+ }
String systemDomain = server.getDefaultDomain() + ".system";
- log.debug("Using system domain: " + systemDomain);
+ if (debug) {
+ log.debug("Using system domain: " + systemDomain);
+ }
// Register ourselves first
server.registerMBean(this,
@@ -92,11 +101,14 @@
initBootLibraries();
// Create MBeanClassLoader for the base system
- ObjectName loaderName = new ObjectName(systemDomain, "service",
"ServiceClassLoader");
+ ObjectName loaderName =
+ new ObjectName(systemDomain, "service", "ServiceClassLoader");
MBeanClassLoader mcl = new MBeanClassLoader(loaderName);
server.registerMBean(mcl, loaderName);
- log.debug("Registered service classloader: " + loaderName);
+ if (debug) {
+ log.debug("Registered service classloader: " + loaderName);
+ }
// Set ServiceClassLoader as classloader for the construction of
// the basic system
@@ -104,7 +116,7 @@
// Setup logging
server.createMBean("org.jboss.logging.Log4jService",
- new ObjectName(systemDomain,"service", "Logging"),
+ new ObjectName(systemDomain, "service", "Logging"),
loaderName);
log.debug("Logging has been initialized");
@@ -119,7 +131,7 @@
// General Purpose Architecture information
server.createMBean("org.jboss.system.Info",
- new ObjectName(systemDomain,"service", "Info"),
+ new ObjectName(systemDomain, "service", "Info"),
loaderName);
// Service Controller
@@ -128,12 +140,19 @@
new ObjectName(systemDomain, "service", "ServiceController"),
loaderName).getObjectName();
- log.debug("Registered service controller: " + controllerName);
+ if (debug) {
+ log.debug("Registered service controller: " + controllerName);
+ }
// Install the shutdown hook
- ShutdownHook hook = new ShutdownHook(controllerName);
- Runtime.getRuntime().addShutdownHook(hook);
- log.debug("Shutdown hook added");
+ try {
+ ShutdownHook hook = new ShutdownHook(controllerName);
+ Runtime.getRuntime().addShutdownHook(hook);
+ log.debug("Shutdown hook added");
+ }
+ catch (Exception e) {
+ log.warn("Failed to add shutdown hook", e);
+ }
// Deployer
ObjectName mainDeployer =
@@ -147,7 +166,7 @@
null,
loaderName).getObjectName();
- //Ok, now do a first deploy of JBoss' jboss-service.xml
+ // Ok, now do a first deploy of JBoss' jboss-service.xml
server.invoke(mainDeployer,
"deploy",
new Object[] {config.getConfigURL() + "jboss-service.xml"},
@@ -164,13 +183,14 @@
// Tell the world how fast it was =)
log.info("JBoss (MX MicroKernel) " +
- version + " [" + version.getName() + "]"+ " Started in " + minutes + "m:"
+
- seconds + "s:" + milliseconds +"ms");
+ version + " [" + version.getName() + "]" +
+ " Started in " + minutes + "m:" +
+ seconds + "s:" + milliseconds +"ms");
}
/**
- * Initialize the boot libraries.
- */
+ * Initialize the boot libraries.
+ */
private void initBootLibraries() throws Exception {
// Build the list of URL for the spine to boot
List list = new ArrayList();
@@ -227,10 +247,10 @@
}
/**
- * Shutdown the server, virtual machine and run shutdown hooks.
- *
- * @throws Exception Failed to shutdown.
- */
+ * Shutdown the server, virtual machine and run shutdown hooks.
+ *
+ * @throws Exception Failed to shutdown.
+ */
public void shutdown() throws Exception {
// start in new thread so that we might have a chance to gice positive
// feed back to requesting client of success.
@@ -243,8 +263,8 @@
}
/**
- * Forcibly terminates the currently running Java virtual machine.
- */
+ * Forcibly terminates the currently running Java virtual machine.
+ */
public void halt() {
// start in new thread so that we might have a chance to gice positive
// feed back to requesting client of success.
@@ -280,15 +300,15 @@
}
/**
- * Enable or disable tracing method calls at the Runtime level.
- */
+ * Enable or disable tracing method calls at the Runtime level.
+ */
public void traceMethodCalls(final Boolean flag) {
Runtime.getRuntime().traceMethodCalls(flag.booleanValue());
}
/**
- * Enable or disable tracing instructions the Runtime level.
- */
+ * Enable or disable tracing instructions the Runtime level.
+ */
public void traceInstructions(final Boolean flag) {
Runtime.getRuntime().traceInstructions(flag.booleanValue());
}
@@ -311,9 +331,8 @@
}
public Long getMaxMemory() {
- /* Uncomment when JDK 1.4 is the base JVM
- return new Long(Runtime.getRuntime().maxMemory());
- */
+ // Uncomment when JDK 1.4 is the base JVM
+ // return new Long(Runtime.getRuntime().maxMemory());
return new Long(-1);
}
@@ -370,7 +389,7 @@
///////////////////////////////////////////////////////////////////////////
private class ShutdownHook
- extends Thread
+ extends Thread
{
/** The ServiceController which we will ask to shut things down with. */
private ObjectName contollerName;
@@ -393,9 +412,9 @@
}
/**
- * The <code>shutdownServices</code> method calls the one and only
- * ServiceController to shut down all the mbeans registered with it.
- */
+ * The <code>shutdownServices</code> method calls the one and only
+ * ServiceController to shut down all the mbeans registered with it.
+ */
protected void shutdownServices()
{
try
@@ -421,127 +440,3 @@
}
}
}
-
-/*
-
-
-public Main(String installURL,
-String confDir,
-String patchDir,
-String libDir,
-String spineDir)
-{
-long startTime = System.currentTimeMillis();
-
-try
-{
-final PrintStream err = System.err;
-
-System.setProperty("jboss.system.started", new Date(startTime).toString());
-System.setProperty("jboss.system.installationURL", installURL);
-System.setProperty("jboss.system.configurationDirectory", confDir);
-System.setProperty("jboss.system.patchDirectory", patchDir);
-System.setProperty("jboss.system.libraryDirectory", libDir);
-System.setProperty("jboss.system.version", version.toString());
-System.setProperty("jboss.system.version.name", version.getName());
-
-// Give feedback about from where jndi.properties is read
-URL jndiLocation = this.getClass().getResource("/jndi.properties");
-if (jndiLocation instanceof URL)
-{
-System.out.println("Please make sure the following is intended " +
-"(check your CLASSPATH): jndi.properties is " +
-"read from " + jndiLocation);
-}
-
-// Create MBeanServer
-final MBeanServer server =
-MBeanServerFactory.createMBeanServer("jboss");
-
-// Initialize the MBean libraries repository
-server.registerMBean(ServiceLibraries.getLibraries(),
-new ObjectName(server.getDefaultDomain(),
-"spine",
-"ServiceLibraries"));
-
-// Build the list of URL for the spine to boot
-ArrayList urls = new ArrayList();
-
-// Add the patch directory
-addJars(patchDir, urls);
-
-// Add configuration directory to be able to load files
-urls.add(new URL(confDir));
-
-// Add the local path stuff
-urls.add(new URL(libDir + "log4j.jar"));
-urls.add(new URL(libDir + "jboss-spine.jar"));
-
-// Crimson and jaxp are fucked up right now, cl usage fixed in new
-// version of jaxp according to the developers.
-//urls.add(new URL(libDir+"jaxp.jar"));
-//urls.add(new URL(libDir+"crimson.jar"));
-
-Iterator bootURLs = urls.iterator();
-while (bootURLs.hasNext())
-{
-// The libraries will register themselves with the libraries
-URL thisUrl = (URL) bootURLs.next();
-new UnifiedClassLoader(thisUrl);
-}
-
-// Create MBeanClassLoader for the base system
-ObjectName loader = new ObjectName(server.getDefaultDomain(),
-"spine",
-"ServiceClassLoader");
-MBeanClassLoader mcl = new MBeanClassLoader(loader);
-
-try
-{
-server.registerMBean(mcl, loader);
-
-// Set ServiceClassLoader as classloader for the construction of
-// the basic JBoss-System
-Thread.currentThread().setContextClassLoader(mcl);
-
-// Create the Loggers
-server.createMBean("org.jboss.logging.Log4jService", null, loader);
-
-// General Purpose Architecture information
-server.createMBean("org.jboss.system.Info", null, loader);
-
-// Shutdown stuff
-server.createMBean("org.jboss.system.Shutdown", null, loader);
-
-// Properties for the JAXP configuration
-if (System.getProperty("javax.xml.parsers.DocumentBuilderFactory") == null) {
-System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
-"org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");
-}
-if (System.getProperty("javax.xml.parsers.SAXParserFactory") == null) {
-System.setProperty("javax.xml.parsers.SAXParserFactory",
-"org.apache.crimson.jaxp.SAXParserFactoryImpl");
-}
-
-}
-catch(RuntimeMBeanException e)
-{
-e.getTargetException().printStackTrace();
-}
-catch (RuntimeOperationsException roe)
-{
-roe.getTargetException().printStackTrace();
-}
-catch (RuntimeErrorException ree)
-{
-ree.getTargetError().printStackTrace();
-}
-catch (MBeanException mbe)
-{
-mbe.getTargetException().printStackTrace();
-}
-catch (ReflectionException re)
-{
-re.getTargetException().printStackTrace();
-}
-*/
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development