[jboss-cvs] JBossAS SVN: r89918 - branches/Branch_5_x/main/src/main/org/jboss.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 5 14:39:42 EDT 2009


Author: ALRubinger
Date: 2009-06-05 14:39:42 -0400 (Fri, 05 Jun 2009)
New Revision: 89918

Modified:
   branches/Branch_5_x/main/src/main/org/jboss/Main.java
Log:
[JBAS-6974] Main ShutdownHook to block on server shutdown

Modified: branches/Branch_5_x/main/src/main/org/jboss/Main.java
===================================================================
--- branches/Branch_5_x/main/src/main/org/jboss/Main.java	2009-06-05 18:39:02 UTC (rev 89917)
+++ branches/Branch_5_x/main/src/main/org/jboss/Main.java	2009-06-05 18:39:42 UTC (rev 89918)
@@ -101,8 +101,7 @@
          // Concurrent
          "concurrent.jar",
          // Logging
-         "log4j-boot.jar", 
-         "jboss-logging-spi.jar", 
+         "log4j-boot.jar", "jboss-logging-spi.jar",
          "jboss-logging-log4j.jar",
          "jboss-logging-jdk.jar",
          "jboss-logmanager.jar",
@@ -111,37 +110,24 @@
          "jboss-common-core.jar",
          "jboss-xml-binding.jar",
          // Bootstrap
-         "jboss-bootstrap-spi.jar", 
-         "jboss-bootstrap-spi-as.jar", 
-         "jboss-bootstrap-spi-mc.jar",
-         "jboss-bootstrap-impl-base.jar", 
-         "jboss-bootstrap-impl-as.jar",
+         "jboss-bootstrap-spi.jar", "jboss-bootstrap-spi-as.jar", "jboss-bootstrap-spi-mc.jar",
+         "jboss-bootstrap-impl-base.jar", "jboss-bootstrap-impl-as.jar",
          "jboss-bootstrap-impl-mc.jar",
          // Microcontainer
-         "javassist.jar", 
-         "jboss-reflect.jar", 
-         "jboss-mdr.jar", 
-         "jboss-dependency.jar", 
-         "jboss-kernel.jar",
-         "jboss-metatype.jar", 
-         "jboss-managed.jar",
+         "javassist.jar", "jboss-reflect.jar", "jboss-mdr.jar", "jboss-dependency.jar", "jboss-kernel.jar",
+         "jboss-metatype.jar", "jboss-managed.jar",
          // Fixme ClassLoading
-         "jboss-vfs.jar", 
-         "jboss-classloading-spi.jar", 
-         "jboss-classloader.jar", 
-         "jboss-classloading.jar",
+         "jboss-vfs.jar", "jboss-classloading-spi.jar", "jboss-classloader.jar", "jboss-classloading.jar",
          "jboss-classloading-vfs.jar",
          // Fixme aop
-         "jboss-aop.jar", 
-         "jboss-aop-mc-int.jar", 
-         "trove.jar",};
+         "jboss-aop.jar", "jboss-aop-mc-int.jar", "trove.jar",};
 
    /**
     * Server properties.  This object holds all of the required
     * information to get the server up and running. Use System
     * properties for defaults.
     */
-   private Map<String,String> props = new HashMap<String, String>();
+   private Map<String, String> props = new HashMap<String, String>();
 
    /** 
     * The booted server instance. 
@@ -159,7 +145,7 @@
     * The FQN of the default server implementation class to create
     */
    private static final String DEFAULT_AS_SERVER_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.as.server.JBossASServerImpl";
-   
+
    /**
     * The name of the system property denoting where the boot.log will be placed
     */
@@ -171,7 +157,7 @@
    public Main()
    {
       super();
-      
+
       // Set default properties
       final Properties sysProps = System.getProperties();
       for (final Object propName : sysProps.keySet())
@@ -200,11 +186,11 @@
     */
    public void boot(final String[] args) throws Exception
    {
-	   // remove this when JBAS-6744 is fixed
-	   String useUnorderedSequence = System.getProperty("xb.builder.useUnorderedSequence");
-	   if(useUnorderedSequence == null)
-		   System.setProperty("xb.builder.useUnorderedSequence", "true");
-	   
+      // remove this when JBAS-6744 is fixed
+      String useUnorderedSequence = System.getProperty("xb.builder.useUnorderedSequence");
+      if (useUnorderedSequence == null)
+         System.setProperty("xb.builder.useUnorderedSequence", "true");
+
       // First process the command line to pickup custom props/settings
       processCommandLine(args);
 
@@ -228,7 +214,7 @@
       else if (homeDir != null)
       {
          final File homeDirFile = new File(homeDir);
-         if(!homeDirFile.exists())
+         if (!homeDirFile.exists())
          {
             throw new IllegalArgumentException("Specified " + JBossASServerConfig.PROP_KEY_JBOSSAS_HOME_DIR
                   + " does not point to a valid location: " + homeDirFile.toString());
@@ -249,7 +235,7 @@
          URL homeUrlFromDir = homeFile.toURI().toURL();
          jbossHome = homeUrlFromDir;
       }
-      
+
       // Get Library URL
       String libUrlFromProp = props.get(JBossASServerConfig.PROP_KEY_JBOSSAS_BOOT_LIBRARY_URL);
       URL libUrl = null;
@@ -261,7 +247,7 @@
       {
          libUrl = new URL(jbossHome, JBossASConfigurationInitializer.VALUE_LIBRARY_URL_SUFFIX_DEFAULT);
       }
-      
+
       /*
        * Set boot log directory
        */
@@ -288,7 +274,7 @@
       {
          SecurityActions.setSystemProperty(sysPropBootLogDir, manualLogDir);
       }
-      
+
       // Get TCCL
       final ClassLoader tccl = SecurityActions.getThreadContextClassLoader();
 
@@ -347,7 +333,7 @@
       {
          urls.add(extraClasspath.get(i));
       }
-      
+
       // Add all boot libs required from $JBOSS_HOME/lib
       final File bootLibDir = new File(libUrl.toURI());
       if (!bootLibDir.exists())
@@ -365,28 +351,28 @@
          {
             System.out.println("WARNING: Could not find expected boot lib " + bootLibFile);
          }
-         final URL bootLibUrl = bootLibFile.toURI().toURL(); 
+         final URL bootLibUrl = bootLibFile.toURI().toURL();
          urls.add(bootLibUrl);
       }
-      
+
       // Make a ClassLoader to be used in loading the server
       final URL[] urlArray = urls.toArray(new URL[]
       {});
       final ClassLoader loadingCl = new URLClassLoader(urlArray, tccl);
 
       // Load the server
-      server = ServerFactory.createServer(DEFAULT_AS_SERVER_IMPL_CLASS_NAME,loadingCl);
+      server = ServerFactory.createServer(DEFAULT_AS_SERVER_IMPL_CLASS_NAME, loadingCl);
 
       // Get out the default configuration
       // This cast to object first is to workaround the JDK Bug: http://bugs.sun.com/view_bug.do?bug_id=6548436
       final Object jdk6Bug6548436Hack = (Object) server.getConfiguration();
       JBossASServerConfig config = (JBossASServerConfig) jdk6Bug6548436Hack;
-      
+
       // Set JBOSS_HOME and properties
       config.properties(props).jbossHome(jbossHome);
-      
+
       // Make a shutdown hook
-      SecurityActions.addShutdownHook(new ShutdownHook(server,loadingCl));
+      SecurityActions.addShutdownHook(new ShutdownHook(server, loadingCl));
 
       try
       {
@@ -852,7 +838,7 @@
       }
 
    }
-   
+
    /**
     * ShutdownHook
     *
@@ -861,12 +847,12 @@
     */
    private static class ShutdownHook extends Thread
    {
-      
+
       /**
        * Underlying server instance
        */
       private Server<?, ?> server;
-      
+
       /**
        * ClassLoader used to start/init the server
        */
@@ -879,18 +865,18 @@
        * @param serverCl The ClassLoader to be optionally closed upon shutdown
        * @throws IllegalArgumentException If any argument is not supplied (null)
        */
-      ShutdownHook(final Server<?, ?> server,final ClassLoader serverCl) throws IllegalArgumentException
+      ShutdownHook(final Server<?, ?> server, final ClassLoader serverCl) throws IllegalArgumentException
       {
          // Precondition checks
-         if(server==null)
+         if (server == null)
          {
             throw new IllegalArgumentException("server must be specified");
          }
-         if(serverCl==null)
+         if (serverCl == null)
          {
             throw new IllegalArgumentException("server ClassLoader must be specified");
          }
-         
+
          // Set properties
          this.server = server;
          this.serverCl = serverCl;
@@ -908,48 +894,95 @@
             // 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))
+            
+            // start in new thread to give positive
+            // feedback to requesting client of success.
+            final Thread shutdownThread = new Thread()
             {
-               // start in new thread to give positive
-               // feedback to requesting client of success.
-               new Thread()
+               public void run()
                {
-                  public void run()
+                  try
                   {
-                     try
+                     // Flag if we've got a clean shutdown (ie. server had completely started)
+                     boolean cleanShutdown = false;
+                     
+                     /*
+                      * This bit is a hack.
+                      * 
+                      * It's in place because AS does not presently respond to Thread
+                      * interruption.  If it did, then the start lifecycle would
+                      * attempt to cleanly finish in expedient fashion such that the shutdown
+                      * lifecycle could take over.
+                      * 
+                      * Until the server is able to have start() get interrupted, we'd be 
+                      * blocking on a complete startup before shutdown could continue.  
+                      * We don't want to wait for full startup, so this hack only triggers
+                      * shutdown if fully started.  If still starting, we prematurely
+                      * halt the VM.
+                      * 
+                      * JBBOOT-75
+                      * JBAS-6974
+                      */
+                     // Shutdown if started only
+                     if (server.getState().equals(LifecycleState.STARTED))
                      {
-                        // just run the hook, don't call System.exit, as we may
-                        // be embeded in a vm that would not like that very much
+                        cleanShutdown = true;
                         server.shutdown();
-                        
-                        /*
-                         * Close the Loading CL, if URLCL and JDK7+
-                         * JBBOOT-23
-                         */
-                        if (serverCl != null && serverCl instanceof Closeable)
+                     }
+                     
+                     /*
+                      * Close the Loading CL, if URLCL and JDK7+
+                      * JBBOOT-23
+                      */
+                     if (serverCl != null && serverCl instanceof Closeable)
+                     {
+                        try
                         {
-                           try
-                           {
-                              ((Closeable) serverCl).close();
-                           }
-                           catch (IOException ioe)
-                           {
-                              // Swallow
-                           }
+                           ((Closeable) serverCl).close();
                         }
+                        catch (IOException ioe)
+                        {
+                           // Swallow
+                        }
                      }
-                     // In case of any Exception thrown up the chain, let us know
-                     catch (final Exception e)
+                     
+                     /*
+                      * Part of the halt hack as explained above
+                      * 
+                      * JBBOOT-75
+                      * JBAS-6974
+                      */
+                     // If the server's not fully started, we're not going to block on it
+                     // before calling shutdown, so just kill the VM
+                     if (!cleanShutdown)
                      {
-                        throw new RuntimeException("Exception encountered in shutting down the server", e);
+                        System.out.println("Server startup has not completed, so halting the process");
+                        Runtime.getRuntime().halt(-1);
                      }
+                     
                   }
-               }.start();
+                  // 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);
+                  }
+               }
+            };
+
+            // Run
+            shutdownThread.start();
+
+            // Block until done
+            try
+            {
+               shutdownThread.join();
             }
-
-         }         
+            catch (final InterruptedException ie)
+            {
+               // Clear the flag
+               Thread.interrupted();
+            }
+         }
       }
    }
 




More information about the jboss-cvs-commits mailing list