avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager ExtendedMX4JSystemManager.java
Date Fri, 06 Sep 2002 17:31:54 GMT
colus       2002/09/06 10:31:53

  Modified:    src/conf emx4j-kernel.xml
               src/java/org/apache/avalon/phoenix/components/manager
                        ExtendedMX4JSystemManager.java
  Log:
  Support startup/shutdown invocation.
  
  Revision  Changes    Path
  1.2       +23 -4     jakarta-avalon-phoenix/src/conf/emx4j-kernel.xml
  
  Index: emx4j-kernel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/conf/emx4j-kernel.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- emx4j-kernel.xml	6 Sep 2002 13:18:19 -0000	1.1
  +++ emx4j-kernel.xml	6 Sep 2002 17:31:53 -0000	1.2
  @@ -45,16 +45,35 @@
                 <attribute name="Port" type="java.lang.Integer">8082</attribute>
                 <attribute name="AuthenticationMethod" type="java.lang.String">basic</attribute>
   
  -              <invoke name="addAuthorization">
  -                  <parameter type="java.lang.String">jmx</parameter>
  -                  <parameter type="java.lang.String">jmx</parameter>
  -              </invoke>
  +              <startup>
  +                  <invoke name="addAuthorization">
  +                      <parameter type="java.lang.String">jmx</parameter>
  +                      <parameter type="java.lang.String">jmx</parameter>
  +                  </invoke>
  +                  <invoke name="start"/>
  +              </startup>
  +              <shutdown>
  +                  <invoke name="stop"/>
  +              </shutdown>
             </mbean>
   
             <mbean name="Naming:type=rmiregistry" class="mx4j.tools.naming.NamingService">
  +              <startup>
  +                  <invoke name="start"/>
  +              </startup>
  +              <shutdown>
  +                  <invoke name="stop"/>
  +              </shutdown>
             </mbean>
             <mbean name="Adaptor:protocol=JRMP" class="mx4j.adaptor.rmi.jrmp.JRMPAdaptor">
                 <attribute name="JNDIName" type="java.lang.String">jrmp</attribute>
  +
  +              <startup>
  +                  <invoke name="start"/>
  +              </startup>
  +              <shutdown>
  +                  <invoke name="stop"/>
  +              </shutdown>
             </mbean>
   
           </component>
  
  
  
  1.3       +49 -29    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/ExtendedMX4JSystemManager.java
  
  Index: ExtendedMX4JSystemManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/ExtendedMX4JSystemManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExtendedMX4JSystemManager.java	6 Sep 2002 16:32:50 -0000	1.2
  +++ ExtendedMX4JSystemManager.java	6 Sep 2002 17:31:53 -0000	1.3
  @@ -47,6 +47,7 @@
       private File m_homeDir;
       private Configuration m_configuration;
       private Map m_jmxMBeans;
  +    private Map m_jmxMBeanConfs;
   
       public void contextualize( Context context )
           throws ContextException
  @@ -78,6 +79,7 @@
           super.initialize();
   
           m_jmxMBeans = new HashMap();
  +        m_jmxMBeanConfs = new HashMap();
           final Configuration[] mBeanConfs = m_configuration.getChildren( "mbean" );
           for ( int i = 0; i < mBeanConfs.length; i++ )
           {
  @@ -136,37 +138,16 @@
                   mBeanServer.setAttribute( objectName, new Attribute( name, new ObjectName(
value ) ) );
               }
   
  -            //invoke operations
  -            final Configuration[] invokes = mBeanConf.getChildren( "invoke" );
  -            for ( int i = 0; i < invokes.length; i++ )
  -            {
  -                final Configuration invoke = invokes[ i ];
  -                final Configuration[] paramConfs = invoke.getChildren( "parameter" );
  -
  -                final String operationName = invoke.getAttribute( "name" );
  -                final String[] types = new String[ paramConfs.length ];
  -                final Object[] values = new Object[ paramConfs.length ];
  -                for ( int j = 0; j < paramConfs.length; j++ )
  -                {
  -                    types[ j ] = paramConfs[ j ].getAttribute( "type" );
  -                    values[ j ] = paramConfs[ j ].getValue( null );
  -                    if ( null != values[ j ] )
  -                    {
  -                        final Class valueClass = Class.forName( types[ j ] );
  -                        values[ j ] = valueConverter.convert( valueClass, values[ j ],
null );
  -                    }
  -                }
  -                mBeanServer.invoke( objectName, operationName, values, types );
  -            }
  -
  -            //start mbean
  -            mBeanServer.invoke( objectName, "start", null, null );
  +            //invoke startup operations
  +            final Configuration[] invokes = mBeanConf.getChild( "startup", true ).getChildren(
"invoke" );
  +            invokeOperations( mBeanServer, objectName, invokes );
   
               m_jmxMBeans.put( objectName.getCanonicalName(), objectName );
  +            m_jmxMBeanConfs.put( objectName.getCanonicalName(), mBeanConf );
           }
           catch ( final Exception e )
           {
  -            final String message = REZ.getString( "jmxmanager.error.jmxmbean.initialize"
);
  +            final String message = REZ.getString( "jmxmanager.error.jmxmbean.initialize",
objectName );
               getLogger().error( message , e );
           }
       }
  @@ -176,16 +157,55 @@
           final MBeanServer mBeanServer = getMBeanServer();
   
           final ObjectName objectName = (ObjectName)m_jmxMBeans.get( name );
  +        final Configuration mBeanConf = (Configuration)m_jmxMBeanConfs.get( name );
           try
           {
  -            //stop mbean.
  -            mBeanServer.invoke( objectName, "stop", null, null );
  +            final Configuration[] invokes = mBeanConf.getChild( "shutdown", true ).getChildren(
"invoke" );
  +            invokeOperations( mBeanServer, objectName, invokes );
           }
           catch ( final Exception e )
           {
  -            final String message = REZ.getString( "jmxmanager.error.jmxmbean.dispose" );
  +            final String message = REZ.getString( "jmxmanager.error.jmxmbean.dispose",
objectName );
               getLogger().error( message , e );
           }
  +    }
  +
  +    private void invokeOperations( final MBeanServer mBeanServer,
  +                                   final ObjectName objectName,
  +                                   final Configuration[] invokes )
  +        throws Exception
  +    {
  +        for ( int i = 0; i < invokes.length; i++ )
  +        {
  +            final Configuration invoke = invokes[ i ];
  +            invokeOperation( mBeanServer, objectName, invoke );
  +        }
  +    }
  +
  +    private void invokeOperation( final MBeanServer mBeanServer,
  +                                  final ObjectName objectName,
  +                                  final Configuration invoke )
  +        throws Exception
  +    {
  +        final Converter valueConverter = new SimpleMasterConverter();
  +
  +        final String operationName = invoke.getAttribute( "name" );
  +        final Configuration[] paramConfs = invoke.getChildren( "parameter" );
  +        final String[] types = new String[ paramConfs.length ];
  +        final Object[] values = new Object[ paramConfs.length ];
  +        for ( int i = 0; i < paramConfs.length; i++ )
  +        {
  +            final String type = paramConfs[ i ].getAttribute( "type" );
  +            Object value = paramConfs[ i ].getValue( null );
  +            if ( null != value )
  +            {
  +                final Class valueClass = Class.forName( type );
  +                value = valueConverter.convert( valueClass, value, null );
  +            }
  +            types[ i ] = type;
  +            values[ i ] = value;
  +        }
  +        mBeanServer.invoke( objectName, operationName, values, types );
       }
   
       protected MBeanServer createMBeanServer()
  
  
  

--
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