User: hugo    
  Date: 00/12/13 01:16:45

  Modified:    src/main/org/jboss/util ServiceControl.java
  Log:
  Changed ServiceControl's start/shutdown sequences, so that beans not shutdown in 
reverse order...
  Hugo Pinto.
  
  Revision  Changes    Path
  1.5       +49 -38    jboss/src/main/org/jboss/util/ServiceControl.java
  
  Index: ServiceControl.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/util/ServiceControl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServiceControl.java       2000/12/13 00:22:16     1.4
  +++ ServiceControl.java       2000/12/13 09:16:44     1.5
  @@ -22,13 +22,15 @@
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
    *   @author Hugo Pinto (mailto:[EMAIL PROTECTED])
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    */
   public class ServiceControl
  +
      implements ServiceControlMBean, MBeanRegistration, NotificationListener
   {
      // Constants -----------------------------------------------------
      public static final String OBJECT_NAME = ":service=ServiceControl";
  +
       
      // Attributes ----------------------------------------------------
      Log log = Log.createLog("Service Control");
  @@ -44,9 +46,6 @@
      public void init()
         throws Exception
      {
  -     invokeOnMBeans ("init", "Initializing", "initialize", "Initialized");
  -     
  -     /*
         log.log("Initializing "+mbeans.size()+" MBeans");
         
         List mbeansCopy = new ArrayList(mbeans);
  @@ -79,15 +78,11 @@
            }
         }
         log.log("Initialized "+mbeansCopy.size()+" services");
  -      */
      }
      
      public void start()
         throws Exception
      { 
  -             invokeOnMBeans ("start", "Starting", "start", "Started");
  -
  -     /* 
         log.log("Starting "+mbeans.size()+" MBeans");
         
         List mbeansCopy = new ArrayList(mbeans);
  @@ -117,58 +112,74 @@
            }
         }
         log.log("Started "+mbeansCopy.size()+" services");
  -      */
      }
      
      public void stop()
      {
  -     invokeOnMBeans ("stop", "Stopping", "stop", "Stopped");
  +      log.log("Stopping "+mbeans.size()+" MBeans");
  +      
  +      List mbeansCopy = new ArrayList(mbeans);
  +      ListIterator enum = mbeansCopy.listIterator();
  +      int serviceCounter = 0;
  +      while (enum.hasNext()) enum.next(); // pass them all
  +      while (enum.hasPrevious())
  +      {
  +         ObjectName name = (ObjectName)enum.previous();
  +         
  +         try
  +         {
  +            server.invoke(name, "stop", new Object[0], new String[0]);
  +            serviceCounter++;
  +         } catch (ReflectionException e)
  +         {
  +           // Not a service - ok 
  +         } catch (Throwable e)
  +         {
  +            log.error("Could not stop "+name);
  +            
  +            if (e instanceof RuntimeErrorException)
  +            {
  +               e = ((RuntimeErrorException)e).getTargetError();
  +            }
  +            
  +            log.exception(e);
  +         }
  +      }
  +      log.log("Stopped "+mbeansCopy.size()+" services");
      }
      
      public void destroy()
  -   {
  -     invokeOnMBeans ("destroy", "Destroying", "destroy", "Destroyed");
  -   }
  -   
  -   public void invokeOnMBeans (String methodname, String aboutaction, String 
action, String pastaction)  
      {
  -      log.log(aboutaction + " "+mbeans.size()+" MBeans");
  +      log.log("Destroying "+mbeans.size()+" MBeans");
         
         List mbeansCopy = new ArrayList(mbeans);
  -      Iterator enum = mbeansCopy.iterator();
  +      ListIterator enum = mbeansCopy.listIterator();
         int serviceCounter = 0;
  -      while (enum.hasNext())
  +      while (enum.hasNext()) enum.next(); // pass them all
  +      while (enum.hasPrevious())
         {
  -         ObjectName name = (ObjectName)enum.next();
  +         ObjectName name = (ObjectName)enum.previous();
  +         
            try
            {
  -            server.invoke(name, methodname, new Object[0], new String[0]);
  +            server.invoke(name, "destroy", new Object[0], new String[0]);
               serviceCounter++;
  -            
  -            // Register start/stop listener
  -            try {
  -             server.addNotificationListener(name,
  -                                                 this,
  -                                               null,
  -                                             name);
  -            } catch (Exception ex) {
  -             log.error ("Warning: " + ex.getMessage());
  -            }        
            } catch (ReflectionException e)
            {
              // Not a service - ok 
  -         } catch (RuntimeMBeanException e)
  -         {
  -            log.error("Could not " + action+" "+name);
  -            log.exception(e.getTargetException());
  -         } catch (Exception e)
  +         } catch (Throwable e)
            {
  -            log.error("Could not "+action  +" "+name);
  +            log.error("Could not destroy "+name);
  +            
  +            if (e instanceof RuntimeErrorException)
  +            {
  +               e = ((RuntimeErrorException)e).getTargetError();
  +            }
  +            
               log.exception(e);
            }
         }
  -      log.log(pastaction+" "+mbeansCopy.size()+" services");
  -      
  +      log.log("Destroyed "+mbeansCopy.size()+" services");
      }
      
      
  
  
  

Reply via email to