/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jmx.shutdown;

import javax.naming.InitialContext;

import org.jboss.system.ServiceMBeanSupport;

/** A service that calls System.exit from its stopService method. Note that
 * this service cannot be deployed when the server is shutdown as its call
 * to System.exit(0) will hang the vm in java.lang.Shutdown.exit as the
 * as the Shutdown.class monitor is already held by the signal handler.
 * 
 * @author Scott.Stark@jboss.org
 * @version $Revision: 1.1.2.2 $
 */
public class ExitOnShutdown
   extends ServiceMBeanSupport
   implements ExitOnShutdownMBean
{
   protected void startService() throws Exception
   {
      InitialContext ctx = new InitialContext();
      ctx.bind("ExitOnShutdown", Boolean.TRUE);
   }

   protected void stopService() throws Exception
   {
      System.exit(0);
   }
}
