User: d_jencks
  Date: 02/03/23 21:35:01

  Modified:    src/main/org/jboss/system ServiceConfigurator.java
                        ServiceContext.java ServiceController.java
  Removed:     src/main/org/jboss/system ServiceControllerMBean.java
  Log:
  Moved mbean xml config processing entirely into ServiceConfigurator and added nested 
mbean configuration processing.  Made a couple more mbean interfaces xdoclet generated
  
  Revision  Changes    Path
  1.4       +290 -160  jboss-system/src/main/org/jboss/system/ServiceConfigurator.java
  
  Index: ServiceConfigurator.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-system/src/main/org/jboss/system/ServiceConfigurator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceConfigurator.java  2 Mar 2002 01:16:37 -0000       1.3
  +++ ServiceConfigurator.java  24 Mar 2002 05:35:01 -0000      1.4
  @@ -9,50 +9,54 @@
   
   package org.jboss.system;
   
  +
  +
  +
  +
   import java.beans.PropertyEditor;
   import java.beans.PropertyEditorManager;
   import java.io.StringWriter;
   import java.io.Writer;
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  -import java.util.StringTokenizer;
  -import java.util.LinkedList;
   import java.util.ArrayList;
   import java.util.Hashtable;
  -
  +import java.util.LinkedList;
  +import java.util.List;
  +import java.util.ListIterator;
  +import java.util.StringTokenizer;
   import javax.management.Attribute;
   import javax.management.InstanceNotFoundException;
   import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanException;
   import javax.management.MBeanInfo;
   import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectInstance;
   import javax.management.ObjectName;
  -import javax.management.MBeanException;
   import javax.management.ReflectionException;
  -import javax.management.RuntimeOperationsException;
  -import javax.management.RuntimeMBeanException;
   import javax.management.RuntimeErrorException;
  -
  +import javax.management.RuntimeMBeanException;
  +import javax.management.RuntimeOperationsException;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
  -
  +import org.jboss.deployment.DeploymentException;
  +import org.jboss.logging.Logger;
  +import org.jboss.util.jmx.JMXExceptionDecoder;
  +import org.jboss.util.jmx.ObjectNameFactory;
  +import org.jboss.util.xml.DOMWriter;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   import org.w3c.dom.Text;
   
  -import org.jboss.deployment.DeploymentException;
  -import org.jboss.logging.Logger;
  -import org.jboss.util.xml.DOMWriter;
  -
   /**
    * Service configuration helper.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Hiram Chirino</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    *
    * <p><b>20010830 marc fleury:</b>
    * <ul>
  @@ -81,119 +85,111 @@
      }
      
      /** The MBean server which this service is registered in. */
  -   private MBeanServer server;
  +   private final MBeanServer server;
  +   private final ServiceController serviceController;
  +   private final ServiceCreator serviceCreator;
      
      /** The instance logger. */
  -   private static Logger log = Logger.getLogger(ServiceConfigurator.class);
  +   private final Logger log = Logger.getLogger(getClass());
      
      // Constructors --------------------------------------------------
      
  -   public ServiceConfigurator(final MBeanServer server)
  +   public ServiceConfigurator(final MBeanServer server,
  +                              final ServiceController serviceController,
  +                              final ServiceCreator serviceCreator)
      {
         this.server = server;
  +      this.serviceController = serviceController;
  +      this.serviceCreator = serviceCreator;
      }
      
      // Public  -------------------------------------------------------
      
  -   /** A helper to deal with those pesky JMX exceptions. */
  -   private void setAttribute(ObjectName name, Attribute attr)
  -      throws Exception
  -   {
  -      try {
  -         server.setAttribute(name, attr);
  -      }
  -      catch (MBeanException e) {
  -         throw e.getTargetException();
  -      }
  -      catch (ReflectionException e) {
  -         throw e.getTargetException();
  -      }
  -      catch (RuntimeOperationsException e) {
  -         throw e.getTargetException();
  -      }
  -      catch (RuntimeMBeanException e) {
  -         throw e.getTargetException();
  -      }
  -      catch (RuntimeErrorException e) {
  -         throw e.getTargetError();
  -      }
  -   }
  +
  +   // Public -----------------------------------------------------
   
      /**
  -   * Builds a string that consists of the configuration elements of
  -   * the currently running MBeans registered in the server.
  -   *
  -   * @throws Exception    Failed to construct configuration.
  -   */
  -   public String getConfiguration(ObjectName[] objectNames)
  -   throws Exception
  +    * The <code>install</code> method iterates through the mbean tags in the 
  +    * supplied xml configuration and creates and configures the mbeans shown.
  +    * The mbean configuration can be nested.  
  +    * 
  +    * @param config the xml <code>Element</code> containing the configuration of 
