----- Original Message -----
From: Niclas Hedhman <[EMAIL PROTECTED]>
Date: Thursday, May 6, 2004 10:33 pm
Subject: Re: Merlin logging, dynamic procies and JMX

> On Friday 07 May 2004 06:39, Scott Brickner wrote:
> > I'm using JMX fairly extensively with Merlin 3.2.5 - I rolled my 
> own bit
> > of magic using an @avalon.extension component. The extension 
> creates an
> > mbean server, an HTTP adaptor, and a remote connector.
> 
> I am quite impressed, that people manages to roll their own through 
> the fairly 
> simple LifeCycle extension mechanism...
> 
> I think the full code per se is not 'candidate' for inclusion into 
> the JMX 
> facility.
> 
> > Basically, if you mark a class as being "manageable" (i.e., mark 
> it as
> > using the extension), then the manager will automatically 
> register the
> > mbean with the mbeanServer when the component is deployed and then
> > unregisters it when it's deployed.[sic!]
> 
> I think the 'marker' should be a method level meta-info tag, for 
> instance    @avalon.jmx.management
> And that the meta-info task creates the necessary info into the 
> .xinfo file, 
> and the JMX facility picks that up and adds the method to the 
> management 
> interface.

I agree.  There was a similar concept in the Phoenix JMX implementation (@phoenix:mx 
tags -> .mxinfo file).  I believe the current implementation of the facility will 
still support those .mxinfo files if it finds them, although I haven't tested that.

> Cameron, if you are up for the task to make the 
> "@avalon.jmx.management" 
> mechanism, with my help outside the JMX Facility, give me a time 
> when you can 
> chat over IRC, so we can help each other forward on this...

I'm on PDT, not sure of your timezone Niclas but I am pretty flexible for a time to 
discuss it.  I'll try to be logged on IRC at work today so we can at least schedule 
something.

