User: mnf999 Date: 02/01/20 07:18:16 Modified: src/main/org/jboss/system Server.java Log: Unified Deployers and classloaders Revision Changes Path 1.3 +239 -106 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Server.java 2002/01/04 00:18:52 1.2 +++ Server.java 2002/01/20 15:18:16 1.3 @@ -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,41 +28,41 @@ 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.2 $ - */ +* 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.3 $ +*/ public class Server - implements ServerMBean +implements ServerMBean { /** Class logger */ private static final BootstrapLogger log = BootstrapLogger.getLogger(Server.class); - + /** Container for version information. */ private final Version version = Version.getInstance(); /** The basic configuration for the server. */ private final ServerConfig config; - + /** The JMX MBeanServer which will serve as our communication bus. */ private final MBeanServer server; - + /** When the server was started. */ 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"); - + this.config = config; log.debug("Using config: " + config); @@ -72,7 +72,7 @@ // remeber when we we started started = new Date(); log.info("Starting General Purpose Architecture (GPA)..."); - + // Create the MBeanServer server = MBeanServerFactory.createMBeanServer(config.getDomain()); log.debug("Created MBeanServer: " + server); @@ -82,37 +82,31 @@ // Register ourselves first server.registerMBean(this, - new ObjectName(systemDomain, - "service", - "Server")); - + new ObjectName(systemDomain,"service", "Server")); + // Initialize the MBean libraries repository server.registerMBean(ServiceLibraries.getLibraries(), - new ObjectName(systemDomain, - "service", - "ServiceLibraries")); + new ObjectName(systemDomain, "service","ServiceLibraries")); // Initialize spine boot libraries 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); - + // Set ServiceClassLoader as classloader for the construction of // the basic system Thread.currentThread().setContextClassLoader(mcl); - + // Setup logging server.createMBean("org.jboss.logging.Log4jService", - new ObjectName(systemDomain, - "service", - "Logging"), - loaderName); + new ObjectName(systemDomain,"service", "Logging"), + loaderName); + log.debug("Logging has been initialized"); // Log the basic configuration elements @@ -122,63 +116,78 @@ log.info("Spine URL: " + config.getSpineURL()); log.info("Library URL: " + config.getLibraryURL()); log.info("Patch URL: " + config.getPatchURL()); - + // General Purpose Architecture information server.createMBean("org.jboss.system.Info", - new ObjectName(systemDomain, - "service", - "Info"), - loaderName); - + new ObjectName(systemDomain,"service", "Info"), + loaderName); + // Service Controller ObjectName controllerName = - server.createMBean("org.jboss.system.ServiceController", - new ObjectName(systemDomain, - "service", - "ServiceController"), - loaderName).getObjectName(); + server.createMBean("org.jboss.system.ServiceController", + new ObjectName(systemDomain, "service", "ServiceController"), + loaderName).getObjectName(); + log.debug("Registered service controller: " + controllerName); // Install the shutdown hook ShutdownHook hook = new ShutdownHook(controllerName); Runtime.getRuntime().addShutdownHook(hook); log.debug("Shutdown hook added"); - - // Service Deployer - ObjectName deployerName = - server.createMBean("org.jboss.deployment.ServiceDeployer", - new ObjectName(systemDomain, - "service", - "ServiceDeployer"), - loaderName).getObjectName(); - log.debug("Registered service deployer: " + deployerName); - + + // Deployer + ObjectName mainDeployer = + server.createMBean("org.jboss.deployment.MainDeployer", + null, + loaderName).getObjectName(); + + // SAR Deployer + ObjectName sarDeployer = server.createMBean( + "org.jboss.deployment.SARDeployer", + null, + loaderName).getObjectName(); + + //Ok, now do a first deploy of JBoss' jboss-service.xml + server.invoke(mainDeployer, + "deploy", + new Object[] {config.getConfigURL() + "jboss-service.xml"}, + new String[] {"java.lang.String"}); + + // Start the main deployer thread + server.invoke(mainDeployer, "start", new Object[]{}, new String[] {}); + + /* // Ok, now deploy jboss-service.xml URL serviceURL = new URL(config.getConfigURL(), "jboss-service.xml"); log.info("Deploying basic components from: " + serviceURL); server.invoke(deployerName, - "deploy", - new Object[] { serviceURL.toString() }, - new String[] { "java.lang.String" }); - + "deploy", + new Object[] { serviceURL.toString() }, + new String[] { "java.lang.String" }); + */ + + + + + // Calculate how long it took long lapsedTime = System.currentTimeMillis() - started.getTime(); long minutes = lapsedTime / 60000; long seconds = (lapsedTime - 60000 * minutes) / 1000; long milliseconds = (lapsedTime -60000 * minutes - 1000 * seconds); - + // Tell the world how fast it was =) log.info("Started in " + minutes + "m:" + - seconds + "s:" + milliseconds +"ms"); + 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(); - + // Add the patch URL. If the url protocol is file, then // add the contents of the directory it points to URL patchURL = config.getPatchURL(); @@ -188,7 +197,7 @@ if (dir.exists()) { // Add the local file patch directory list.add(dir.toURL()); - + // Add the contents of the directory too File[] jars = dir.listFiles(new FileFilter() { @@ -226,15 +235,15 @@ // Should probably remove this "side-effect" and make this more explicit // This is a boot URL, so key it on itself. - URLClassLoader loader = new URLClassLoader(url); + UnifiedClassLoader loader = new UnifiedClassLoader(url); } } /** - * 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. @@ -247,8 +256,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. @@ -260,7 +269,7 @@ }.start(); } - + /////////////////////////////////////////////////////////////////////////// // Runtime Access // /////////////////////////////////////////////////////////////////////////// @@ -277,31 +286,31 @@ log.info("Hinted to the JVM to run garbage collection"); logMemoryUsage(rt); } - + public void runFinalization() { Runtime.getRuntime().runFinalization(); log.info("Hinted to the JVM to run any pending object finalizations"); } /** - * 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()); } - + /////////////////////////////////////////////////////////////////////////// // Server Information // /////////////////////////////////////////////////////////////////////////// - + public Date getStarted() { return started; } @@ -320,27 +329,27 @@ */ return new Long(-1); } - + public String getVersion() { return version.toString(); } - + public String getVersionName() { return version.getName(); } - + public String getBuildNumber() { return version.getBuildNumber(); } - + public String getBuildID() { return version.getBuildID(); } - + public String getBuildDate() { return version.getBuildDate(); } - + public String getHomeDir() { return config.getHomeDir().toString(); } @@ -367,14 +376,14 @@ return null; return patchURL.toString(); } - + /////////////////////////////////////////////////////////////////////////// // Shutdown Hook // /////////////////////////////////////////////////////////////////////////// - + private class ShutdownHook - extends Thread + extends Thread { /** The ServiceController which we will ask to shut things down with. */ private ObjectName contollerName; @@ -388,27 +397,27 @@ public void run() { log.info("Shutting down all services"); System.out.println("Shutting down"); - + // Make sure all services are down properly shutdownServices(); - + log.info("Shutdown complete"); System.out.println("Shutdown complete"); } - + /** - * 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 { // get the deployed objects from ServiceController server.invoke(contollerName, - "shutdown", - new Object[0], - new String[0]); + "shutdown", + new Object[0], + new String[0]); } catch (MBeanException e) { @@ -425,3 +434,127 @@ } } } + +/* + + +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-SYSTEM"); + +// 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(); +} +*/ \ No newline at end of file
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
