colus 2002/09/06 06:18:19
Modified: . build.xml
src/java/org/apache/avalon/phoenix/components/manager
Resources.properties
Added: lib excalibur-converter-1.0.jar
src/conf emx4j-kernel.xml
src/java/org/apache/avalon/phoenix/components/manager
ExtendedMX4JSystemManager.java
Log:
More extensible MX4JSystemManager. Need more testing and refactoring.
Revision Changes Path
1.163 +1 -0 jakarta-avalon-phoenix/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/build.xml,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -r1.162 -r1.163
--- build.xml 6 Sep 2002 12:15:45 -0000 1.162
+++ build.xml 6 Sep 2002 13:18:18 -0000 1.163
@@ -380,6 +380,7 @@
<copy todir="${bin.dist.conf}" filtering="on">
<fileset dir="${conf.dir}">
<include name="kernel.xml"/>
+ <include name="emx4j-kernel.xml"/>
</fileset>
</copy>
1.1 jakarta-avalon-phoenix/lib/excalibur-converter-1.0.jar
<<Binary file>>
1.1 jakarta-avalon-phoenix/src/conf/emx4j-kernel.xml
Index: emx4j-kernel.xml
===================================================================
<?xml version="1.0"?>
<phoenix>
<embeddor role="org.apache.avalon.phoenix.interfaces.Embeddor"
class="org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor">
<component role="org.apache.avalon.phoenix.interfaces.Deployer"
class="org.apache.avalon.phoenix.components.deployer.DefaultDeployer"
logger="deployer"/>
<component role="org.apache.avalon.phoenix.interfaces.LogManager"
class="org.apache.avalon.phoenix.components.logger.DefaultLogManager"
logger="logs"/>
<!-- There is one JMX MBeanServer infrastructure currently
supported by Avalon, namely MX4J. Previously the JMX RI
was supported but due to severe bugs and lack of implementation
of certain features (such as ModelMBeans), support has been
dropped for the JMX RI implementation.
The MX4J manager using the MX4J adapter devewloped at SourceForge
See http://mx4j.sourceforge.net/ -
org.apache.avalon.phoenix.components.manager.MX4JSystemManager
There is an impl of system manager that does nothing and it is....
org.apache.avalon.phoenix.components.manager.NoopSystemManager
Alternatively, you could comment the whole SystemManager section out.
-->
<component role="org.apache.avalon.phoenix.interfaces.SystemManager"
class="org.apache.avalon.phoenix.components.manager.ExtendedMX4JSystemManager"
logger="manager" >
<!--rmi-naming-factory>com.sun.jndi.rmi.registry.RegistryContextFactory</rmi-naming-factory-->
<mbean name="Http:name=XSLTProcessor"
class="mx4j.adaptor.http.XSLTProcessor">
<attribute name="File" type="java.lang.String">conf/xsl</attribute>
<attribute name="UseCache" type="java.lang.Boolean">false</attribute>
</mbean>
<mbean name="Http:name=HttpAdaptor" class="mx4j.adaptor.http.HttpAdaptor">
<use name="ProcessorName">Http:name=XSLTProcessor</use>
<attribute name="Host" type="java.lang.String">localhost</attribute>
<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>
</mbean>
<mbean name="Naming:type=rmiregistry"
class="mx4j.tools.naming.NamingService">
</mbean>
<mbean name="Adaptor:protocol=JRMP"
class="mx4j.adaptor.rmi.jrmp.JRMPAdaptor">
<attribute name="JNDIName" type="java.lang.String">jrmp</attribute>
</mbean>
</component>
<!-- There are two kernels
org.apache.avalon.phoenix.components.kernel.DefaultKernel
- The default one.
org.apache.avalon.phoenix.components.kernel.beanshell.BeanShellKernel
- One with a beanshell view at the application level.
-->
<component role="org.apache.avalon.phoenix.interfaces.Kernel"
class="@KERNEL-CLASS@"
logger="kernel"/>
<component
role="org.apache.avalon.phoenix.interfaces.ConfigurationRepository"
class="org.apache.avalon.phoenix.components.configuration.DefaultConfigurationRepository"
logger="config"/>
<!--
<component
role="org.apache.avalon.phoenix.interfaces.ConfigurationRepository"
class="org.apache.avalon.phoenix.components.configuration.FileSystemPersistentConfigurationRepository"
logger="config"/>
-->
<component role="org.apache.avalon.phoenix.interfaces.ConfigurationValidator"
class="org.apache.avalon.phoenix.components.configuration.validator.NoopConfigurationValidator"
logger="validator"/>
<!--
<component role="org.apache.avalon.phoenix.interfaces.ConfigurationValidator"
class="org.apache.avalon.phoenix.components.configuration.validator.DelegatingConfigurationValidator"
logger="validator">
<delegate schema-type="relax-ng"
class="org.apache.avalon.phoenix.components.configuration.validator.JarvConfigurationValidator">
<schema-language>http://relaxng.org/ns/structure/1.0</schema-language>
</delegate>
</component>
-->
<component role="org.apache.avalon.phoenix.interfaces.ClassLoaderManager"
class="org.apache.avalon.phoenix.components.classloader.DefaultClassLoaderManager"
logger="classes"/>
<component role="org.apache.avalon.excalibur.packagemanager.ExtensionManager"
class="org.apache.avalon.phoenix.components.extensions.DefaultExtensionManager"
logger="packages"/>
<!--
<component role="org.apache.avalon.excalibur.packagemanager.ExtensionManager"
class="org.apache.avalon.excalibur.packagemanager.impl.NoopPackageRepository"
logger="packages"/>
-->
</embeddor>
</phoenix>
1.6 +2 -0
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/Resources.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Resources.properties 30 Jul 2002 12:31:16 -0000 1.5
+++ Resources.properties 6 Sep 2002 13:18:19 -0000 1.6
@@ -24,3 +24,5 @@
jmxmanager.error.mbean.load.class=Failed to find MBean of class {0} in classpath.
mxinfo.error.file=Failed to read mxinfo file {0}.
jmxmanager.error.mbeanserver.create=Failed to create MBean Server of class {0}.
+jmxmanager.error.jmxmbean.initialize=Failted to initialize {0}.
+jmxmanager.error.jmxmbean.dispose=Error disposing {0}.
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/manager/ExtendedMX4JSystemManager.java
Index: ExtendedMX4JSystemManager.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.io.File;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
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.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.excalibur.converter.Converter;
import org.apache.excalibur.converter.lib.SimpleMasterConverter;
/**
* This component is responsible for managing phoenix instance.
*
* @author <a href="[EMAIL PROTECTED]">Leo Simons</a>
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Huw Roberts</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Eung-ju Park</a>
*/
public class ExtendedMX4JSystemManager
extends AbstractJMXManager
implements Contextualizable, Configurable
{
private static final Resources REZ =
ResourceManager.getPackageResources( ExtendedMX4JSystemManager.class );
private static final String DEFAULT_NAMING_FACTORY =
"com.sun.jndi.rmi.registry.RegistryContextFactory";
private File m_homeDir;
private Configuration m_configuration;
private Map m_jmxMBeans;
public void contextualize( Context context )
throws ContextException
{
m_homeDir = (File)context.get( "phoenix.home" );
}
public void configure( final Configuration configuration )
throws ConfigurationException
{
final String namingFactory =
configuration.getChild( "rmi-naming-factory" ).getValue( null);
if ( null != namingFactory )
{
System.setProperty( "java.naming.factory.initial", namingFactory );
}
else if ( null == System.getProperty( "java.naming.factory.initial" ) )
{
System.setProperty( "java.naming.factory.initial",
DEFAULT_NAMING_FACTORY );
}
m_configuration = configuration;
}
public void initialize()
throws Exception
{
super.initialize();
m_jmxMBeans = new HashMap();
final Configuration[] mBeanConfs = m_configuration.getChildren( "mbean" );
for ( int i = 0; i < mBeanConfs.length; i++ )
{
initializeMBean( mBeanConfs[ i ] );
}
}
public void dispose()
{
final MBeanServer mBeanServer = getMBeanServer();
final Iterator mBeanNames = m_jmxMBeans.values().iterator();
while ( mBeanNames.hasNext() )
{
final ObjectName mBeanName = (ObjectName)mBeanNames.next();
try
{
//stop mbean.
mBeanServer.invoke( mBeanName, "stop", null, null );
}
catch ( final Exception e )
{
final String message = REZ.getString(
"jmxmanager.error.jmxmbean.dispose" );
getLogger().error( message , e );
}
}
super.dispose();
}
private void initializeMBean( final Configuration mBeanConf )
throws Exception
{
final MBeanServer mBeanServer = getMBeanServer();
final Converter valueConverter = new SimpleMasterConverter();
final ObjectName mBeanName = new ObjectName( mBeanConf.getAttribute( "name"
) );
try
{
mBeanServer.createMBean( mBeanConf.getAttribute( "class" ), mBeanName,
null );
//set attributes
final Configuration[] attributes = mBeanConf.getChildren( "attribute" );
for ( int i = 0; i < attributes.length; i++ )
{
final Configuration attribute = attributes[ i ];
final String name = attribute.getAttribute( "name" );
final String type = attribute.getAttribute( "type" );
Object value = attribute.getValue( null );
if ( null != value )
{
final Class valueClass = Class.forName( type );
value = valueConverter.convert( valueClass, value, null );
}
mBeanServer.setAttribute( mBeanName, new Attribute( name, value ) );
}
//set dependent attributes
final Configuration[] uses = mBeanConf.getChildren( "use" );
for ( int i = 0; i < uses.length; i++ )
{
final Configuration use = uses[ i ];
final String name = use.getAttribute( "name" );
final String value = use.getValue();
mBeanServer.setAttribute( mBeanName, 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( mBeanName, operationName, values, types );
}
//start mbean
mBeanServer.invoke( mBeanName, "start", null, null );
m_jmxMBeans.put( mBeanName.getCanonicalName(), mBeanName );
}
catch ( final Exception e )
{
final String message = REZ.getString(
"jmxmanager.error.jmxmbean.initialize" );
getLogger().error( message , e );
}
}
protected MBeanServer createMBeanServer()
throws Exception
{
MX4JLoggerAdapter.setLogger(getLogger());
mx4j.log.Log.redirectTo(new MX4JLoggerAdapter());
return MBeanServerFactory.createMBeanServer( "Phoenix" );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>