You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2003/01/28 06:29:22 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java

costin      2003/01/27 21:29:22

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        MBeanUtils.java
  Log:
  Another commit - my workspace is almost in sync now.
  
  Make few methods public - so same code will be used to create the names.
  More important - replace the use of the hashcode in the Valve names with a seq.
  number.
  
  One change I'm not committing yet is use of .ser cache for mbeans-descriptors.xml.
  
  Revision  Changes    Path
  1.10      +41 -18    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java
  
  Index: MBeanUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MBeanUtils.java	22 Nov 2002 22:36:51 -0000	1.9
  +++ MBeanUtils.java	28 Jan 2003 05:29:22 -0000	1.10
  @@ -68,6 +68,7 @@
   import java.lang.reflect.Method;
   import java.net.URL;
   import java.net.URLEncoder;
  +import java.util.Hashtable;
   
   import javax.management.Attribute;
   import javax.management.InstanceAlreadyExistsException;
  @@ -102,6 +103,7 @@
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   import org.apache.catalina.Valve;
  +import org.apache.catalina.valves.ValveBase;
   import org.apache.catalina.core.StandardService;
   import org.apache.catalina.deploy.ContextEnvironment;
   import org.apache.catalina.deploy.ContextResource;
  @@ -870,7 +872,7 @@
        *
        * @exception MalformedObjectNameException if a name cannot be created
        */
  -    static ObjectName createObjectName(String domain,
  +    public static ObjectName createObjectName(String domain,
                                                 ContextEnvironment environment)
           throws MalformedObjectNameException {
   
  @@ -924,7 +926,7 @@
        *
        * @exception MalformedObjectNameException if a name cannot be created
        */
  -    static ObjectName createObjectName(String domain,
  +    public static ObjectName createObjectName(String domain,
                                                 ContextResource resource)
           throws MalformedObjectNameException {
   
  @@ -983,7 +985,7 @@
        *
        * @exception MalformedObjectNameException if a name cannot be created
        */
  -    static ObjectName createObjectName(String domain,
  +    public static ObjectName createObjectName(String domain,
                                                 ContextResourceLink resourceLink)
           throws MalformedObjectNameException {
   
  @@ -1522,8 +1524,13 @@
        * @exception MalformedObjectNameException if a name cannot be created
        */
       static ObjectName createObjectName(String domain,
  -                                              Valve valve)
  +                                       Valve valve)
           throws MalformedObjectNameException {
  +        if( valve instanceof ValveBase ) {
  +            ObjectName name=((ValveBase)valve).getObjectName();
  +            if( name != null )
  +                return name;
  +        }
   
           ObjectName name = null;
           Container container = null;
  @@ -1538,15 +1545,15 @@
           
           if (container instanceof Engine) {
               Service service = ((Engine)container).getService();
  +            String local=",service=" + service.getName();
               name = new ObjectName(domain + ":type=Valve,sequence=" +
  -                                  valve.hashCode() + ",service=" +
  -                                  service.getName());
  +                                  getSeq(local) + local );
           } else if (container instanceof Host) {
               Service service = ((Engine)container.getParent()).getService();
  +            String local=",host=" +container.getName() + ",service=" +
  +                    service.getName();
               name = new ObjectName(domain + ":type=Valve,sequence=" +
  -                                  valve.hashCode() + ",host=" +
  -                                  container.getName() + ",service=" +
  -                                  service.getName() );
  +                                  getSeq(local) + local);
           } else if (container instanceof Context) {
               String path = ((Context)container).getPath();
               if (path.length() < 1) {
  @@ -1554,17 +1561,29 @@
               }
               Host host = (Host) container.getParent();
               Service service = ((Engine) host.getParent()).getService();
  +            String local=",path=" + path + ",host=" +
  +                    host.getName() + ",service=" + service.getName();
               name = new ObjectName(domain + ":type=Valve,sequence=" +
  -                                  valve.hashCode() + ",path=" +
  -                                  path + ",host=" +
  -                                  host.getName() + ",service=" +
  -                                  service.getName());
  +                                  getSeq(local) + local );
           }
   
           return (name);
   
       }
   
  +    static Hashtable seq=new Hashtable();
  +    static int getSeq( String key ) {
  +        int i[]=(int [])seq.get( key );
  +        if (i == null ) {
  +            i=new int[1];
  +            i[0]=0;
  +            seq.put( key, i);
  +        } else {
  +            i[0]++;
  +        }
  +        return i[0];
  +    }
  +
       /**
        * Create and configure (if necessary) and return the registry of
        * managed object descriptions.
  @@ -1572,14 +1591,18 @@
       public synchronized static Registry createRegistry() {
   
           if (registry == null) {
  +            registry = Registry.getRegistry();
  +            // If that failed - try the xml source
               try {
  -                URL url = ServerLifecycleListener.class.getResource
  +		 URL url = ServerLifecycleListener.class.getResource
                       ("/org/apache/catalina/mbeans/mbeans-descriptors.xml");
  +
                   InputStream stream = url.openStream();
                   //                Registry.setDebug(1);
                   Registry.loadRegistry(stream);
                   stream.close();
                   registry = Registry.getRegistry();
  +
               } catch (Throwable t) {
                   t.printStackTrace(System.out);
                   System.exit(1);
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On 28 Jan 2003 costin@apache.org wrote:

> Date: 28 Jan 2003 05:29:22 -0000
> From: costin@apache.org
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: jakarta-tomcat-catalina-cvs@apache.org
> Subject: cvs commit:
>     jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans
>     MBeanUtils.java
>
> costin      2003/01/27 21:29:22
>
>   Modified:    catalina/src/share/org/apache/catalina/mbeans
>                         MBeanUtils.java
>   Log:
>   Another commit - my workspace is almost in sync now.
>
>   Make few methods public - so same code will be used to create the names.
>   More important - replace the use of the hashcode in the Valve names with a seq.
>   number.
>

Just a word of warning ... we tried sequence numbers for Valves initially,
but got into problems when contexts were reloaded.  Make sure you've
covered all of those corner cases.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>