> Scott, thanks for the contribution, although we may or may not use 
> the code 
> below, you have at least fueled the JMX fire, which is positive for 
> those 
> involved.
> 
> Merlin 3.3 is going out through the door "real soon now", BUT the 
> facilities 
> are not part of the distro anymore. We will roll the facilities one 
> by one as 
> they ready for wider community tests. In the pipeline for the 
> facilities are; 
> embedded http server, JMX, Message-Driven service, embedded Database.
> Milage varies...
> 
> Cheers
> Niclas
> 
> > It automatically assigns ObjectNames based on the implementation 
> package> of the deployed component and the component's block name 
> (i.e.,> "com.mycompany.myproject.mypackage:block=myBlockName"). 
> Alternatively,> the component can implement a Manageable interface 
> that the management
> > extension will use to get a name for the object.
> >
> > Currently, there's no effort to make ObjectNames unique to support
> > non-singleton component lifestyles - I haven't needed it for my 
> project,> so I didn't build it. Someone with a better understanding 
> of Merlin's
> > innards might be able to do that quite easily.
> >
> > If anyone thinks this code would be useful, I'll happily 
> contribute it.
> >
> > Here you go...
> >
> > /**
> >  * @avalon.stage id='urn:flashtalk.com:manageable'
> >  */
> > public interface Manageable {
> >     String getManagementName();
> > }
> >
> > import java.io.File;
> > import javax.management.Attribute;
> > import javax.management.InstanceNotFoundException;
> > import javax.management.MalformedObjectNameException;
> > import javax.management.MBeanRegistrationException;
> > import javax.management.MBeanServer;
> > import javax.management.MBeanServerFactory;
> > import javax.management.ObjectName;
> > import mx4j.adaptor.http.HttpAdaptor;
> > 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.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.logger.LogEnabled;
> > import org.apache.avalon.framework.logger.Logger;
> > import org.apache.avalon.lifecycle.Creator;
> >
> > import javax.management.remote.JMXServiceURL;
> > import javax.management.remote.JMXConnectorServer;
> > import javax.management.remote.JMXConnectorServerFactory;
> >
> > /**
> >  * @avalon.component name='managementServer' lifestyle='singleton'
> >  * @avalon.extension id='urn:flashtalk.com:manageable'
> >  */
> > public class ManagementServer implements Creator, LogEnabled,
> > Configurable, Initializable, Startable, Disposable {
> >     private Logger logger;
> >
> >     public static final int DEFAULT_PORT = 9999;
> >
> >     private MBeanServer mbeanServer;
> >     private HttpAdaptor httpAdaptor;
> >     private JMXConnectorServer connectorServer;
> >
> >     private int port;
> >
> >     public void enableLogging( Logger logger) { this.logger = 
> logger; }
> >
> >     public void configure( Configuration configuration) throws
> > ConfigurationException {
> >             port = configuration.getChild( "port").getValueAsInteger(
> > DEFAULT_PORT);
> >     }
> >
> >     public void initialize() throws Exception {
> >             mbeanServer = MBeanServerFactory.createMBeanServer();
> >             httpAdaptor = new HttpAdaptor();
> >             ObjectName name = new ObjectName( 
> "Server:name=HttpAdaptor");>          mbeanServer.registerMBean( 
> httpAdaptor, name);
> >             httpAdaptor.setPort( port);
> >
> >             ObjectName processorName = new ObjectName(
> > "Server:name=XSLTProcessor");
> >             mbeanServer.createMBean( "mx4j.adaptor.http.XSLTProcessor",
> > processorName, null);
> >             mbeanServer.setAttribute( name, new Attribute( 
> "ProcessorName",> processorName));
> >             mbeanServer.setAttribute( processorName, new Attribute( 
> "File",> System.getProperty( "user.home") + File.separator +
> > "merlin/repository/mx4j/jars/mx4j-tools.1.1.1.jar"));
> >             mbeanServer.setAttribute( processorName, new Attribute( 
> "PathInJar",> "mx4j/adaptor/http/xsl"));
> >             mbeanServer.setAttribute( processorName, new Attribute( 
> "UseCache",> Boolean.FALSE));
> >
> >             logger.info( "creating RMI connector server");
> >             JMXServiceURL url = new JMXServiceURL(
> > "service:jmx:rmi:///jndi/rmi://localhost/server");
> >             connectorServer = 
> JMXConnectorServerFactory.newJMXConnectorServer(> url, null, 
> mbeanServer);>                logger.info( "created RMI connector server");
> >     }
> >
> >     public void start() throws Exception {
> >             httpAdaptor.start();
> >             logger.info( "starting RMI connector server");
> >             connectorServer.start();
> >             logger.info( "started RMI connector server");
> >     }
> >
> >     public void stop() throws Exception {
> >             httpAdaptor.stop();
> >             logger.info( "stopping RMI connector server");
> >             connectorServer.stop();
> >             logger.info( "stopped RMI connector server");
> >     }
> >
> >     public void dispose() {
> >             MBeanServerFactory.releaseMBeanServer( mbeanServer);
> >     }
> >
> >     public void create( Object object, Context context) throws 
> Exception {
> >             String name = generateName( object, ( String) context.get(
> > "urn:avalon:name"));
> >             if ( logger.isDebugEnabled()) logger.debug( "Registering 
> " + object +
> > " (" + name + ")");
> >             ObjectName objectName = new ObjectName( name);
> >             if ( !mbeanServer.isRegistered( objectName))
> > mbeanServer.registerMBean( object, objectName);
> >     }
> >
> >     private String generateName( Object object, String blockName) {
> >             if ( object instanceof Manageable) {
> >                     Manageable manageable = ( Manageable) object;
> >                     return manageable.getManagementName();
> >             }
> >             Class c = object.getClass();
> >             return c.getPackage().getName() + ":block=" + blockName;
> >     }
> >
> >     public void destroy( Object object, Context context) {
> >             String name;
> >             try {
> >                     name = generateName( object, ( String) context.get(
> > "urn:avalon:name"));
> >             } catch ( ContextException e) {
> >                     assert false;
> >                     name = null;
> >             }
> >             if ( logger.isDebugEnabled()) logger.debug( "Releasing " 
> + object + "
> > (" + name + ")");
> >             try {
> >                     mbeanServer.unregisterMBean( new ObjectName( 
> name));>              } catch ( MalformedObjectNameException e) {
> >                     if ( logger.isWarnEnabled()) logger.warn( 
> "releasing " + name, e);
> >             } catch ( InstanceNotFoundException e) {
> >                     if ( logger.isWarnEnabled()) logger.warn( 
> "releasing " + name, e);
> >             } catch ( MBeanRegistrationException e) {
> >                     if ( logger.isWarnEnabled()) logger.warn( 
> "releasing " + name, e);
> >             }
> >     }
> > }
> >
> >
> >
> >
> > ------------------------------------------------------------------
> ---
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> 
> -- 
> +---------//-------------------+
> |   http://www.bali.ac         |
> |  http://niclas.hedhman.org   |
> +------//----------------------+
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to