the 
  +    * mbeans to create and configure.
  +    * @return a <code>List</code> of ObjectNames of created mbeans.
  +    * @exception DeploymentException if an error occurs
  +    */
  +   public List install(Element config) throws DeploymentException
      {
  -      boolean debug = log.isDebugEnabled();
  -
  -      Writer out = new StringWriter();
  -
  -      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  -      DocumentBuilder builder = factory.newDocumentBuilder();
  -      Document doc = builder.newDocument();
  -
  -      Element serverElement = doc.createElement("server");
  -
  -      // Store attributes as XML
  -      for (int j = 0 ; j<objectNames.length ; j++)
  +      List mbeans = new ArrayList();
  +      try 
         {
  -         ObjectInstance instance = server.getObjectInstance(objectNames[j]);
  -         ObjectName name = (ObjectName)instance.getObjectName();
  -         Element mbeanElement = doc.createElement("mbean");
  -         mbeanElement.setAttribute("name", name.toString());
  -
  -         MBeanInfo info = server.getMBeanInfo(name);
  -         mbeanElement.setAttribute("code", info.getClassName());
  -         MBeanAttributeInfo[] attributes = info.getAttributes();
  -         boolean hasAttributes = true;
  -         for (int i = 0; i < attributes.length; i++)
  +         NodeList nl = config.getChildNodes();
  +      
  +         for (int i = 0; i < nl.getLength(); i++)
            {
  -            if (attributes[i].isReadable() && 
isAttributeWriteable(server.getObjectInstance(name).getClassName(), 
attributes[i].getName(), attributes[i].getType()))
  +            if (nl.item(i).getNodeType() == Node.ELEMENT_NODE)
               {
  -               if (!attributes[i].isWritable())
  -               {
  -                  if (debug)
  -                     log.debug("Detected JMX Bug: Server reports attribute 
'"+attributes[i].getName() + "' is not writeable for MBean '" + 
name.getCanonicalName() + "'");
  -               }
  -               Element attributeElement = doc.createElement("attribute");
  -               Object value = server.getAttribute(name, attributes[i].getName());
  -
  -               attributeElement.setAttribute("name", attributes[i].getName());
   
  -               if (value != null)
  +               Element element = (Element)nl.item(i);
  +               if (element.getTagName().equals("mbean"))
                  {
  -                  
attributeElement.appendChild(doc.createTextNode(value.toString()));
  -               }
  -               
  -               mbeanElement.appendChild(attributeElement);
  -               hasAttributes = true;
  -            }
  +                  Element mbean = (Element)nl.item(i);
  +                  internalInstall(mbean, mbeans);
  +               } // end of if ()
  +            } // end of if ()
            }
  -         
  -         if (hasAttributes)
  +         return mbeans;      
  +      }
  +      catch (DeploymentException de)
  +      {
  +         for (ListIterator li = mbeans.listIterator(mbeans.size()); 
li.hasPrevious();)
            {
  -            serverElement.appendChild(mbeanElement);
  -         }
  +            ObjectName mbean = (ObjectName)li.previous();
  +            try 
  +            {
  +               serviceCreator.remove(mbean);
  +            }
  +            catch (Exception e)
  +            {
  +               log.info("exception removing mbean after failed deployment: " + 
mbean, e);  
  +            } // end of try-catch
  +            
  +         } // end of for ()
  +         
  +         throw de;
  +      } // end of try-catch
  +   }
  +
  +   private ObjectName internalInstall(Element mbean, List mbeans) throws 
DeploymentException
  +   {
  +      ObjectName mbeanName = null;
  +      try 
  +      {
  +         mbeanName = serviceCreator.install(mbean).getObjectName();
         }
  +      catch (Exception e)
  +      {
  +         throw new DeploymentException("could not create mbean", e);
  +      } // end of catch
         
  -      doc.appendChild(serverElement);
  -      
  -      // Write configuration
  -      (new DOMWriter(out, false)).print(doc, true);
  -      
  -      out.close();
  -
  -      // Return configuration
  -      return out.toString();
  +      mbeans.add(mbeanName);
  +      if (mbeanName != null) 
  +      {
  +         try 
  +         {
  +            configure(mbeanName, mbean, mbeans);
  +            serviceController.getServiceContext(mbeanName).state = 
ServiceContext.CONFIGURED;
  +         }
  +         catch (DeploymentException de)
  +         {
  +            serviceController.getServiceContext(mbeanName).state = 
ServiceContext.FAILED;
  +            throw de;
  +         } // end of try-catch
  +         
  +      } // end of if ()
  +         
  +      return mbeanName;
      }
  -
  -
  -   // Public -----------------------------------------------------
  -
      /**
      * The <code>configure</code> method configures an mbean based on the xml element 
configuration
      * passed in.  Three formats are supported:
  @@ -203,20 +199,19 @@
      * [list of]  &lt;/depends-list-element&gt;(object 
name)&lt;/depends-list-element&gt;
      * &lt;/depends-list&gt;
      *
  +   * The last two can include nested mbean configurations or ObjectNames.
  +   * SIDE-EFFECT: adds all mbeans this one depends on to the ServiceContext 
structures.
      * @param mbeanElement an <code>Element</code> value
  -   * @return a <code>ArrayList</code> of all the mbeans this one references.
      * @exception Exception if an error occurs
      */
  -   public ArrayList configure(Element mbeanElement)
  -   throws Exception
  +   protected void configure(ObjectName objectName, Element mbeanElement, List 
mbeans)
  +   throws DeploymentException
      {
   
         // Set configuration to MBeans from XML
   
         boolean debug = log.isDebugEnabled();
   
  -      // get the name of the mbean
  -      ObjectName objectName = parseObjectName(mbeanElement);
   
         MBeanInfo info;
         try
  @@ -227,12 +222,17 @@
            // The MBean is no longer available
            throw new DeploymentException("trying to configure nonexistent mbean: " + 
objectName);
         }
  -      // Set mbean references (object names)
  -      ArrayList mbeans = new ArrayList();
  -
  +      catch (Exception e)
  +      {
  +         throw new DeploymentException("Could not get mbeanInfo", 
JMXExceptionDecoder.decode(e));
  +      } // end of catch
  +      if (info == null) 
  +      {
  +         throw new DeploymentException("MBeanInfo is null for mbean: " + 
objectName);
  +      } // end of if ()
  +      
         // Set attributes
         MBeanAttributeInfo[] attributes = info.getAttributes();
  -      //NodeList attrs = mbeanElement.getElementsByTagName("attribute");
         NodeList attrs = mbeanElement.getChildNodes();
         for (int j = 0; j < attrs.getLength(); j++)
         {
  @@ -266,7 +266,15 @@
                        }
                        else
                        {
  -                        typeClass = Class.forName(typeName);
  +                           try 
  +                           {
  +                              typeClass = Class.forName(typeName);
  +                           }
  +                           catch (ClassNotFoundException e)
  +                           {
  +                              throw new DeploymentException("Attribute class " + 
typeName + " not found");
  +                           } // end of try-catch
  +                           
                        }
   
                        Object value = null;
  @@ -292,7 +300,7 @@
                        {
                           PropertyEditor editor = 
PropertyEditorManager.findEditor(typeClass);
                              if (editor == null) {
  -                              throw new ConfigurationException
  +                              throw new DeploymentException
                                    ("No property editor for attribute: " + 
attributeName + 
                                     "; type=" + typeClass);
                              }
  @@ -301,8 +309,7 @@
                           value = editor.getValue();
                        }
                        
  -                     if (debug)
  -                        log.debug(attributeName + " set to " + value + " in " + 
objectName);
  +                        log.debug(attributeName + " set to " + value + " in " + 
objectName);
                     
                        setAttribute(objectName, new Attribute(attributeName, value));
                     
  @@ -331,13 +338,7 @@
               } // end of if ()
            
               // Get the mbeanRef value
  -            String value = ((Text)element.getFirstChild()).getData().trim();
  - 
  -            ObjectName dependsObjectName = new ObjectName(value);
  -            if (!mbeans.contains(dependsObjectName)) 
  -            {
  -               mbeans.add(dependsObjectName);
  -            } // end of if ()
  +            ObjectName dependsObjectName = processDependency(objectName, element, 
mbeans);
               if (debug)
                  log.debug("considering " + ((mbeanRefName == null)? "<anonymous>": 
mbeanRefName.toString()) + " with object name " + dependsObjectName);
               if (mbeanRefName != null) 
  @@ -356,27 +357,29 @@
                  dependsListName = null;
               } // end of if ()
   
  -            NodeList dependsList = 
element.getElementsByTagName("depends-list-element");
  +            NodeList dependsList = element.getChildNodes();
               ArrayList dependsListNames = new ArrayList();
               for (int l = 0; l < dependsList.getLength(); l++) 
               {
  -               Element dependsElement = (Element)dependsList.item(l);
  -               if (!dependsElement.hasChildNodes()) 
  -               {
  -                  throw new DeploymentException("Empty depends-list-element!");    
  -               } // end of if ()
  +                  if (dependsList.item(l).getNodeType() == Node.ELEMENT_NODE)
  +                  {
   
  -               // Get the depends value
  -               String dependsValue = 
((Text)dependsElement.getFirstChild()).getData().trim();
  -               ObjectName dependsObjectName = new ObjectName(dependsValue);
  -               if (!dependsListNames.contains(dependsObjectName)) 
  -               {
  -                  dependsListNames.add(dependsObjectName);
  -               } // end of if ()
  -               if (!mbeans.contains(dependsObjectName)) 
  -               {
  -                  mbeans.add(dependsObjectName);
  -               } // end of if ()
  +                     Element dependsElement = (Element)dependsList.item(l);
  +                     if (dependsElement.getTagName().equals("depends-list-element"))
  +                     {
  +                        if (!dependsElement.hasChildNodes()) 
  +                        {
  +                           throw new DeploymentException("Empty 
depends-list-element!");    
  +                        } // end of if ()
  +                     
  +                        // Get the depends value
  +                        ObjectName dependsObjectName = 
processDependency(objectName, dependsElement, mbeans);
  +                        if (!dependsListNames.contains(dependsObjectName)) 
  +                        {
  +                           dependsListNames.add(dependsObjectName);
  +                        } // end of if ()
  +                     }
  +                  }
               
               } // end of for ()
               if (dependsListName != null) 
  @@ -386,33 +389,83 @@
            }//end of depends-list
         }
         }
  -      return mbeans;
      }
  -   
  -   
  -   
  -   /**
  -   * Parse an object name from the given element attribute 'name'.
  -   *
  -   * @param element    Element to parse name from.
  -   * @return           Object name.
  -   *
  -   * @throws ConfigurationException   Missing attribute 'name'
  -   *                                  (thrown if 'name' is null or "").
  -   * @throws MalformedObjectNameException
  -   */
  -   private ObjectName parseObjectName(final Element element)
  -   throws ConfigurationException, MalformedObjectNameException
  +
  +   private ObjectName processDependency(ObjectName container, Element element, List 
mbeans) 
  +      throws DeploymentException
      {
  -      String name = element.getAttribute("name");
  -      if (name == null || name.trim().equals(""))
  +      ObjectName dependsObjectName = null;
  +      NodeList nl = element.getChildNodes();
  +      for (int i = 0; i < nl.getLength(); i++)
         {
  -         throw new ConfigurationException
  -         ("MBean attribute 'name' must be given.");
  +         Node childNode = nl.item(i);
  +         if (childNode.getNodeType() == Node.ELEMENT_NODE)
  +         {
  +            
  +            Element child = (Element)childNode;
  +            if (child.getTagName().equals("mbean"))
  +            {
  +               dependsObjectName = internalInstall(child, mbeans);
  +               break;
  +            }
  +            else
  +            {
  +               throw new DeploymentException("Non mbean child element in depends 
tag: " + child);
  +            } // end of else
  +         
  +            
  +         } // end of if ()
  +      } // end of for ()
  +      
  +      if (dependsObjectName == null)
  +      {
  +         if (nl.item(0).getNodeType() == Node.TEXT_NODE) 
  +         {
  +            String name = ((Text)nl.item(0)).getData().trim();
  +            
  +            dependsObjectName = ObjectNameFactory.create(name);
  +         
  +         } // end of if ()
  +         else
  +         {
  +            throw new DeploymentException("Nothing supplied for an object name! " + 
element);
  +         } // end of else
         }
  +      registerDependency(container, dependsObjectName);
  +      return dependsObjectName;
         
  -      return new ObjectName(name);
      }
  +
  +   
  +   /** A helper to deal with those pesky JMX exceptions. */
  +   private void setAttribute(ObjectName name, Attribute attr)
  +      throws DeploymentException
  +   {
  +      try {
  +         server.setAttribute(name, attr);
  +      }
  +      catch (Exception e) {
  +         throw new DeploymentException("Exception setting attribute " + attr + " on 
mbean " + name, JMXExceptionDecoder.decode(e));
  +      }
  +   }
  +
  +
  +   private void registerDependency(ObjectName needs, ObjectName used)
  +   {
  +      log.debug("recording that " + needs + " depends on " + used);
  +      ServiceContext needsCtx = serviceController.getServiceContext(needs);
  +      ServiceContext usedCtx = serviceController.getServiceContext(used);
  +               
  +
  +      if (!needsCtx.iDependOn.contains(usedCtx)) 
  +      {
  +         // needsCtx depends on usedCtx
  +         needsCtx.iDependOn.add(usedCtx);
  +         // UsedCtx needs to know I depend on him
  +         usedCtx.dependsOnMe.add(needsCtx);
  +      } // end of if ()
  +   }
  +   
      
      /**
      * Checks if an attribute of a given class is writtable.
  @@ -422,6 +475,7 @@
      * @param type          The attribute type that the setter takes.
      *
      * @throws Exception    Unable to determin if attribute is writable.
  +   * @todo Remove this -- used only in obsolete listConfiguration method.
      */
      private boolean isAttributeWriteable(final String className,
         final String attribute,
  @@ -480,6 +534,7 @@
      *
      * @param m     The method to check.
      * @return      True if the method is a "setter" method.
  +   * @todo Remove this -- used only in obsolete listConfiguration method.
      */
      private boolean isSetterMethod(final Method m)
      {
  @@ -493,4 +548,79 @@
         
         return false;
      }
  +
  +   /**
  +   * Builds a string that consists of the configuration elements of
  +   * the currently running MBeans registered in the server.
  +   *
  +   * @throws Exception    Failed to construct configuration.
  +   * @todo replace with more sophisticated mbean persistence mechanism.
  +   */
  +   public String getConfiguration(ObjectName[] objectNames)
  +   throws Exception
  +   {
  +      boolean debug = log.isDebugEnabled();
  +
  +      Writer out = new StringWriter();
  +
  +      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +      DocumentBuilder builder = factory.newDocumentBuilder();
  +      Document doc = builder.newDocument();
  +
  +      Element serverElement = doc.createElement("server");
  +
  +      // Store attributes as XML
  +      for (int j = 0 ; j<objectNames.length ; j++)
  +      {
  +         ObjectInstance instance = server.getObjectInstance(objectNames[j]);
  +         ObjectName name = (ObjectName)instance.getObjectName();
  +         Element mbeanElement = doc.createElement("mbean");
  +         mbeanElement.setAttribute("name", name.toString());
  +
  +         MBeanInfo info = server.getMBeanInfo(name);
  +         mbeanElement.setAttribute("code", info.getClassName());
  +         MBeanAttributeInfo[] attributes = info.getAttributes();
  +         boolean hasAttributes = true;
  +         for (int i = 0; i < attributes.length; i++)
  +         {
  +            if (attributes[i].isReadable() && 
isAttributeWriteable(server.getObjectInstance(name).getClassName(), 
attributes[i].getName(), attributes[i].getType()))
  +            {
  +               if (!attributes[i].isWritable())
  +               {
  +                  if (debug)
  +                     log.debug("Detected JMX Bug: Server reports attribute 
'"+attributes[i].getName() + "' is not writeable for MBean '" + 
name.getCanonicalName() + "'");
  +               }
  +               Element attributeElement = doc.createElement("attribute");
  +               Object value = server.getAttribute(name, attributes[i].getName());
  +
  +               attributeElement.setAttribute("name", attributes[i].getName());
  +
  +               if (value != null)
  +               {
  +                  
attributeElement.appendChild(doc.createTextNode(value.toString()));
  +               }
  +               
  +               mbeanElement.appendChild(attributeElement);
  +               hasAttributes = true;
  +            }
  +         }
  +         
  +         if (hasAttributes)
  +         {
  +            serverElement.appendChild(mbeanElement);
  +         }
  +      }
  +      
  +      doc.appendChild(serverElement);
  +      
  +      // Write configuration
  +      (new DOMWriter(out, false)).print(doc, true);
  +      
  +      out.close();
  +
  +      // Return configuration
  +      return out.toString();
  +   }
  +
  +
   }
  
  
  
  1.2       +28 -2     jboss-system/src/main/org/jboss/system/ServiceContext.java
  
  Index: ServiceContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-system/src/main/org/jboss/system/ServiceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceContext.java       24 Feb 2002 10:24:34 -0000      1.1
  +++ ServiceContext.java       24 Mar 2002 05:35:01 -0000      1.2
  @@ -10,6 +10,7 @@
   package org.jboss.system;
   
   import javax.management.ObjectName;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.LinkedList;
   
  @@ -20,7 +21,7 @@
    * @see ServiceMBeanSupport
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>marc fleury</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    *   
    * <p><b>Revisions:</b>
    *
  @@ -43,6 +44,16 @@
      public static int DESTROYED = 6;
      public static int NOTYETINSTALLED = 7;
      
  +   private static String[] stateNames = 
  +   {"INSTALLED",
  +    "CONFIGURED",
  +    "CREATED",
  +    "RUNNING",
  +    "FAILED",
  +    "STOPPED",
  +    "DESTROYED",
  +    "NOTYETINSTALLED"};
  +
      /** The name of the service **/
      public ObjectName objectName;
      
  @@ -57,5 +68,20 @@
      
      /** the fancy proxy to my service calls **/
      public Service proxy;
  -   
  +
  +   public String toString()
  +   {
  +      return "ObjectName: " + objectName + "\n state: " + stateNames[state] + "\n I 
Depend On: " + printList(iDependOn) + "\n Depends On Me: " + printList(dependsOnMe);
  +   }
  +   
  +   private String printList(List ctxs)
  +   {
  +      StringBuffer result = new StringBuffer();
  +      for (Iterator i = ctxs.iterator(); i.hasNext();)
  +      {
  +         result.append("  
").append(((ServiceContext)i.next()).objectName).append("\n");
  +      } // end of for ()
  +      return result.toString();
  +   }
  +      
   }
  
  
  
  1.5       +78 -150   jboss-system/src/main/org/jboss/system/ServiceController.java
  
  Index: ServiceController.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-system/src/main/org/jboss/system/ServiceController.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServiceController.java    12 Mar 2002 01:05:00 -0000      1.4
  +++ ServiceController.java    24 Mar 2002 05:35:01 -0000      1.5
  @@ -34,6 +34,7 @@
   
   import org.w3c.dom.Element;
   
  +import org.jboss.deployment.DeploymentException;
   import org.jboss.logging.Logger;
   
   import org.jboss.util.jmx.JMXExceptionDecoder;
  @@ -46,7 +47,7 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  - * @version $Revision: 1.4 $ <p>
  + * @version $Revision: 1.5 $ <p>
    *
    * <b>Revisions:</b> <p>
    *
  @@ -64,6 +65,8 @@
    * <ol>
    *   <li>Rewrite
    * </ol>
  + *
  + * @jmx:mbean name="jboss.system:service=ServiceController"
    */
   public class ServiceController
      implements ServiceControllerMBean, MBeanRegistration
  @@ -76,7 +79,7 @@
      /** A callback to the JMX MBeanServer */
      MBeanServer server;
      
  -   /** Creator, helper class to instanciate MBeans **/
  +   /** Creator, helper class to instantiate MBeans **/
      protected ServiceCreator creator;
      
      /** Configurator, helper class to configure MBeans **/
  @@ -93,23 +96,31 @@
      // Public --------------------------------------------------------
      
      /**
  -   * Gets the Deployed attribute of the ServiceController object
  +   * Lists the ServiceContexts of deployed mbeans
      *
  -   * @return The Deployed value
  +   * @return the list of ServiceContexts for mbeans deployed through 
ServiceController.
  +   * @jmx:managed-operation
      */
  -   public ObjectName[] getDeployed()
  +   public List listDeployed()
      {
  -      ObjectName[] deployed = new ObjectName[installedServices.size()];
  -      
  -      ListIterator iterator = installedServices.listIterator();
  -      
  -      for (int i = 0; i<installedServices.size() ; i++)
  +      return new ArrayList(installedServices);
  +   }
  +   
  +   /**
  +   * lists ObjectNames of deployed mbeans deployed through serviceController.
  +   *
  +   * @return a list of ObjectNames of deployed mbeans.
  +   * @jmx:managed-operation
  +   */
  +   public List listDeployedNames()
  +   {
  +      List names = new ArrayList(installedServices.size());
  +      for (Iterator i = installedServices.iterator(); i.hasNext();)
         {
  -         ServiceContext ctx = (ServiceContext) iterator.next();
  -         deployed[i] = ctx.objectName;
  -      }
  -
  -      return deployed;
  +         names.add(((ServiceContext)i.next()).objectName);
  +      } // end of for ()
  +      
  +      return names;
      }
      
      /**
  @@ -118,8 +129,9 @@
      * @param objectNames Description of Parameter
      * @return The Configuration value
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
  -   public String getConfiguration(ObjectName[] objectNames) throws Exception
  +   public String listConfiguration(ObjectName[] objectNames) throws Exception
      {
         return configurator.getConfiguration(objectNames);
      }
  @@ -127,83 +139,25 @@
      /**
      * Deploy the beans
      *
  -   * Deploy means "instanciate and configure" so the MBean is created in the 
MBeanServer
  +   * Deploy means "instantiate and configure" so the MBean is created in the 
MBeanServer
      * You must call "create" and "start" separately on the MBean to affect the 
service lifecycle
      * deploy doesn't bother with service lifecycle only MBean 
instanciation/registration/configuration
      *  
      * @param mbeanElement Description of Parameter
      * @return Description of the Returned Value
      * @throws Exception ???
  +   * @jmx:managed-operation
      */
  -   public synchronized ObjectName install(Element mbeanElement)
  -      throws Exception
  +   public synchronized List install(Element config)
  +      throws DeploymentException
      {
  -      boolean debug = log.isDebugEnabled();
  -      
  -      // Create a Service Context for the service, or get one if it exists
  -      ServiceContext ctx = getServiceContext(parseObjectName(mbeanElement));
  -      
  -      // MARCF FIXME THINK ABOUT REMOVe IF ACTIVE HERE
  -      //at least make a new version!
  -      //remove(objectName);
  -      
  -      // It is not there so really create the component now, this registers the 
component in the mbeanserver
  -
  -      // deal with those pesky JMX exceptions
  -      try
  +      List mbeans = configurator.install(config);
  +      for (Iterator i = mbeans.iterator(); i.hasNext();)
         {
  -         creator.install(mbeanElement);
  -      }
  -      catch (Exception e)
  -      {
  -         JMXExceptionDecoder.rethrow(e);
  -      }
  -
  -      // We got this far
  -      ctx.state = ServiceContext.INSTALLED;
  -      
  -      try
  -      {
  -         // Configure the MBean
  -         synchronized (this)
  -         {
  -            // The return is a list of MBeans this MBean "depends" on
  -            List mbeans = configurator.configure(mbeanElement);
  -            
  -            // Link the dependency me.idependOn(them) and them.dependsOnMe(me)
  -            Iterator iterator = mbeans.iterator();
  -            while (iterator.hasNext()) {
  -               
  -               // We work from the service context, if it doesn't exist yet, we 
have a wrapper (OK)
  -               ServiceContext service = getServiceContext((ObjectName) 
iterator.next());
  -               
  -               if (debug)
  -                  log.debug("recording that " + ctx.objectName + " depends on " + 
service.objectName);
  -               // ctx depends on service
  -               ctx.iDependOn.add(service);
  -               
  -               // Service needs to know I depend on him
  -               service.dependsOnMe.add(ctx);
  -            }
  -         } 
  -      }
  -      catch (Exception e)
  -      {
  -         log.error("Could not configure MBean: " + ctx.objectName, e);
  -         
  -         server.unregisterMBean(ctx.objectName);
  -         
  -         ctx.state = ServiceContext.FAILED ; 
  -         throw e;
  -      }
  -      
  -      // We got this far
  -      ctx.state = ServiceContext.CONFIGURED;
  -      
  -      if ( !installedServices.contains(ctx))
  -         installedServices.add(ctx);
  -
  -      return ctx.objectName;
  +         ObjectName mbean = (ObjectName)i.next();
  +         installedServices.add(getServiceContext(mbean));
  +      } // end of for ()
  +      return mbeans;
      }
      
      /**
  @@ -211,6 +165,7 @@
      *
      * @param serviceName Description of Parameter
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
      public synchronized void create(ObjectName serviceName) throws Exception
      {  
  @@ -273,6 +228,7 @@
      *
      * @param serviceName Description of Parameter
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
      public synchronized void start(ObjectName serviceName) throws Exception
      {   
  @@ -348,6 +304,7 @@
      *
      * @param serviceName Description of Parameter
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
      public void stop(ObjectName serviceName) throws Exception
      {
  @@ -403,6 +360,7 @@
      *
      * @param serviceName Description of Parameter
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
      public void destroy(ObjectName serviceName) throws Exception
      {
  @@ -450,21 +408,11 @@
      }   
      
      /**
  -   * #Description of the Method
  -   *
  -   * @param mbeanElement Description of Parameter
  -   * @exception Exception Description of Exception
  -   */
  -   public void remove(Element mbeanElement) throws Exception
  -   {  
  -      remove(parseObjectName(mbeanElement));
  -   }
  -   
  -   /**
      * This MBean is going buh bye
      *
      * @param objectName Description of Parameter
      * @exception Exception Description of Exception
  +   * @jmx:managed-operation
      */
      public void remove(ObjectName objectName) throws Exception
      {
  @@ -507,6 +455,38 @@
         }
      }
      
  +   /**
  +    * Describe <code>shutdown</code> method here.
  +    *
  +    * @jmx:managed-operation
  +    */
  +   public synchronized void shutdown()
  +   {
  +      log.info("Stopping " + nameToServiceMap.size() + " services");
  +      
  +      List servicesCopy = new ArrayList(installedServices);
  +      
  +      int serviceCounter = 0;
  +      ObjectName name = null;
  +      
  +      ListIterator i = servicesCopy.listIterator(servicesCopy.size());
  +      while (i.hasPrevious()) 
  +      {
  +         name = ((ServiceContext)i.previous()).objectName;
  +         
  +         try
  +         {
  +            remove(name);
  +            serviceCounter++;
  +         }
  +         catch (Throwable e)
  +         {
  +            log.error("Could not remove " + name, e);
  +         }
  +      }
  +      log.info("Stopped " + serviceCounter + " services");
  +   }
  +   
      // MBeanRegistration implementation ----------------------------------------
      
      /**
  @@ -523,7 +503,7 @@
         this.server = server;
         
         creator = new ServiceCreator(server);
  -      configurator = new ServiceConfigurator(server);
  +      configurator = new ServiceConfigurator(server, this, creator);
         
         log.info("Controller MBean online");
         return name == null ? OBJECT_NAME : name;
  @@ -546,37 +526,6 @@
      {
      }
      
  -   // Service implementation ----------------------------------------
  -   
  -   /**
  -   * This is the only one we should have of these lifecycle methods!
  -   */
  -   public synchronized void shutdown()
  -   {
  -      log.info("Stopping " + nameToServiceMap.size() + " services");
  -      
  -      List servicesCopy = new ArrayList(installedServices);
  -      
  -      int serviceCounter = 0;
  -      ObjectName name = null;
  -      
  -      ListIterator i = servicesCopy.listIterator(servicesCopy.size());
  -      while (i.hasPrevious()) 
  -      {
  -         name = ((ServiceContext)i.previous()).objectName;
  -         
  -         try
  -         {
  -            remove(name);
  -            serviceCounter++;
  -         }
  -         catch (Throwable e)
  -         {
  -            log.error("Could not remove " + name, e);
  -         }
  -      }
  -      log.info("Stopped " + serviceCounter + " services");
  -   }
      
      /**
      * Get the Service interface through which the mbean given by objectName
  @@ -614,29 +563,6 @@
         return service;
      }
      
  -   /**
  -   * Parse an object name from the given element attribute 'name'.
  -   *
  -   * @param element   Element to parse name from.
  -   * @return          Object name.
  -   * 
  -   * @throws ConfigurationException   Missing attribute 'name' (thrown if 
  -   *                                  'name' is null or "").
  -   * @throws MalformedObjectNameException
  -   */
  -   private ObjectName parseObjectName(final Element element)
  -   throws ConfigurationException, MalformedObjectNameException
  -   {
  -      String name = element.getAttribute("name");
  -      if (name == null || name.trim().equals(""))
  -      {
  -         throw new ConfigurationException
  -         ("MBean attribute 'name' must be given.");
  -      }
  -      return new ObjectName(name);
  -   }
  -   
  -   // Inner classes -------------------------------------------------
      
      // Create a Service Context for the service, or get one if it exists
      public synchronized ServiceContext getServiceContext(ObjectName objectName)
  @@ -654,6 +580,8 @@
         
         return ctx;
      }
  +   
  +   // Inner classes -------------------------------------------------
      
      /**
      * A mapping from the Service interface method names to the corresponding
  
  
  

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

Reply via email to