avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces SystemManager.java
Date Sat, 13 Jul 2002 10:15:13 GMT
donaldp     2002/07/13 03:15:13

  Modified:    src/java/org/apache/avalon/phoenix/components/embeddor
                        DefaultEmbeddor.java
               src/java/org/apache/avalon/phoenix/components/kernel
                        DefaultKernel.java
               src/java/org/apache/avalon/phoenix/components/manager
                        AbstractSystemManager.java DefaultManager.java
                        MX4JSystemManager.java ManagedEntry.java
               src/java/org/apache/avalon/phoenix/interfaces
                        SystemManager.java
  Added:       src/java/org/apache/avalon/phoenix/components/manager
                        AbstractJMXManager.java SubContext.java
  Log:
  This patch implements the concept of a 'local' management context that
  objects are registered with.  I think its better than spreading the JMX
  naming scheme in different parts of the code.  The big change is the
  addition of the getSubContext() method to SystemManager.  The contexts are
  organized into hierarchy like this:
  
          Component List
                  Component 1
                  Component 2
          Application List
                  Application 1
                          Block List
                                  Block 1
                                  Block 2
                  Application 2
                          Block List
                                  Block 1
                                  Block 2
  
  JMX naming is then derived by 'walking' up to the top level context, which
  is the 'real' SystemManager.
  
  There is also significant refactoring to remove redundency between both JMX implementations.
  
  Submitted by: Huw Roberts <Huw@mmlive.com>
  
  Revision  Changes    Path
  1.71      +16 -8     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- DefaultEmbeddor.java	20 Jun 2002 11:39:31 -0000	1.70
  +++ DefaultEmbeddor.java	13 Jul 2002 10:15:12 -0000	1.71
  @@ -604,17 +604,22 @@
       {
           final SystemManager systemManager =
               (SystemManager)getServiceManager().lookup( SystemManager.ROLE );
  -        systemManager.register( ManagementRegistration.EMBEDDOR.getName(),
  -                                this, ManagementRegistration.EMBEDDOR.getInterfaces() );
  +
  +        final SystemManager componentManager =
  +            systemManager.getSubContext( null, "component" );
  +
  +        componentManager.register( ManagementRegistration.EMBEDDOR.getName(),
  +                                   this,
  +                                   ManagementRegistration.EMBEDDOR.getInterfaces() );
   
           for( int i = 0; i < m_entries.length; i++ )
           {
               final ManagementRegistration registration =
                   ManagementRegistration.getManagementInfoForRole( m_entries[ i ].getRole()
);
  -            if ( null != registration )
  +            if( null != registration )
               {
  -                systemManager.register( registration.getName(),
  -                                        m_entries[ i ].getObject(), registration.getInterfaces()
);
  +                componentManager.register( registration.getName(),
  +                                           m_entries[ i ].getObject(), registration.getInterfaces()
);
               }
           }
       }
  @@ -627,15 +632,18 @@
       {
           final SystemManager systemManager =
               (SystemManager)getServiceManager().lookup( SystemManager.ROLE );
  -        systemManager.unregister( ManagementRegistration.EMBEDDOR.getName() );
  +
  +        SystemManager componentManager = systemManager.getSubContext( null, "component"
);
  +
  +        componentManager.unregister( ManagementRegistration.EMBEDDOR.getName() );
   
           for( int i = 0; i < m_entries.length; i++ )
           {
               final ManagementRegistration registration =
                   ManagementRegistration.getManagementInfoForRole( m_entries[ i ].getRole()
);
  -            if ( null != registration )
  +            if( null != registration )
               {
  -                systemManager.unregister( registration.getName() );
  +                componentManager.unregister( registration.getName() );
               }
           }
       }
  
  
  
  1.71      +8 -5      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- DefaultKernel.java	28 Jun 2002 05:11:52 -0000	1.70
  +++ DefaultKernel.java	13 Jul 2002 10:15:12 -0000	1.71
  @@ -55,6 +55,7 @@
   
       ///SystemManager provided by Embeddor
       private SystemManager m_systemManager;
  +    private SystemManager m_applicationManager;
   
       ///Configuration Repository
       private ConfigurationRepository m_repository;
  @@ -76,6 +77,8 @@
       public void initialize()
           throws Exception
       {
  +        m_applicationManager =
  +            m_systemManager.getSubContext( null, "application" );
       }
   
       public void dispose()
  @@ -158,10 +161,9 @@
               // manage application
               try
               {
  -                final String managementName = name + ",type=Application";
  -                m_systemManager.register( managementName,
  -                                          application,
  -                                          new Class[]{ApplicationMBean.class} );
  +                m_applicationManager.register( name,
  +                                               application,
  +                                               new Class[]{ApplicationMBean.class} );
               }
               catch( final Throwable t )
               {
  @@ -225,6 +227,7 @@
   
           ContainerUtil.enableLogging( context, createContextLogger( name ) );
           ContainerUtil.service( context, createServiceManager() );
  +        ContainerUtil.initialize( context );
           return context;
       }
   
  @@ -267,7 +270,7 @@
               // un-manage application
               try
               {
  -                m_systemManager.unregister( name + ",type=Application" );
  +                m_applicationManager.unregister( name );
               }
               catch( final Throwable t )
               {
  
  
  
  1.15      +69 -44    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/AbstractSystemManager.java
  
  Index: AbstractSystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/AbstractSystemManager.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AbstractSystemManager.java	20 Jun 2002 11:39:31 -0000	1.14
  +++ AbstractSystemManager.java	13 Jul 2002 10:15:12 -0000	1.15
  @@ -10,10 +10,10 @@
   import java.util.HashMap;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.phoenix.interfaces.ManagerException;
   import org.apache.avalon.phoenix.interfaces.SystemManager;
   
  @@ -30,78 +30,55 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( AbstractSystemManager.class );
   
  -    private HashMap m_entries = new HashMap();
  +    private final HashMap m_entries = new HashMap();
  +    private SubContext m_subContext;
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +        m_subContext = new SubContext( this, null, null );
  +    }
   
       /**
  -     * Register an object for management.
  -     * The object is exported through some management scheme
  -     * (typically JMX) and the management is restricted
  -     * to the interfaces passed in as a parameter to method.
  -     *
  -     * @param name the name to register object under
  -     * @param object the object
  -     * @param interfaces the interfaces to register the component under
  -     * @throws ManagerException if an error occurs. An error could occur if the object
doesn't
  -     *            implement the interfaces, the interfaces parameter contain non-instance
  -     *            classes, the name is already registered etc.
  -     * @throws IllegalArgumentException if object or interfaces is null
  +     * @see SystemManager#register(String, Object, Class[])
        */
       public synchronized void register( final String name,
                                          final Object object,
                                          final Class[] interfaces )
           throws ManagerException, IllegalArgumentException
       {
  -        checkRegister( name, object );
           if( null == interfaces )
           {
  -            final String message = REZ.getString( "manager.error.interfaces.null", name
);
  +            final String message =
  +                REZ.getString( "manager.error.interfaces.null", name );
               throw new IllegalArgumentException( message );
           }
  -
           verifyInterfaces( object, interfaces );
   
  -        final ManagedEntry entry =
  -            new ManagedEntry( object, interfaces );
  -        entry.setExportedObject( export( name, entry.getObject(), interfaces ) );
  -
  -        m_entries.put( name, entry );
  +        doRegister( name, object, interfaces );
       }
   
       /**
  -     * Register an object for management.
  -     * The object is exported through some management scheme
  -     * (typically JMX).
  -     *
  -     * @param name the name to register object under
  -     * @param object the object
  -     * @throws ManagerException if an error occurs such as name already registered.
  -     * @throws IllegalArgumentException if object is null
  +     * @see SystemManager#register(String, Object)
        */
  -    public synchronized void register( final String name, final Object object )
  +    public synchronized void register( final String name,
  +                                       final Object object )
           throws ManagerException, IllegalArgumentException
       {
  -        checkRegister( name, object );
  -
  -        final ManagedEntry entry =
  -            new ManagedEntry( object, null );
  -        entry.setExportedObject( export( name, entry.getObject(), null ) );
  -        m_entries.put( name, entry );
  +        doRegister( name, object, null );
       }
   
       /**
  -     * Unregister named object.
  -     *
  -     * @param name the name of object to unregister
  -     * @throws ManagerException if an error occurs such as when no such object registered.
  +     * @see SystemManager#unregister(String)
        */
       public synchronized void unregister( final String name )
           throws ManagerException
       {
           final ManagedEntry entry = (ManagedEntry)m_entries.remove( name );
  -
           if( null == entry )
           {
  -            final String message = REZ.getString( "manager.error.unregister.noentry", name
);
  +            final String message =
  +                REZ.getString( "manager.error.unregister.noentry", name );
               throw new ManagerException( message );
           }
   
  @@ -109,6 +86,19 @@
       }
   
       /**
  +     * Returns the subcontext of the specified name.  If it does not exist it
  +     * is created.
  +     *
  +     * @throws ManagerException if context cannot be created or retrieved
  +     * @return  the subcontext with the specified name
  +     */
  +    public SystemManager getSubContext( String parent, String type )
  +        throws ManagerException
  +    {
  +        return m_subContext.getSubContext( parent,type );
  +    }
  +
  +    /**
        * Export the object to the particular management medium using
        * the supplied object and interfaces.
        * This needs to be implemented by subclasses.
  @@ -133,6 +123,18 @@
           throws ManagerException;
   
       /**
  +     * Verfify that name is well formed.
  +     *
  +     * @param name the name
  +     * @param object the object so named
  +     */
  +    protected void verifyName( final String name,
  +                               final Object object )
  +        throws ManagerException
  +    {
  +    }
  +
  +    /**
        * Verify that an interface conforms to the requirements of management medium.
        *
        * @param clazz the interface class
  @@ -196,10 +198,33 @@
               throw new NullPointerException( "name" );
           }
   
  +        verifyName( name, object );
  +
           if( null != m_entries.get( name ) )
           {
               final String message = REZ.getString( "manager.error.register.exists", name
);
               throw new ManagerException( message );
           }
  +    }
  +
  +    /**
  +     * Utility method that actually does the registration.
  +     *
  +     * @param name the name to register under
  +     * @param object the object
  +     * @param interfaces the interfaces (may be null)
  +     * @throws ManagerException if error occurs
  +     */
  +    private void doRegister( final String name,
  +                             final Object object,
  +                             final Class[] interfaces )
  +        throws ManagerException
  +    {
  +        checkRegister( name, object );
  +
  +        final Object exportedObject = export( name, object, interfaces );
  +        final ManagedEntry entry =
  +            new ManagedEntry( object, interfaces, exportedObject );
  +        m_entries.put( name, entry );
       }
   }
  
  
  
  1.27      +25 -127   jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/DefaultManager.java
  
  Index: DefaultManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/DefaultManager.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DefaultManager.java	23 Jun 2002 18:45:02 -0000	1.26
  +++ DefaultManager.java	13 Jul 2002 10:15:12 -0000	1.27
  @@ -16,22 +16,16 @@
   import java.rmi.server.UnicastRemoteObject;
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  -import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.avalon.phoenix.components.kernel.DefaultKernel;
  -import org.apache.avalon.phoenix.components.kernel.DefaultKernelMBean;
   import org.apache.avalon.phoenix.components.manager.rmiadaptor.RMIAdaptorImpl;
  -import org.apache.avalon.phoenix.interfaces.ManagerException;
  -import org.apache.excalibur.baxter.JavaBeanMBean;
   
   /**
    * This component is responsible for managing phoenix instance.
  @@ -41,7 +35,7 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public class DefaultManager
  -    extends AbstractSystemManager
  +    extends AbstractJMXManager
       implements Parameterizable, Configurable
   {
       private static final Resources REZ =
  @@ -57,15 +51,12 @@
           System.getProperty( "phoenix.admin.passwd" );
   
       private Parameters m_parameters;
  -    private MBeanServer m_mBeanServer;
       private RMIAdaptorImpl m_rmiAdaptor;
       private Registry m_rmiRegistry;
   
       ///Name Adaptor registered with
       private String m_name;
   
  -    private String m_domain = "Phoenix";
  -
       private Configuration m_configuration;
   
       public void parameterize( final Parameters parameters )
  @@ -83,26 +74,35 @@
       public void initialize()
           throws Exception
       {
  -        m_mBeanServer = createMBeanServer();
  -        m_rmiAdaptor = new RMIAdaptorImpl( m_mBeanServer );
  +        super.initialize();
  +        final MBeanServer mBeanServer = getMBeanServer();
  +        m_rmiAdaptor = new RMIAdaptorImpl( mBeanServer );
   
           try
           {
  -            final String htmlParserClass = m_configuration.getChild( "manager-html-parser"
).getValue( null );
  +            final String htmlParserClass =
  +                m_configuration.getChild( "manager-html-parser" ).
  +                getValue( null );
               ObjectName parserName = null;
               if( null != htmlParserClass )
               {
                   parserName = new ObjectName( "Adaptor:name=htmlParser" );
                   System.out.println( "Created HTML Parser " + parserName );
  -                m_mBeanServer.createMBean( htmlParserClass, parserName );
  +                mBeanServer.createMBean( htmlParserClass, parserName );
               }
   
  -            final int port = m_configuration.getChild( "manager-adaptor-port" ).getValueAsInteger(
DEFAULT_HTTPADAPTER_PORT );
  +            final int port =
  +                m_configuration.getChild( "manager-adaptor-port" ).
  +                getValueAsInteger( DEFAULT_HTTPADAPTER_PORT );
               final HtmlAdaptorServer html =
                   new HtmlAdaptorServer( port );
   
  -            final String adminname = m_configuration.getChild( "manager-admin-name" ).getValue(
DEFAULT_ADMIN_USER );
  -            final String adminpasswd = m_configuration.getChild( "manager-admin-password"
).getValue( DEFAULT_ADMIN_PASSWD );
  +            final String adminname =
  +                m_configuration.getChild( "manager-admin-name" ).
  +                getValue( DEFAULT_ADMIN_USER );
  +            final String adminpasswd =
  +                m_configuration.getChild( "manager-admin-password" ).
  +                getValue( DEFAULT_ADMIN_PASSWD );
               if( null != adminpasswd )
               {
                   final AuthInfo auth = new AuthInfo( adminname, adminpasswd );
  @@ -113,7 +113,7 @@
                   "Adaptor:name=html,port=" + port;
               final ObjectName name = new ObjectName( stringName );
               System.out.println( "Created HTML Adaptor " + name );
  -            m_mBeanServer.registerMBean( html, name );
  +            mBeanServer.registerMBean( html, name );
               if( null != htmlParserClass )
               {
                   html.setParser( parserName );
  @@ -132,7 +132,8 @@
           throws Exception
       {
           final int portp =
  -            m_parameters.getParameterAsInteger( "manager-registry-port", DEFAULT_REGISTRY_PORT
);
  +            m_parameters.getParameterAsInteger( "manager-registry-port",
  +                                                DEFAULT_REGISTRY_PORT );
           final int port =
               m_configuration.getChild( "manager-registry-port" ).getValueAsInteger( portp
);
           m_name = m_parameters.getParameter( "manager-name", "Phoenix.JMXAdaptor" );
  @@ -144,7 +145,8 @@
           final Remote exported = UnicastRemoteObject.exportObject( m_rmiAdaptor );
           final Remote stub = RemoteObject.toStub( exported );
   
  -        //TODO: should this do a lookup and refuse to lauch if existing server registered???
  +        //TODO: should this do a lookup and refuse to lauch
  +        //if existing server registered???
           m_rmiRegistry.bind( m_name, stub );
       }
   
  @@ -158,120 +160,16 @@
   
       public void dispose()
       {
  +        super.dispose();
           //TODO: Unregister everything here or in embeddor???
           m_rmiAdaptor = null;
  -        m_mBeanServer = null;
  -    }
  -
  -    /**
  -     * Export the object to the particular management medium using
  -     * the supplied object and interfaces.
  -     * This needs to be implemented by subclasses.
  -     *
  -     * @param name the name of object
  -     * @param object the object
  -     * @param interfaces the interfaces
  -     * @return the exported object
  -     * @throws ManagerException if an error occurs
  -     */
  -    protected Object export( final String name,
  -                             final Object object,
  -                             final Class[] interfaces )
  -        throws ManagerException
  -    {
  -        try
  -        {
  -            Object mBean = null;
  -            if( null != interfaces )
  -            {
  -                mBean = new JavaBeanMBean( object, interfaces );
  -            }
  -            else
  -            {
  -                mBean = createMBean( object );
  -            }
  -
  -            final ObjectName objectName = createObjectName( name );
  -            m_mBeanServer.registerMBean( mBean, objectName );
  -            return mBean;
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "jmxmanager.error.export.fail", name
);
  -            getLogger().error( message, e );
  -            throw new ManagerException( message, e );
  -        }
  -    }
  -
  -    private ObjectName createObjectName( final String name ) throws MalformedObjectNameException
  -    {
  -        return new ObjectName( m_domain + ":name=" + name );
  -    }
  -
  -    /**
  -     * Create a MBean for specified object.
  -     * The following policy is used top create the MBean...
  -     *
  -     * @param object the object to create MBean for
  -     * @return the MBean to be exported
  -     * @throws ManagerException if an error occurs
  -     */
  -    private Object createMBean( final Object object )
  -        throws ManagerException
  -    {
  -        //HACK: ugly Testing hack!!
  -        if( object instanceof DefaultKernel )
  -        {
  -            return new DefaultKernelMBean( (DefaultKernel)object );
  -        }
  -        else
  -        {
  -            return new JavaBeanMBean( object );
  -        }
  -    }
  -
  -    /**
  -     * Stop the exported object from being managed.
  -     *
  -     * @param name the name of object
  -     * @param exportedObject the object return by export
  -     * @throws ManagerException if an error occurs
  -     */
  -    protected void unexport( final String name,
  -                             final Object exportedObject )
  -        throws ManagerException
  -    {
  -        try
  -        {
  -            m_mBeanServer.unregisterMBean( createObjectName( name ) );
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "jmxmanager.error.unexport.fail", name
);
  -            getLogger().error( message, e );
  -            throw new ManagerException( message, e );
  -        }
  -    }
  -
  -    /**
  -     * Verify that an interface conforms to the requirements of management medium.
  -     *
  -     * @param clazz the interface class
  -     * @throws ManagerException if verification fails
  -     */
  -    protected void verifyInterface( final Class clazz )
  -        throws ManagerException
  -    {
  -        //TODO: check it extends all right things and that it
  -        //has all the right return types etc. Blocks must have
  -        //interfaces extending Service (or Manageable)
       }
   
       /**
        * Creates a new Manager. The mBeanServer it uses is determined from
        * the Parameters's manager-mBeanServer-class variable.
        */
  -    private MBeanServer createMBeanServer()
  +    protected MBeanServer createMBeanServer()
           throws Exception
       {
           try
  
  
  
  1.9       +13 -139   jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java
  
  Index: MX4JSystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/MX4JSystemManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MX4JSystemManager.java	20 Jun 2002 14:13:29 -0000	1.8
  +++ MX4JSystemManager.java	13 Jul 2002 10:15:13 -0000	1.9
  @@ -10,41 +10,28 @@
   import javax.management.Attribute;
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  -import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
  -import org.apache.avalon.excalibur.i18n.ResourceManager;
  -import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.phoenix.components.kernel.DefaultKernel;
  -import org.apache.avalon.phoenix.components.kernel.DefaultKernelMBean;
  -import org.apache.avalon.phoenix.interfaces.ManagerException;
  -import org.apache.excalibur.baxter.JavaBeanMBean;
   
   /**
    * This component is responsible for managing phoenix instance.
  - * This includes managing embeddor, deployer and kernel.
    *
    * @author <a href="mail@leosimons.com">Leo Simons</a>
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:Huw@mmlive.com">Huw Roberts</a>
    */
   public class MX4JSystemManager
  -    extends AbstractSystemManager
  +    extends AbstractJMXManager
   {
  -    private static final Resources REZ =
  -        ResourceManager.getPackageResources( MX4JSystemManager.class );
  -
  -    //private Parameters m_parameters;
  -    private MBeanServer m_mBeanServer;
  -
  -    private String m_domain = "Phoenix";
  -
       public void initialize()
           throws Exception
       {
  -        m_mBeanServer = MBeanServerFactory.createMBeanServer( "Phoenix" );
  +        super.initialize();
  +
  +        final MBeanServer mBeanServer = getMBeanServer();
   
           final ObjectName adaptorName = new ObjectName( "Http:name=HttpAdaptor" );
  -        m_mBeanServer.createMBean( "mx4j.adaptor.http.HttpAdaptor", adaptorName, null );
  -        m_mBeanServer.setAttribute( adaptorName, new Attribute( "Port", new Integer( 8083
) ) );
  +        mBeanServer.createMBean( "mx4j.adaptor.http.HttpAdaptor", adaptorName, null );
  +        mBeanServer.setAttribute( adaptorName, new Attribute( "Port", new Integer( 8083
) ) );
   
           /**
            // add user names
  @@ -58,7 +45,7 @@
            */
   
           ObjectName processorName = new ObjectName( "Http:name=XSLTProcessor" );
  -        m_mBeanServer.createMBean( "mx4j.adaptor.http.XSLTProcessor", processorName, null
);
  +        mBeanServer.createMBean( "mx4j.adaptor.http.XSLTProcessor", processorName, null
);
           /*
                   if( path != null )
                   {
  @@ -67,7 +54,7 @@
           */
           final Attribute useCache =
               new Attribute( "UseCache", new Boolean( false ) );
  -        m_mBeanServer.setAttribute( processorName, useCache );
  +        mBeanServer.setAttribute( processorName, useCache );
           /*
                   if( pathInJar != null )
                   {
  @@ -76,128 +63,15 @@
                   }
           */
   
  -        m_mBeanServer.setAttribute( adaptorName, new Attribute( "ProcessorName", processorName
) );
  +        mBeanServer.setAttribute( adaptorName, new Attribute( "ProcessorName", processorName
) );
   
           // starts the server
  -        m_mBeanServer.invoke( adaptorName, "start", null, null );
  +        mBeanServer.invoke( adaptorName, "start", null, null );
       }
   
  -    public void start()
  +    protected MBeanServer createMBeanServer()
           throws Exception
       {
  -    }
  -
  -    public void stop()
  -        throws Exception
  -    {
  -    }
  -
  -    public void dispose()
  -    {
  -        m_mBeanServer = null;
  -    }
  -
  -    /**
  -     * Export the object to the particular management medium using
  -     * the supplied object and interfaces.
  -     * This needs to be implemented by subclasses.
  -     *
  -     * @param name the name of object
  -     * @param object the object
  -     * @param interfaces the interfaces
  -     * @return the exported object
  -     * @throws ManagerException if an error occurs
  -     */
  -    protected Object export( final String name,
  -                             final Object object,
  -                             final Class[] interfaces )
  -        throws ManagerException
  -    {
  -        try
  -        {
  -            Object mBean = null;
  -            if( null != interfaces )
  -            {
  -                mBean = new JavaBeanMBean( object, interfaces );
  -            }
  -            else
  -            {
  -                mBean = createMBean( object );
  -            }
  -
  -            final ObjectName objectName = createObjectName( name );
  -            m_mBeanServer.registerMBean( mBean, objectName );
  -            return mBean;
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "jmxmanager.error.export.fail", name
);
  -            getLogger().error( message, e );
  -            throw new ManagerException( message, e );
  -        }
  -    }
  -
  -    private ObjectName createObjectName( final String name ) throws MalformedObjectNameException
  -    {
  -        return new ObjectName( m_domain + ":name=" + name );
  -    }
  -
  -    /**
  -     * Create a MBean for specified object.
  -     * The following policy is used top create the MBean...
  -     *
  -     * @param object the object to create MBean for
  -     * @return the MBean to be exported
  -     * @throws ManagerException if an error occurs
  -     */
  -    private Object createMBean( final Object object )
  -        throws ManagerException
  -    {
  -        //HACK: ugly Testing hack!!
  -        if( object instanceof DefaultKernel )
  -        {
  -            return new DefaultKernelMBean( (DefaultKernel)object );
  -        }
  -        else
  -        {
  -            return new JavaBeanMBean( object );
  -        }
  -    }
  -
  -    /**
  -     * Stop the exported object from being managed.
  -     *
  -     * @param name the name of object
  -     * @param exportedObject the object return by export
  -     * @throws ManagerException if an error occurs
  -     */
  -    protected void unexport( final String name,
  -                             final Object exportedObject )
  -        throws ManagerException
  -    {
  -        try
  -        {
  -            m_mBeanServer.unregisterMBean( createObjectName( name ) );
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "jmxmanager.error.unexport.fail", name
);
  -            getLogger().error( message, e );
  -            throw new ManagerException( message, e );
  -        }
  -    }
  -
  -    /**
  -     * Verify that an interface conforms to the requirements of management medium.
  -     *
  -     * @param clazz the interface class
  -     * @throws ManagerException if verification fails
  -     */
  -    protected void verifyInterface( final Class clazz )
  -        throws ManagerException
  -    {
  -        //TODO: check it extends all right things and that it
  -        //has all the right return types etc. Blocks must have
  -        //interfaces extending Service (or Manageable)
  +        return MBeanServerFactory.createMBeanServer( "Phoenix" );
       }
   }
  
  
  
  1.2       +3 -6      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/ManagedEntry.java
  
  Index: ManagedEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/ManagedEntry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ManagedEntry.java	20 May 2002 11:53:49 -0000	1.1
  +++ ManagedEntry.java	13 Jul 2002 10:15:13 -0000	1.2
  @@ -19,10 +19,12 @@
       private Object m_exportedObject;
   
       ManagedEntry( final Object object,
  -                  final Class[] interfaces )
  +                  final Class[] interfaces,
  +                  final Object exportedObject )
       {
           m_object = object;
           m_interfaces = interfaces;
  +        m_exportedObject = exportedObject;
       }
   
       Object getObject()
  @@ -38,10 +40,5 @@
       Object getExportedObject()
       {
           return m_exportedObject;
  -    }
  -
  -    void setExportedObject( final Object exportedObject )
  -    {
  -        m_exportedObject = exportedObject;
       }
   }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/AbstractJMXManager.java
  
  Index: AbstractJMXManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.manager;
  
  import javax.management.MBeanServer;
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.phoenix.components.kernel.DefaultKernel;
  import org.apache.avalon.phoenix.components.kernel.DefaultKernelMBean;
  import org.apache.avalon.phoenix.interfaces.ManagerException;
  import org.apache.excalibur.baxter.JavaBeanMBean;
  
  /**
   * An abstract class via which JMX Managers can extend.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:Huw@mmlive.com">Huw Roberts</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/13 10:15:12 $
   */
  public abstract class AbstractJMXManager
      extends AbstractSystemManager
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( AbstractJMXManager.class );
  
      private MBeanServer m_mBeanServer;
      private String m_domain = "Phoenix";
  
      public void initialize()
          throws Exception
      {
          super.initialize();
  
          final MBeanServer mBeanServer = createMBeanServer();
          setMBeanServer( mBeanServer );
      }
  
      public void start()
          throws Exception
      {
      }
  
      public void stop()
          throws Exception
      {
      }
  
      public void dispose()
      {
          setMBeanServer( null );
      }
  
      /**
       * Export the object to the particular management medium using
       * the supplied object and interfaces.
       * This needs to be implemented by subclasses.
       *
       * @param name the name of object
       * @param object the object
       * @param interfaces the interfaces
       * @return the exported object
       * @throws ManagerException if an error occurs
       */
      protected Object export( final String name,
                               final Object object,
                               final Class[] interfaces )
          throws ManagerException
      {
          try
          {
              final Object mBean = createMBean( object, interfaces );
              final ObjectName objectName = createObjectName( name );
              getMBeanServer().registerMBean( mBean, objectName );
              return mBean;
          }
          catch( final Exception e )
          {
              final String message = REZ.getString( "jmxmanager.error.export.fail", name );
              getLogger().error( message, e );
              throw new ManagerException( message, e );
          }
      }
  
      /**
       * Create MBean for specified object (and interfaces if any).
       *
       * @param object the object
       * @param interfaces the interfaces to export
       * @return the MBean
       * @throws ManagerException if unable to create MBean
       */
      private Object createMBean( final Object object,
                                  final Class[] interfaces )
          throws ManagerException
      {
          if( null != interfaces )
          {
              return new JavaBeanMBean( object, interfaces );
          }
          else
          {
              return createMBean( object );
          }
      }
  
      /**
       * Create JMX name for object.
       *
       * @param name the name of object
       * @return the {@link ObjectName} representing object
       * @throws MalformedObjectNameException if malformed name
       */
      private ObjectName createObjectName( final String name )
          throws MalformedObjectNameException
      {
          return new ObjectName( getDomain() + ":" + name );
      }
  
      /**
       * Create a MBean for specified object.
       * The following policy is used top create the MBean...
       *
       * @param object the object to create MBean for
       * @return the MBean to be exported
       * @throws ManagerException if an error occurs
       */
      private Object createMBean( final Object object )
          throws ManagerException
      {
          //HACK: ugly Testing hack!!
          if( object instanceof DefaultKernel )
          {
              return new DefaultKernelMBean( (DefaultKernel)object );
          }
          else
          {
              return new JavaBeanMBean( object );
          }
      }
  
      /**
       * Stop the exported object from being managed.
       *
       * @param name the name of object
       * @param exportedObject the object return by export
       * @throws ManagerException if an error occurs
       */
      protected void unexport( final String name,
                               final Object exportedObject )
          throws ManagerException
      {
          try
          {
              getMBeanServer().unregisterMBean( createObjectName( name ) );
          }
          catch( final Exception e )
          {
              final String message =
                  REZ.getString( "jmxmanager.error.unexport.fail", name );
              getLogger().error( message, e );
              throw new ManagerException( message, e );
          }
      }
  
      /**
       * Verify that an interface conforms to the requirements of management medium.
       *
       * @param clazz the interface class
       * @throws ManagerException if verification fails
       */
      protected void verifyInterface( final Class clazz )
          throws ManagerException
      {
          //TODO: check it extends all right things and that it
          //has all the right return types etc. Blocks must have
          //interfaces extending Service (or Manageable)
      }
  
      protected MBeanServer getMBeanServer()
      {
          return m_mBeanServer;
      }
  
      protected void setMBeanServer( MBeanServer mBeanServer )
      {
          m_mBeanServer = mBeanServer;
      }
  
      protected String getDomain()
      {
          return m_domain;
      }
  
      protected void setDomain( final String domain )
      {
          m_domain = domain;
      }
  
      /**
       * Creates a new MBeanServer.
       * The subclass should implement this to create specific MBeanServer.
       */
      protected abstract MBeanServer createMBeanServer()
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/SubContext.java
  
  Index: SubContext.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.manager;
  
  import java.util.HashMap;
  import org.apache.avalon.phoenix.interfaces.ManagerException;
  import org.apache.avalon.phoenix.interfaces.SystemManager;
  
  /**
   * Implements a management context local to a particular process with which
   * it can register its managed object.  The naming scheme that results is
   * meant to be compatible with jmx.
   *
   * @author <a href="mailto:Huw@mmlive.com">Huw Roberts</a>
   */
  class SubContext
      implements SystemManager
  {
      private static final String EMPTY_STRING = "";
  
      private final HashMap m_subcontexts = new HashMap();
      private final SystemManager m_parent;
      private final String m_name;
      private final String m_type;
  
      /**
       * Creates new SubContext to the specified context.  Objects registered
       * under the subcontext will be typed with the name of the context so the
       * jmx name becomes 'contextName' + 'objectNameSoFar'
       *
       * @param parent the parent context
       * @param name the subcontext name
       */
      public SubContext( final SystemManager parent,
                         final String name,
                         final String type )
      {
          if( null == parent )
          {
              throw new NullPointerException( "parent" );
          }
          m_parent = parent;
          m_name = name;
          m_type = type;
      }
  
      /**
       * Register an object for management.
       * The object is exported through some management scheme
       * (typically JMX) and the management is restricted
       * to the interfaces passed in as a parameter to method.
       *
       * @param name the name to register object under
       * @param object the object
       * @param interfaces the interfaces to register the component under
       * @throws ManagerException if an error occurs. An error could occur if the object doesn't
       *            implement the interfaces, the interfaces parameter contain non-instance
       *            classes, the name is already registered etc.
       * @throws IllegalArgumentException if object or interfaces is null
       */
      public void register( String name, Object object, Class[] interfaces )
          throws ManagerException, IllegalArgumentException
      {
          m_parent.register( jmxName( name ), object, interfaces );
      }
  
      /**
       * Register an object for management.
       * The object is exported through some management scheme
       * (typically JMX). Note that the particular management scheme
       * will most likely use reflection to extract manageable information.
       *
       * @param name the name to register object under
       * @param object the object
       * @throws ManagerException if an error occurs such as name already registered.
       * @throws IllegalArgumentException if object is null
       */
      public void register( String name, Object object )
          throws ManagerException, IllegalArgumentException
      {
          m_parent.register( jmxName( name ), object );
      }
  
      /**
       * Unregister named object.
       *
       * @param name the name of object to unregister
       * @throws ManagerException if an error occurs such as when no such object registered.
       */
      public void unregister( String name )
          throws ManagerException
      {
          m_parent.unregister( jmxName( name ) );
      }
  
      /**
       * Returns the subcontext of the specified name.  If it does not exist it
       * is created.
       *
       * @return the subcontext with the specified name
       * @throws ManagerException if context cannot be created or retrieved
       */
      public SystemManager getSubContext( final String name,
                                          final String type )
          throws ManagerException
      {
          if( null == type || EMPTY_STRING.equals( type ) )
          {
              final String message = "type cannot be null or empty";
              throw new ManagerException( message );
          }
  
          // get from list if possible
          final String key = contextKey( name, type );
          SystemManager subcontext =
              (SystemManager)m_subcontexts.get( key );
  
          // otherwise create and add to list
          if( subcontext == null )
          {
              subcontext = new SubContext( this, name, type );
              m_subcontexts.put( key, subcontext );
          }
  
          return subcontext;
      }
  
      /**
       *  Helper method used to generate the jmx name by appending the current name
       *  and passing up the chain to the root context
       */
      private String jmxName( final String name )
      {
          final StringBuffer sb = new StringBuffer();
          if( null != m_name )
          {
              sb.append( m_name );
              sb.append( ',' );
          }
          if( null != m_type )
          {
              sb.append( m_type );
              sb.append( '=' );
          }
          sb.append( name );
  
          return sb.toString();
      }
  
      /**
       *  Helper method to get key used to store subcontexts
       * in m_subcontexts
       */
      private String contextKey( final String parent,
                                 final String type )
      {
          return parent + "|" + type;
      }
  }
  
  
  
  1.8       +12 -1     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/SystemManager.java
  
  Index: SystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/SystemManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SystemManager.java	10 May 2002 11:08:57 -0000	1.7
  +++ SystemManager.java	13 Jul 2002 10:15:13 -0000	1.8
  @@ -57,4 +57,15 @@
        */
       void unregister( String name )
           throws ManagerException;
  -}
  +
  +    /**
  +     * Returns the subcontext of the specified name.  If it does not exist it
  +     * is created.
  +     *
  +     * @param name name of the object in the parent context that will own this one
  +     * @throws ManagerException if context cannot be created or retrieved
  +     * @return  the subcontext with the specified name
  +     */
  +    SystemManager getSubContext( String name, String type )
  +        throws ManagerException;
  +}
  \ No newline at end of file
  
  
  

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


Mime
View raw message