avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/tools SystemInfo.java SystemInfoMBean.java SystemInfoMBeanDescription.java
Date Sun, 29 Jun 2003 09:16:21 GMT
mcconnell    2003/06/29 02:16:21

  Added:       merlin-test .cvsignore
               merlin-test/merlin-jmx-demo .cvsignore maven.xml project.xml
               merlin-test/merlin-jmx-demo/conf block.xml mbeans.mlet
               merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx
                        HTTPAdaptorWrapper.java JMXServerProxy.java
                        JRMPAdaptorWrapper.java MBeanable.java
                        MBeanableHandler.java
               merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples
                        HelloSample.java HelloSample2.java
                        HelloSample2MBean.java
                        HelloSample2MBeanDescription.java HelloSample3.java
                        HelloSample3MBean.java
                        HelloSample3MBeanDescription.java HelloSample4.java
                        HelloSample4MBean.java
                        HelloSample4MBeanDescription.java
                        HelloSampleMBean.java
                        HelloSampleMBeanDescription.java
               merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/tools
                        SystemInfo.java SystemInfoMBean.java
                        SystemInfoMBeanDescription.java
  Log:
  Commit sample managable components.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin-test/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  project.xml
  maven.log
  velocity.log
  build.properties
  target
  xdocs
  forced-error
  publisher
  singleton
  *.zip
  *.gz
  
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  xdocs
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="java:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
  
    <preGoal name="java:compile">
      <attainGoal name="merlin:meta"/>
    </preGoal>
  
  </project>
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project>
  
    <groupId>merlin</groupId>
    <id>merlin-jmx-demo</id>
    <name>Merlin JMX RMI Test Case</name>
    <package>my.avalon.jmx</package>
  
    <currentVersion>1.0</currentVersion>
    <inceptionYear>2003</inceptionYear>
    <shortDescription>Test for the Merlin RMI JMX Connection.</shortDescription>
  
    <dependencies>
      <dependency>
        <groupId>mx4j</groupId>
        <artifactId>mx4j-jmx</artifactId>
        <version>1.1.1</version>
      </dependency>
      <dependency>
        <groupId>mx4j</groupId>
        <artifactId>mx4j-tools</artifactId>
        <version>1.1.1</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5-dev</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-impl</artifactId>
        <version>4.1.5-dev</version>
      </dependency>
      <dependency>
        <id>excalibur-lifecycle</id>
        <version>1.0</version>
      </dependency>
    </dependencies>
    
    <build>
  
      <sourceDirectory>${basedir}/src/main</sourceDirectory>
      <unitTestSourceDirectory></unitTestSourceDirectory>
      <unitTest></unitTest>
      <testResources></testResources>
      <integrationUnitTestPatterns></integrationUnitTestPatterns>
  
      <resources>
        <resource>
          <directory>${basedir}/src/main</directory> 
          <includes>
            <include>**/*.properties</include>
          </includes>
        </resource>
        <resource>
          <directory>${maven.build.src}</directory> 
          <includes>
            <include>**/*.x*</include>
          </includes>
        </resource>
        <resource>
          <directory>${maven.conf.dir}</directory>
          <targetPath>BLOCK-INF</targetPath>
          <includes>
            <include>block.xml</include>
          </includes>
        </resource>
        <resource>
          <directory>${maven.conf.dir}</directory>
          <includes>
            <include>jndi.properties</include>
            <include>mbeans.mlet</include>
          </includes>
        </resource>
      </resources>
  
      <jars></jars>
  
    </build>
  
  </project>
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/conf/block.xml
  
  Index: block.xml
  ===================================================================
  <?xml version="1.0" encoding="iso-8859-1"?>
  
  <block name="jmx">
  
    <implementation>
  
      <categories priority="INFO"/>
  
      <engine>
        <classpath>
          <repository>
            <resource id="mx4j:mx4j-jmx" version="1.1.1"/>
            <resource id="mx4j:mx4j-tools" version="1.1.1"/>
          </repository>
        </classpath>
      </engine>
  
      <!-- the declaration of jmx-server is optional -->
      <component name="jmx-server" class="my.avalon.jmx.JMXServerProxy" activation="true"/>
  
      <!-- an "jmx-http" could be used to access jmx-server throught HTTP -->
      <component name="jmx-http" class="my.avalon.jmx.HTTPAdaptorWrapper" activation="true">
        <configuration>
          <xslt-processor enable="true"/>
          <port>8082</port>
          <host>localhost</host>
        </configuration>
      </component>
  
      <component name="jmx-jrmp" class="my.avalon.jmx.JRMPAdaptorWrapper" activation="true">
        <configuration>
          <port>1099</port>
        </configuration>
      </component>
  
      <!-- samples component (see api for difference) -->
      <component name="system-info" class="my.avalon.jmx.tools.SystemInfo" activation="true"/>
  
      <!-- samples component (see api for difference) -->
      <component name="jmx-hello" class="my.avalon.jmx.samples.HelloSample" activation="true"/>
      <component name="jmx-hello2" class="my.avalon.jmx.samples.HelloSample2" activation="true"/>
      <component name="jmx-hello3" class="my.avalon.jmx.samples.HelloSample3" activation="true"/>
      <component name="jmx-hello3Bis" class="my.avalon.jmx.samples.HelloSample3" activation="true"/>
      <container name="jmx-hello4Compo" class="my.avalon.jmx.samples.HelloSample4" activation="true">
        <component name="jmx-hello3Sub" class="my.avalon.jmx.samples.HelloSample3" activation="true"/>
      </container>
    </implementation>
  </block>
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/conf/mbeans.mlet
  
  Index: mbeans.mlet
  ===================================================================
  <!--
    Generated file - Do not edit!
  -->
  
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/HTTPAdaptorWrapper.java
  
  Index: HTTPAdaptorWrapper.java
  ===================================================================
  package my.avalon.jmx;
  
  import mx4j.adaptor.http.HttpAdaptor;
  import mx4j.adaptor.http.XSLTProcessor;
  
  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.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  
  /**
   * Wrapper of the mx4j HttpAdaptor to use it in the Avalon Framework.
   *
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-http
   * @avalon.meta.lifestyle singleton
   */
  public class HTTPAdaptorWrapper extends AbstractLogEnabled implements Serviceable, Configurable, Startable {
      private HttpAdaptor wrapped_;
      private MBeanServer jmxServer_;
      private ObjectName  jmxName_;
  
      public HTTPAdaptorWrapper() {
          wrapped_ = new HttpAdaptor();
      }
  
      /**
       * Servicing of the component by the container during
       * which service dependencies declared under the component
       * can be resolved using the supplied service manager.
       *
       * @param manager the service manager
       * @avalon.meta.dependency key="jmx-server" type="javax.management.MBeanServer"
       */
      public void service(ServiceManager manager) throws ServiceException {
          jmxServer_ = (MBeanServer) manager.lookup("jmx-server");
      }
  
      /**
       * Configuration of the component by the container.  The
       * implementation get a child element named 'source' and
       * assigns the value of the element to a local variable.
       *
       * @param config the component configuration
       * @exception ConfigurationException if a configuration error occurs
       */
      public void configure(Configuration config) throws ConfigurationException {
          try {
              wrapped_.setHost(config.getChild("host").getValue(null));
              wrapped_.setPort(config.getChild("port").getValueAsInteger(8082));
              jmxName_ = new ObjectName(config.getAttribute("jmxName", "JMXServer:name=adaptor,protocol=HTTP"));
  
              if (config.getChild("xslt-processor").getAttributeAsBoolean("enable", false)) {
                  XSLTProcessor xsltProcessor = new XSLTProcessor();
                  wrapped_.setProcessor(xsltProcessor);
              }
          } catch (Exception exc) {
              throw new ConfigurationException("", exc);
          }
      }
  
      public void start() throws Exception {
          jmxServer_.registerMBean(wrapped_, jmxName_);
          wrapped_.start();
      }
  
      public void stop() throws Exception {
          wrapped_.stop();
          jmxServer_.unregisterMBean(jmxName_);
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/JMXServerProxy.java
  
  Index: JMXServerProxy.java
  ===================================================================
  package my.avalon.jmx;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  import java.io.ObjectInputStream;
  
  import java.util.Set;
  
  import javax.management.*;
  
  
  /**
   * JMXServerProxy is a proxy to a MBeanServer (adpater MBeanServer to Avalon).
   *
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-server
   * @avalon.meta.service type="javax.management.MBeanServer"
   * @avalon.meta.lifestyle singleton
   */
  public class JMXServerProxy extends AbstractLogEnabled implements Initializable, MBeanServer {
      private MBeanServer server_;
  
      /**
      * Initialization of the component by the container.
      * @exception Exception if an initialization error occurs
      */
      public void initialize() throws Exception {
          getLogger().info("initialization stage");
          server_ = MBeanServerFactory.createMBeanServer();
      }
  
      //-- MBeanServer impl (can't use Dynamic Proxy if I wan't to use it as a standard component)
      public void addNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback)
                                   throws InstanceNotFoundException {
          server_.addNotificationListener(observed, listener, filter, handback);
      }
  
      public void addNotificationListener(ObjectName observed, ObjectName listener, NotificationFilter filter, Object handback)
                                   throws InstanceNotFoundException {
          server_.addNotificationListener(observed, listener, filter, handback);
      }
  
      public void removeNotificationListener(ObjectName observed, NotificationListener listener)
                                      throws InstanceNotFoundException, ListenerNotFoundException {
          server_.removeNotificationListener(observed, listener);
      }
  
      public void removeNotificationListener(ObjectName observed, ObjectName listener)
                                      throws InstanceNotFoundException, ListenerNotFoundException {
          server_.removeNotificationListener(observed, listener);
      }
  
      public Object instantiate(String className) throws ReflectionException, MBeanException {
          return server_.instantiate(className);
      }
  
      public Object instantiate(String className, ObjectName loaderName)
                         throws ReflectionException, MBeanException, InstanceNotFoundException {
          return server_.instantiate(className, loaderName);
      }
  
      public Object instantiate(String className, ObjectName loaderName, Object[] args, String[] parameters)
                         throws ReflectionException, MBeanException, InstanceNotFoundException {
          return server_.instantiate(className, loaderName, args, parameters);
      }
  
      public Object instantiate(String className, Object[] args, String[] parameters)
                         throws ReflectionException, MBeanException {
          return server_.instantiate(className, args, parameters);
      }
  
      public ObjectInstance createMBean(String className, ObjectName objectName)
                                 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
                                        NotCompliantMBeanException {
          return server_.createMBean(className, objectName);
      }
  
      public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName)
                                 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
                                        NotCompliantMBeanException, InstanceNotFoundException {
          return server_.createMBean(className, objectName, loaderName);
      }
  
      public ObjectInstance createMBean(java.lang.String className, ObjectName objectName, Object[] args, String[] parameters)
                                 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
                                        NotCompliantMBeanException {
          return server_.createMBean(className, objectName, args, parameters);
      }
  
      public ObjectInstance createMBean(String className, ObjectName objectName, ObjectName loaderName, Object[] args, String[] parameters)
                                 throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
                                        NotCompliantMBeanException, InstanceNotFoundException {
          return server_.createMBean(className, objectName, loaderName, args, parameters);
      }
  
      public ObjectInstance registerMBean(Object mbean, ObjectName objectName)
                                   throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
          return server_.registerMBean(mbean, objectName);
      }
  
      public void unregisterMBean(ObjectName objectName)
                           throws InstanceNotFoundException, MBeanRegistrationException {
          server_.unregisterMBean(objectName);
      }
  
      public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] bytes)
                                    throws InstanceNotFoundException, OperationsException, ReflectionException {
          return server_.deserialize(className, loaderName, bytes);
      }
  
      public ObjectInputStream deserialize(String className, byte[] bytes)
                                    throws OperationsException, ReflectionException {
          return server_.deserialize(className, bytes);
      }
  
      public ObjectInputStream deserialize(ObjectName objectName, byte[] bytes)
                                    throws InstanceNotFoundException, OperationsException {
          return server_.deserialize(objectName, bytes);
      }
  
      public Object getAttribute(ObjectName objectName, String attribute)
                          throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
          return server_.getAttribute(objectName, attribute);
      }
  
      public void setAttribute(ObjectName objectName, Attribute attribute)
                        throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
          server_.setAttribute(objectName, attribute);
      }
  
      public AttributeList getAttributes(ObjectName objectName, String[] attributes)
                                  throws InstanceNotFoundException, ReflectionException {
          return server_.getAttributes(objectName, attributes);
      }
  
      public AttributeList setAttributes(ObjectName objectName, AttributeList attributes)
                                  throws InstanceNotFoundException, ReflectionException {
          return server_.setAttributes(objectName, attributes);
      }
  
      public Object invoke(ObjectName objectName, String methodName, Object[] args, String[] parameters)
                    throws InstanceNotFoundException, MBeanException, ReflectionException {
          return server_.invoke(objectName, methodName, args, parameters);
      }
  
      public String getDefaultDomain() {
          return server_.getDefaultDomain();
      }
  
      public Integer getMBeanCount() {
          return server_.getMBeanCount();
      }
  
      public boolean isRegistered(ObjectName objectName) {
          return server_.isRegistered(objectName);
      }
  
      public MBeanInfo getMBeanInfo(ObjectName objectName)
                             throws InstanceNotFoundException, IntrospectionException, ReflectionException {
          return server_.getMBeanInfo(objectName);
      }
  
      public ObjectInstance getObjectInstance(ObjectName objectName)
                                       throws InstanceNotFoundException {
          return server_.getObjectInstance(objectName);
      }
  
      public boolean isInstanceOf(ObjectName objectName, String className)
                           throws InstanceNotFoundException {
          return server_.isInstanceOf(objectName, className);
      }
  
      public Set queryMBeans(ObjectName patternName, QueryExp filter) {
          return server_.queryMBeans(patternName, filter);
      }
  
      public Set queryNames(ObjectName patternName, QueryExp filter) {
          return server_.queryNames(patternName, filter);
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/JRMPAdaptorWrapper.java
  
  Index: JRMPAdaptorWrapper.java
  ===================================================================
  package my.avalon.jmx;
  
  import mx4j.adaptor.rmi.jrmp.JRMPAdaptor;
  
  import mx4j.tools.naming.NamingService;
  
  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.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import javax.naming.Context;
  
  
  /**
   * Wrapper of the mx4j RMIAdaptor to use it in the Avalon Framework.
   *
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-rmi
   * @avalon.meta.lifestyle singleton
   */
  public class JRMPAdaptorWrapper extends AbstractLogEnabled implements Serviceable, Configurable, Startable {
      private MBeanServer   jmxServer_;
      private JRMPAdaptor   wrapped_;
      private ObjectName    jmxName_;
      private NamingService naming_;
      private ObjectName    jmxNameNaming_;
      private int           port_;
  
      /**
       * Servicing of the component by the container during
       * which service dependencies declared under the component
       * can be resolved using the supplied service manager.
       *
       * @param manager the service manager
       * @avalon.meta.dependency key="jmx-server" type="javax.management.MBeanServer"
       */
      public void service(ServiceManager manager) throws ServiceException {
          jmxServer_ = (MBeanServer) manager.lookup("jmx-server");
      }
  
      /**
       * Configuration of the component by the container.  The
       * implementation get a child element named 'source' and
       * assigns the value of the element to a local variable.
       *
       * @param config the component configuration
       * @exception ConfigurationException if a configuration error occurs
       */
      public void configure(Configuration config) throws ConfigurationException {
          port_ = config.getChild("port").getValueAsInteger(1099);
      }
  
      public void start() throws Exception {
          // Create and start the naming service
          jmxNameNaming_     = new ObjectName("JMXServer:name=naming,type=rmiregistry");
          naming_            = new NamingService(port_);
          jmxServer_.registerMBean(naming_, jmxNameNaming_);
          naming_.start();
  
          // Create the JRMP adaptor
          ObjectName jmxName_ = new ObjectName("JMXServer:name=adaptor,protocol=JRMP");
          wrapped_ = new JRMPAdaptor();
          wrapped_.setJNDIName("jrmp");
          wrapped_.setPort(port_);
  
          // Optionally, you can specify the JNDI properties,
          // instead of having in the classpath a jndi.properties file
          wrapped_.putJNDIProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
          wrapped_.putJNDIProperty(Context.PROVIDER_URL, "rmi://localhost:" + port_);
  
          jmxServer_.registerMBean(wrapped_, jmxName_);
          wrapped_.start();
      }
  
      public void stop() throws Exception {
          wrapped_.stop();
          jmxServer_.unregisterMBean(jmxName_);
          naming_.stop();
          jmxServer_.unregisterMBean(jmxNameNaming_);
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/MBeanable.java
  
  Index: MBeanable.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx;
  
  
  /**
   * Interface to implements, if component need to control the name used
   * when component is (un)registered into "jmx-server" by MBeanableHandler.
   */
  public interface MBeanable {
      /**
       * name used to (un)register the component, must be <strong>constant</strong> through the 2 calls.
       * @return the name of the component into "jmx-server".
       */
      public String getName();
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/MBeanableHandler.java
  
  Index: MBeanableHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.lifecycle.Accessor;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  
  /**
   * (Un)Register object to the "jmx-server" service. The domaine is "Application"
   * and the name to used to identified object is:
   * <ul>
   *   <li>the return of the method MBeanable.getName() if object is instance of MBeanable.</li>
   *   <li>the value of "urn:avalon:name" store in context.</li>
   * </ul>
   *
   * To be auto-registered a MBean component need to include the stage "my.avalon.jmx.MBeanable".
   * The implementation of the interface my.avalon.jmx.MBeanable is optional (only if you want to choose your name).
   *
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-handler
   * @avalon.meta.extension type="my.avalon.jmx.MBeanable"
   */
  public class MBeanableHandler extends AbstractLogEnabled implements Accessor, Serviceable {
      private MBeanServer jmxServer_;
  
      /**
      * Servicing of the component by the container during
      * which service dependencies declared under the component
      * can be resolved using the supplied service manager.
      *
      * @param manager the service manager
      * @avalon.meta.dependency key="jmx-server" type="javax.management.MBeanServer" optional="true"
      */
      public void service(ServiceManager manager) throws ServiceException {
          if (manager.hasService("jmx-server")) {
              jmxServer_ = (MBeanServer) manager.lookup("jmx-server");
          }
      }
  
      /**
       * Register object to "jmx-server" service.
       */
      public void access(Object object, Context context)
                  throws Exception {
          try {
              if (jmxServer_ != null) {
                  ObjectName name = getObjectName(object, context);
                  jmxServer_.registerMBean(object, name);
                  getLogger().debug("register component : " + name);
              }
          } catch (Exception exc) {
              getLogger().warn("register", exc);
          }
      }
  
      /**
       * Unregister object form "jmx-server" service.
       */
      public void release(Object object, Context context) {
          try {
              if (jmxServer_ != null) {
                  ObjectName name = getObjectName(object, context);
                  jmxServer_.unregisterMBean(name);
                  getLogger().debug("unregister component : " + name);
              }
          } catch (Exception exc) {
              getLogger().warn("unregister", exc);
          }
      }
  
      /**
       * build the ObjectName from source Object and it's context.
       * @param obj the object to register with returned ObjectName.
       * @param context context to use to find "urn:avalon:name" to use if obj isn't instanceof MBeanable
       * @return the builded ObjectName.
       */
      private ObjectName getObjectName(Object obj, Context context)
                                throws Exception {
          String back = null;
  
          if (obj instanceof MBeanable) {
              back = ((MBeanable) obj).getName();
          }
  
          if (back == null) {
              back = (String) context.get("urn:avalon:partition");
          }
  
          return new ObjectName("Application:name=" + back);
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample.java
  
  Index: HelloSample.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx.samples;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.activity.Initializable;
  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.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  
  /**
   * HelloSample sample of avalon component usable throught jmx.
   * This implementation don't use stage but need direct access to "jmx-server" service, and
   * control when (un)register.
   * <ul>
   *   <li>this implementation is more portable (I think it could be work on Fortress,
   *        because don't use any container special features).</li>
   *   <li>this implementation require to include all the (un)registering code (and search of the jmx-server)</li>
   * </ul>
   *
   * @jmx.mbean
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-hello
   */
  public class HelloSample extends AbstractLogEnabled implements HelloSampleMBean, Serviceable, Configurable, Initializable, Executable, Disposable {
      private MBeanServer jmxServer_;
      private ObjectName  jmxName_;
  
      /**
       * Servicing of the component by the container during
       * which service dependencies declared under the component
       * can be resolved using the supplied service manager.
       *
       * @param manager the service manager
       * @avalon.meta.dependency key="jmx-server" type="javax.management.MBeanServer"
       */
      public void service(ServiceManager manager) throws ServiceException {
          jmxServer_ = (MBeanServer) manager.lookup("jmx-server");
      }
  
      /**
       * Configuration of the component by the container.  The
       * implementation get a child element named 'source' and
       * assigns the value of the element to a local variable.
       *
       * @param config the component configuration
       * @exception ConfigurationException if a configuration error occurs
       */
      public void configure(Configuration config) throws ConfigurationException {
          try {
              jmxName_ = new ObjectName(config.getAttribute("jmxName", "Application:name=HelloSample"));
          } catch (Exception exc) {
              throw new ConfigurationException("", exc);
          }
      }
  
      /**
       * Initialization of the component by the container.
       * @exception Exception if an initialization error occurs
       */
      public void initialize() throws Exception {
          getLogger().info("initialize");
          jmxServer_.registerMBean(this, jmxName_);
      }
  
      /**
       * log a info message "execute".
       * @jmx.managed-operation
       */
      public void execute() throws Exception {
          getLogger().info(this.getClass() + " : execute");
      }
  
      public void dispose() {
          getLogger().info("dispose");
  
          try {
              jmxServer_.unregisterMBean(jmxName_);
          } catch (Exception exc) {
              getLogger().warn("", exc);
          }
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample2.java
  
  Index: HelloSample2.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx.samples;
  
  import my.avalon.jmx.MBeanable;
  
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  
  /**
   * HelloSample sample of avalon component usable throught jmx.
   * This component include stage "my.avalon.jmx.MBeanable" and implements MBeanable interface.
   *
   * @jmx.mbean
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-hello2
   * @avalon.meta.stage type="my.avalon.jmx.MBeanable"
   */
  public class HelloSample2 extends AbstractLogEnabled implements HelloSample2MBean, MBeanable, Executable {
      public String getName() {
          return "HelloSample2";
      }
  
      /**
       * log a info message "execute".
       * @jmx.managed-operation
       */
      public void execute() throws Exception {
          getLogger().info(this.getClass() + " : execute");
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample2MBean.java
  
  Index: HelloSample2MBean.java
  ===================================================================
  /*
   * Generated file - Do not edit!
   */
  package my.avalon.jmx.samples;
  
  /**
   * MBean interface.
   * @xdoclet-genereted @ 20030629 0907
   */
  public interface HelloSample2MBean {
  
     /**
      * log a info message "execute".
      */
    void execute() throws java.lang.Exception;
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample2MBeanDescription.java
  
  Index: HelloSample2MBeanDescription.java
  ===================================================================
  /* * Generated file - Do not edit! */package my.avalon.jmx.samples;import mx4j.MBeanDescriptionAdapter;import java.lang.reflect.Method;import java.lang.reflect.Constructor;/** * MBean description. * @xdoclet-genereted @ 20030629 0907
   */public class HelloSample2MBeanDescription extends                         MBeanDescriptionAdapter    {      public String getConstructorDescription(Constructor ctor) {        String name = ctor.getName();             return super.getConstructorDescription(ctor);    }    public String getConstructorParameterName(Constructor ctor, int index) {              return super.getConstructorParameterName(ctor, index);    }    public String getConstructorParameterDescription(Constructor ctor, int index) {              return super.getConstructorParameterDescription(ctor, index);    }    public String getAttributeDescription(String attribute) {                                   return super.getAttributeDescription(attribute);    }    public String getOperationDescription(Method operation) {        String name = operation.getName();                                        return super.getOperationDescription(operation);    }    public String getOperationParameterName(Method method, int index) {        String name = method.getName();                                        return super.getOperationParameterName(method, index);    }    public String getOperationParameterDescription(Method method, int index) {        String name = method.getName();                                        return super.getOperationParameterDescription(method, index);    }}
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample3.java
  
  Index: HelloSample3.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx.samples;
  
  import my.avalon.jmx.MBeanable;
  
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  
  /**
   * HelloSample sample of avalon component usable throught jmx.
   * This component include stage "my.avalon.jmx.MBeanable" but don't implements MBeanable interface.
   * "a meta.verifier.VerifyException" is throw, but Component is accessible.
   *
   * @jmx.mbean
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-hello3
   * @avalon.meta.stage type="my.avalon.jmx.MBeanable"
   */
  public class HelloSample3 extends AbstractLogEnabled implements HelloSample3MBean, Executable {
      /**
       * log a info message "execute".
       * @jmx.managed-operation
       */
      public void execute() throws Exception {
          getLogger().info(this.getClass() + " : execute");
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample3MBean.java
  
  Index: HelloSample3MBean.java
  ===================================================================
  /*
   * Generated file - Do not edit!
   */
  package my.avalon.jmx.samples;
  
  /**
   * MBean interface.
   * @xdoclet-genereted @ 20030629 0907
   */
  public interface HelloSample3MBean {
  
     /**
      * log a info message "execute".
      */
    void execute() throws java.lang.Exception;
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample3MBeanDescription.java
  
  Index: HelloSample3MBeanDescription.java
  ===================================================================
  /* * Generated file - Do not edit! */package my.avalon.jmx.samples;import mx4j.MBeanDescriptionAdapter;import java.lang.reflect.Method;import java.lang.reflect.Constructor;/** * MBean description. * @xdoclet-genereted @ 20030629 0907
   */public class HelloSample3MBeanDescription extends                         MBeanDescriptionAdapter    {      public String getConstructorDescription(Constructor ctor) {        String name = ctor.getName();             return super.getConstructorDescription(ctor);    }    public String getConstructorParameterName(Constructor ctor, int index) {              return super.getConstructorParameterName(ctor, index);    }    public String getConstructorParameterDescription(Constructor ctor, int index) {              return super.getConstructorParameterDescription(ctor, index);    }    public String getAttributeDescription(String attribute) {                        return super.getAttributeDescription(attribute);    }    public String getOperationDescription(Method operation) {        String name = operation.getName();                           return super.getOperationDescription(operation);    }    public String getOperationParameterName(Method method, int index) {        String name = method.getName();                           return super.getOperationParameterName(method, index);    }    public String getOperationParameterDescription(Method method, int index) {        String name = method.getName();                           return super.getOperationParameterDescription(method, index);    }}
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample4.java
  
  Index: HelloSample4.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx.samples;
  
  import my.avalon.jmx.MBeanable;
  
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  
  /**
   * HelloSample sample of avalon component usable throught jmx.
   * This component include stage "my.avalon.jmx.MBeanable" and implements MBeanable interface,
   * but return null as getName(), so MBeanableHandler used "urn:avalon:name".
   *
   * @jmx.mbean
   * @avalon.meta.version 1.0
   * @avalon.meta.name jmx-hello2
   * @avalon.meta.stage type="my.avalon.jmx.MBeanable"
   */
  public class HelloSample4 extends AbstractLogEnabled 
     implements HelloSample4MBean, MBeanable, Executable 
  {
      public String getName() 
      {
          return null;
      }
  
      /**
       * log a info message "execute".
       * @jmx.managed-operation
       */
      public void execute() throws Exception {
          getLogger().info(this.getClass() + " : execute");
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample4MBean.java
  
  Index: HelloSample4MBean.java
  ===================================================================
  /*
   * Generated file - Do not edit!
   */
  package my.avalon.jmx.samples;
  
  /**
   * MBean interface.
   * @xdoclet-genereted @ 20030629 0907
   */
  public interface HelloSample4MBean {
  
     /**
      * log a info message "execute".
      */
    void execute() throws java.lang.Exception;
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSample4MBeanDescription.java
  
  Index: HelloSample4MBeanDescription.java
  ===================================================================
  /* * Generated file - Do not edit! */package my.avalon.jmx.samples;import mx4j.MBeanDescriptionAdapter;import java.lang.reflect.Method;import java.lang.reflect.Constructor;/** * MBean description. * @xdoclet-genereted @ 20030629 0907
   */public class HelloSample4MBeanDescription extends                         MBeanDescriptionAdapter    {      public String getConstructorDescription(Constructor ctor) {        String name = ctor.getName();             return super.getConstructorDescription(ctor);    }    public String getConstructorParameterName(Constructor ctor, int index) {              return super.getConstructorParameterName(ctor, index);    }    public String getConstructorParameterDescription(Constructor ctor, int index) {              return super.getConstructorParameterDescription(ctor, index);    }    public String getAttributeDescription(String attribute) {                                   return super.getAttributeDescription(attribute);    }    public String getOperationDescription(Method operation) {        String name = operation.getName();                                        return super.getOperationDescription(operation);    }    public String getOperationParameterName(Method method, int index) {        String name = method.getName();                                        return super.getOperationParameterName(method, index);    }    public String getOperationParameterDescription(Method method, int index) {        String name = method.getName();                                        return super.getOperationParameterDescription(method, index);    }}
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSampleMBean.java
  
  Index: HelloSampleMBean.java
  ===================================================================
  /*
   * Generated file - Do not edit!
   */
  package my.avalon.jmx.samples;
  
  /**
   * MBean interface.
   * @xdoclet-genereted @ 20030629 0907
   */
  public interface HelloSampleMBean {
  
     /**
      * log a info message "execute".
      */
    void execute() throws java.lang.Exception;
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/samples/HelloSampleMBeanDescription.java
  
  Index: HelloSampleMBeanDescription.java
  ===================================================================
  /* * Generated file - Do not edit! */package my.avalon.jmx.samples;import mx4j.MBeanDescriptionAdapter;import java.lang.reflect.Method;import java.lang.reflect.Constructor;/** * MBean description. * @xdoclet-genereted @ 20030629 0907
   */public class HelloSampleMBeanDescription extends                         MBeanDescriptionAdapter    {      public String getConstructorDescription(Constructor ctor) {        String name = ctor.getName();             return super.getConstructorDescription(ctor);    }    public String getConstructorParameterName(Constructor ctor, int index) {              return super.getConstructorParameterName(ctor, index);    }    public String getConstructorParameterDescription(Constructor ctor, int index) {              return super.getConstructorParameterDescription(ctor, index);    }    public String getAttributeDescription(String attribute) {                                                                    return super.getAttributeDescription(attribute);    }    public String getOperationDescription(Method operation) {        String name = operation.getName();                                                                               return super.getOperationDescription(operation);    }    public String getOperationParameterName(Method method, int index) {        String name = method.getName();                                                                               return super.getOperationParameterName(method, index);    }    public String getOperationParameterDescription(Method method, int index) {        String name = method.getName();                                                                               return super.getOperationParameterDescription(method, index);    }}
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/tools/SystemInfo.java
  
  Index: SystemInfo.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   *
   * http://www.apache.org/
   */
  package my.avalon.jmx.tools;
  
  import my.avalon.jmx.MBeanable;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  import java.util.Properties;
  
  
  /**
   * This Component provide System and Runtime information as MBean.
   * Useness for monitoring.
   *
   * @jmx.mbean
   * @avalon.meta.version 1.0
   * @avalon.meta.name system-info
   * @avalon.meta.stage type="my.avalon.jmx.MBeanable"
   */
  public class SystemInfo extends AbstractLogEnabled implements Initializable, SystemInfoMBean, MBeanable {
      private ThreadGroup rootThreadGroup_;
  
      public void initialize() throws Exception {
          ThreadGroup t = Thread.currentThread().getThreadGroup();
  
          while (t != null) {
              rootThreadGroup_     = t;
              t                    = t.getParent();
          }
      }
  
      public String getName() {
          return "SystemInfo";
      }
  
      /**
       * @jmx.managed-attribute description="Returns the amount of free memory in the system. see Runtime.freeMemory()"
       */
      public long getFreeMemory() throws Exception {
          return Runtime.getRuntime().freeMemory();
      }
  
      /**
       * @jmx.managed-attribute description="Returns the total amount of memory in the Java Virtual Machine. see Runtime.totalMemory()"
       */
      public long getTotalMemory() throws Exception {
          return Runtime.getRuntime().totalMemory();
      }
  
      /**
       * @jmx.managed-attribute description="Returns the ratio (%) free/total amount of memory in the Java Virtual Machine."
       */
      public int getRatioMemory() throws Exception {
          return (int) ((Runtime.getRuntime().freeMemory() * 100) / Runtime.getRuntime().totalMemory());
      }
  
      /**
       * @jmx.managed-operation description="Runs the garbage collector. see Runtime.gc()"
       */
      public void gc(int status) throws Exception {
          Runtime.getRuntime().gc();
      }
  
      /**
       * @jmx.managed-operation description="Terminates the currently running Java virtual machine by initiating its shutdown sequence. see Runtime.exit(int)"
       */
      public void exit(int status) throws Exception {
          Runtime.getRuntime().exit(status);
      }
  
      /**
       * @jmx.managed-operation description="Enables/Disables tracing of instructions. see Runtime.traceInstructions(boolean)"
       */
      public void traceInstructions(boolean on) throws Exception {
          Runtime.getRuntime().traceInstructions(on);
      }
  
      /**
       * @jmx.managed-operation description="Enables/Disables tracing of method calls. see Runtime.traceMethodCalls(boolean)"
       */
      public void traceMethodCalls(boolean on) throws Exception {
          Runtime.getRuntime().traceMethodCalls(on);
      }
  
      /**
       * @jmx.managed-operation description="Determines the current system properties. see System.getProperties()"
       */
      public Properties showProperties() throws Exception {
          return System.getProperties();
      }
  
      /**
       * @jmx.managed-attribute description="Gets the system property indicated by the specified key. see System.getProperty(String)"
       */
      public String getProperty(String key) throws Exception {
          return getProperty(key);
      }
  
      /**
       * @jmx.managed-attribute description="Returns an estimate of the number of active threads."
       */
      public int getNumberOfActiveThreads() throws Exception {
          return rootThreadGroup_.activeCount();
      }
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/tools/SystemInfoMBean.java
  
  Index: SystemInfoMBean.java
  ===================================================================
  /*
   * Generated file - Do not edit!
   */
  package my.avalon.jmx.tools;
  
  /**
   * MBean interface.
   * @xdoclet-genereted @ 20030629 0907
   */
  public interface SystemInfoMBean {
  
    long getFreeMemory() throws java.lang.Exception;
  
    long getTotalMemory() throws java.lang.Exception;
  
    int getRatioMemory() throws java.lang.Exception;
  
    void gc(int status) throws java.lang.Exception;
  
    void exit(int status) throws java.lang.Exception;
  
    void traceInstructions(boolean on) throws java.lang.Exception;
  
    void traceMethodCalls(boolean on) throws java.lang.Exception;
  
    java.util.Properties showProperties() throws java.lang.Exception;
  
    java.lang.String getProperty(java.lang.String key) throws java.lang.Exception;
  
    int getNumberOfActiveThreads() throws java.lang.Exception;
  
  }
  
  
  
  1.1                  avalon-sandbox/merlin-test/merlin-jmx-demo/src/main/my/avalon/jmx/tools/SystemInfoMBeanDescription.java
  
  Index: SystemInfoMBeanDescription.java
  ===================================================================
  /* * Generated file - Do not edit! */package my.avalon.jmx.tools;import mx4j.MBeanDescriptionAdapter;import java.lang.reflect.Method;import java.lang.reflect.Constructor;/** * MBean description. * @xdoclet-genereted @ 20030629 0907
   */public class SystemInfoMBeanDescription extends                         MBeanDescriptionAdapter    {      public String getConstructorDescription(Constructor ctor) {        String name = ctor.getName();             return super.getConstructorDescription(ctor);    }    public String getConstructorParameterName(Constructor ctor, int index) {              return super.getConstructorParameterName(ctor, index);    }    public String getConstructorParameterDescription(Constructor ctor, int index) {              return super.getConstructorParameterDescription(ctor, index);    }    public String getAttributeDescription(String attribute) {                                                if (attribute.equals("FreeMemory")) {            return "Returns the amount of free memory in the system. see Runtime.freeMemory()";        }                                       if (attribute.equals("TotalMemory")) {            return "Returns the total amount of memory in the Java Virtual Machine. see Runtime.totalMemory()";        }                                       if (attribute.equals("RatioMemory")) {            return "Returns the ratio (%) free/total amount of memory in the Java Virtual Machine.";        }                                                                                                                      if (attribute.equals("NumberOfActiveThreads")) {            return "Returns an estimate of the number of active threads.";        }                          return super.getAttributeDescription(attribute);    }    public String getOperationDescription(Method operation) {        String name = operation.getName();                                                                                      if (name.equals("gc")) {            return "Runs the garbage collector. see Runtime.gc()";        }                            if (name.equals("exit")) {            return "Terminates the currently running Java virtual machine by initiating its shutdown sequence. see Runtime.exit(int)";        }                            if (name.equals("traceInstructions")) {            return "Enables/Disables tracing of instructions. see Runtime.traceInstructions(boolean)";        }                            if (name.equals("traceMethodCalls")) {            return "Enables/Disables tracing of method calls. see Runtime.traceMethodCalls(boolean)";        }                            if (name.equals("showProperties")) {            return "Determines the current system properties. see System.getProperties()";        }                                               return super.getOperationDescription(operation);    }    public String getOperationParameterName(Method method, int index) {        String name = method.getName();                                                                                                                                                                          return super.getOperationParameterName(method, index);    }    public String getOperationParameterDescription(Method method, int index) {        String name = method.getName();                                                                                                                                                                          return super.getOperationParameterDescription(method, index);    }}
  
  

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


Mime
View raw message