User: oberg   
  Date: 00/05/30 11:32:34

  Modified:    src/main/org/jboss/util ServiceMBeanSupport.java
  Log:
  Major update. Too much to mention.
  
  Revision  Changes    Path
  1.3       +57 -6     jboss/src/main/org/jboss/util/ServiceMBeanSupport.java
  
  Index: ServiceMBeanSupport.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/util/ServiceMBeanSupport.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceMBeanSupport.java  2000/05/19 07:12:01     1.2
  +++ ServiceMBeanSupport.java  2000/05/30 18:32:33     1.3
  @@ -20,11 +20,11 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.2 $
  + *   @version $Revision: 1.3 $
    */
   public abstract class ServiceMBeanSupport
      extends NotificationBroadcasterSupport
  -   implements ServiceMBean, MBeanRegistration
  +   implements ServiceMBean, MBeanRegistration, Service
   {
      // Attributes ----------------------------------------------------
      private int state;
  @@ -42,9 +42,6 @@
      // Static --------------------------------------------------------
   
      // Public --------------------------------------------------------
  -   public abstract ObjectName getObjectName(MBeanServer server, ObjectName name)
  -      throws javax.management.MalformedObjectNameException;
  -   
      public abstract String getName();
   
      public int getState()
  @@ -57,6 +54,26 @@
         return states[state];
      }
      
  +     public void init()
  +             throws Exception
  +     {
  +             log.log("Initializing");
  +             log.setLog(log);
  +             try
  +             {
  +                initService();
  +             } catch (Exception e)
  +             {
  +                log.error("Initialization failed");
  +                log.exception(e);
  +                throw e;
  +             } finally
  +             {
  +                log.unsetLog();
  +             }
  +             log.log("Initialized");
  +     }
  +     
      public void start()
         throws Exception
      {
  @@ -104,10 +121,29 @@
         log.unsetLog();
      }
      
  +   public void destroy()
  +   {
  +     log.log("Destroying");
  +     log.setLog(log);
  +     try
  +     {
  +        destroyService();
  +     } catch (Exception e)
  +     {
  +        log.exception(e);
  +     }
  +     
  +     log.unsetLog();
  +     log.log("Destroyed");
  +   }
  +     
      public ObjectName preRegister(MBeanServer server, ObjectName name)
         throws java.lang.Exception
      {
                name = getObjectName(server, name);
  +
  +             init();
  +             
         start();
         return name;
      }
  @@ -125,16 +161,31 @@
      
      public void postDeregister()
      {
  -      stop();
  +             if (getState() == STARTED)
  +           stop();
  +             
  +        destroy();
      }
      
      // Protected -----------------------------------------------------
  +   protected abstract ObjectName getObjectName(MBeanServer server, ObjectName name)
  +      throws javax.management.MalformedObjectNameException;
  +   
  +   protected void initService()
  +      throws Exception
  +   {
  +   }
  +     
      protected void startService()
         throws Exception
      {
      }
      
      protected void stopService()
  +   {
  +   }
  +     
  +   protected void destroyService()
      {
      }
   }
  
  
  

Reply via email to