tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/mx DynamicMBeanProxy.java
Date Fri, 09 Aug 2002 17:39:07 GMT
costin      2002/08/09 10:39:07

  Modified:    util/java/org/apache/tomcat/util/mx DynamicMBeanProxy.java
  Log:
  Added 'createMBean( Object, domain, name )'.
  Any component that wants to be visible in JMX needs one line
  in the constructor:
  
    org.apache.tomcat.util.mx.DynamicMBeanProxy.createMBean( this, "domain", "name" );
  
  ( you can do that for other components as well ).
  
  I'll eventually refactor this into 2 classes and move to modeler,
  with one class beeing independent of JMX.
  
  Revision  Changes    Path
  1.4       +29 -2     jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/mx/DynamicMBeanProxy.java
  
  Index: DynamicMBeanProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/mx/DynamicMBeanProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicMBeanProxy.java	2 Jul 2002 19:56:24 -0000	1.3
  +++ DynamicMBeanProxy.java	9 Aug 2002 17:39:07 -0000	1.4
  @@ -112,7 +112,15 @@
   
           if( real==null ) return null;
   
  -        name=real.getClass().getName();
  +        name=generateName(real.getClass());
  +        return name;
  +    }
  +
  +    /** If a name was not provided, generate a name based on the
  +     *  class name and a sequence number.
  +     */
  +    public String generateName(Class realClass) {
  +        name=realClass.getName();
           name=name.substring( name.lastIndexOf( ".") + 1 );
           Integer iInt=(Integer)instances.get(name );
           if( iInt!= null ) {
  @@ -125,12 +133,30 @@
           }
           return name;
       }
  +
  +    public static void createMBean( Object proxy, String domain, String name ) {
  +        try {
  +            DynamicMBeanProxy mbean=new DynamicMBeanProxy();
  +            mbean.setReal( proxy );
  +            if( name!=null ) {
  +                mbean.setName( name );
  +            }
  +
  +            mbean.registerMBean( domain );
  +        } catch( Throwable t ) {
  +            log.error( "Error creating mbean ", t );
  +        }
  +    }
       
       public void registerMBean( String domain ) {
           try {
               // XXX use aliases, suffix only, proxy.getName(), etc
               ObjectName oname=new ObjectName( domain + ": name=" +  getName());
  -            
  +
  +            if(  getMBeanServer().isRegistered( oname )) {
  +                log.info("Unregistering " + oname );
  +                getMBeanServer().unregisterMBean( oname );
  +            }
               getMBeanServer().registerMBean( this, oname );
           } catch( Throwable t ) {
               log.error( "Error creating mbean ", t );
  @@ -298,6 +324,7 @@
           throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
ReflectionException
       {
           if( methods==null ) init();
  +        // XXX Send notification !!!
           Method m=(Method)setAttMap.get( attribute.getName() );
           if( m==null ) throw new AttributeNotFoundException(attribute.getName());
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message