User: user57  
  Date: 01/07/12 18:22:26

  Modified:    src/main/org/jboss/util Shutdown.java ShutdownMBean.java
  Log:
   o added support to invoke Runtime.halt()
   o added a tad bit more logging
  
  Revision  Changes    Path
  1.6       +59 -18    jboss/src/main/org/jboss/util/Shutdown.java
  
  Index: Shutdown.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/Shutdown.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Shutdown.java     2001/06/22 23:11:15     1.5
  +++ Shutdown.java     2001/07/13 01:22:26     1.6
  @@ -6,62 +6,94 @@
    */
   package org.jboss.util;
   
  -import java.io.*;
  -import java.net.*;
  -import java.util.*;
  +import java.util.List;
  +import java.util.ArrayList;
   
  -import org.apache.log4j.Category;
  +import javax.management.MBeanRegistration;
  +import javax.management.MBeanRegistration;
  +import javax.management.MBeanServer;
  +import javax.management.ObjectName;
   
  -import javax.management.*;
  +import org.apache.log4j.Category;
   
   /**
    * Shutdown service.  Installs a hook to cleanly shutdown the server and
    * provides the ability to handle user shutdown requests.
    *      
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>.
  - * @version $Revision: 1.5 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.6 $
    */
   public class Shutdown
      implements MBeanRegistration, ShutdownMBean
   {
      // Constants -----------------------------------------------------
   
  +   /** The default object name to use. */
      public static final String OBJECT_NAME = ":type=Shutdown";
      
      // Attributes ----------------------------------------------------
   
      /** Instance logger. */
      private final Category log = Category.getInstance(Shutdown.class);
  -   
  -   List mbeans = new ArrayList();
  -   MBeanServer server;
  +
  +   /** The MBean server we are attached to. */
  +   private MBeanServer server;
      
      // Public  -------------------------------------------------------
  +
  +   /**
  +    * Shutdown the virtual machine and run shutdown hooks.
  +    */
      public void shutdown()
      {
  +      log.info("Shutting down");
         System.exit(0); // This will execute the shutdown hook
      }
  +
  +   /**
  +    * Forcibly terminates the currently running Java virtual machine.
  +    */
  +   public void halt()
  +   {
  +      System.err.println("Halting the system now!");
  +      Runtime.getRuntime().halt(0);
  +   }
      
      // MBeanRegistration implementation ------------------------------
   
  -   public ObjectName preRegister(final MBeanServer server, ObjectName name)
  +   /**
  +    * Saves a reference to the MBean server for later use and installs
  +    * a shutdown hook.
  +    *
  +    * @param server    The MBean server which we are going to be registered.
  +    * @param name      The object name we have been configured to use.
  +    * @return          Our preferred object name.
  +    *
  +    * @throws MalformedObjectNameException
  +    */
  +   public ObjectName preRegister(final MBeanServer server,
  +                                 final ObjectName name)
         throws Exception
      {
         this.server = server;
         try
         {
  -         Runtime.getRuntime().addShutdownHook(new Thread()
  +         Runtime.getRuntime().addShutdownHook(new Thread("JBoss Shutdown Hook")
            {
               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");
               }
            });
  +         
            log.info("Shutdown hook added");
         } catch (Throwable e)
         {
  @@ -72,23 +104,31 @@
      
      public void postRegister(Boolean registrationDone)
      {
  +      // empty
      }
      
  -   public void preDeregister()
  -      throws Exception
  +   public void preDeregister() throws Exception
      {
  +      // empty
      }
      
      public void postDeregister()
      {
  +      // empty
      }
  -   
  +
  +   /**
  +    * Attempt to <em>stop</em> and <em>destroy</em> all services
  +    * running inside of the MBean server which we are attached too by
  +    * asking the <tt>ServiceControl</tt> to do the dirty work.
  +    */
      protected void shutdownServices()
      {
         try
         {
            // Stop services
  -         server.invoke(new ObjectName(":service=ServiceControl"), "stop", new 
Object[0] , new String[0]);
  +         server.invoke(new ObjectName(":service=ServiceControl"),
  +                       "stop", new Object[0] , new String[0]);
         } catch (Exception e)
         {
            log.error("failed to stop services", e);
  @@ -97,7 +137,8 @@
         try
         {
            // Destroy services
  -         server.invoke(new ObjectName(":service=ServiceControl"), "destroy", new 
Object[0] , new String[0]);
  +         server.invoke(new ObjectName(":service=ServiceControl"),
  +                       "destroy", new Object[0] , new String[0]);
         } catch (Exception e)
         {
            log.error("failed to destroy services", e);         
  
  
  
  1.3       +14 -7     jboss/src/main/org/jboss/util/ShutdownMBean.java
  
  Index: ShutdownMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/ShutdownMBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ShutdownMBean.java        2001/06/18 20:01:28     1.2
  +++ ShutdownMBean.java        2001/07/13 01:22:26     1.3
  @@ -7,16 +7,23 @@
   package org.jboss.util;
   
   /**
  - *   <description> 
  - *      
  - *   @see <related>
  - *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>.
  - *   @version $Revision: 1.2 $
  + * The management interface for the Shutdown bean.
  + * 
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.3 $
    */
   public interface ShutdownMBean
   {
  -   // Public --------------------------------------------------------
  -   public void shutdown();
  +   /**
  +    * Shutdown the virtual machine and run shutdown hooks.
  +    */
  +   void shutdown();
  +   
  +   /**
  +    * Forcibly terminates the currently running Java virtual machine.
  +    */
  +   void halt();
   }
   
   
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to