Dashboard > Jetty > ... > Jetty Documentation > JMX
JMX Log In | Sign Up   View a printable version of the current page.

Added by Greg Wilkins , last edited by Greg Wilkins on Mar 09, 2008  (view change)
Labels: 
(None)

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Jetty JMX Integration

The jetty JMX integration is based on the ObjectMBean implementation of DynamicMBean. This implementation allows an arbitrary POJO to be wrapped in an MBean and for meta data to be provided by properties files

The creation of MBeans is coordinated by the MBeanContainer implementation of the Container.Listener interface. The Jetty Server and it's components use a Container to maintain a containment tree of components and to support notification of changes to that tree. The MBeanContainer class listens for Container events and creates and destroys MBeans as required to wrap all Jetty components.

Using Jetty MBeans

The simplest way to use Jetty MBeans is to use the JVM supplied jconsole utility. If you use mx4j, then an internal HTTP agent can also be used (see jetty-jmx.xml config file comments).

See Running jetty with jconsole for instructions on how to configure jmx for use with Sun's jconsole.

Jetty Standalone

The MBeanContainer instance can be configured for a Jetty server by the jetty-jmx.xml configuration file. This can be run with the standard configuration file as follows:

java -jar start.jar etc/jetty-jmx.xml etc/jetty.xml

Jetty Maven Plugin

If you are using the jetty maven plugin you should copy the etc/jetty-jmx.xml file into your webapp project somewhere, such as src/etc, then add a <jettyConfig> element to the plugin <configuration>:

<plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>${project.version}</version>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <jettyConfig>src/etc/jetty-jmx.xml</jettyConfig>
          <userRealms>
            <userRealm implementation="org.mortbay.jetty.security.HashUserRealm">
              <name>Test Realm</name>
              <config>../../etc/realm.properties</config>
            </userRealm>
          </userRealms>
        </configuration>
</plugin>

Running on Java 1.4 and below (with MX4J)

To run on Java 1.4 and below, mx4j library is used to provide the MBean server.
The commented out section of jetty-jmx.xml needs to be added to create the
mbean server and to register the JMX RMI connector:

<Call id="MBeanServer" class="javax.management.MBeanServerFactory" name="createMBeanServer"/>

<Call id="jmxConnector" class="javax.management.remote.JMXConnectorServerFactory" name="newJMXConnectorServer">
  <Arg>
    <New  class="javax.management.remote.JMXServiceURL">
      <Arg>service:jmx:rmi:///jndi/rmi:///jettymbeanserver</Arg>
    </New>
  </Arg>
  <Arg/>
  <Arg><Ref id="MBeanServer"/></Arg>
  <Call name="start"/>
</Call>

Then, you will need to ensure that you have the rmiregistry running. The start sequence becomes:

rmiregistry &
java -Dcom.sun.management.jmxremote -jar start.jar etc/jetty-jmx.xml etc/jetty.xml [config files]
jconsole &

You then need to configure jconsole to find this remote connector using the Advanced panel and enter the connector url like so:

Click the Connect button and you will be able to manipulate the Jetty mbeans.

An example of how to start up Jetty with JMX programatically:

public static void main(String[] args) throws Exception {

    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    WebAppContext web = new WebAppContext();
    web.setContextPath("/wicket-in-action");
    web.setWar("src/webapp");
    server.addHandler(web);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    server.getContainer().addEventListener(mBeanContainer);
    mBeanContainer.start();

    try {
      server.start();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators