or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/maven-org-eclipse-jetty--jetty-jmx

JMX management integration library for Eclipse Jetty web server providing monitoring and administration capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.eclipse.jetty/jetty-jmx@12.0.x

To install, run

npx @tessl/cli install tessl/maven-org-eclipse-jetty--jetty-jmx@12.0.0

index.mddocs/

Jetty JMX

JMX (Java Management Extensions) integration library for Eclipse Jetty web server providing comprehensive monitoring, management, and administration capabilities. This package enables system administrators and developers to track server performance metrics, configure runtime parameters, and manage server lifecycle operations through standard JMX interfaces.

Package Information

  • Package Name: jetty-jmx
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-jmx</artifactId>
        <version>12.0.21</version>
    </dependency>
  • Module: org.eclipse.jetty.jmx

Core Imports

import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.jmx.ConnectorServer;
import org.eclipse.jetty.jmx.ObjectMBean;

Module imports:

module org.eclipse.jetty.jmx {
    requires org.slf4j;
    requires transitive java.management;
    requires transitive org.eclipse.jetty.util;
    requires static java.management.rmi;
    requires static java.rmi;
    
    exports org.eclipse.jetty.jmx;
}

Basic Usage

import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.jmx.ConnectorServer;
import org.eclipse.jetty.server.Server;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.remote.JMXServiceURL;

// Create Jetty server
Server server = new Server(8080);

// Create MBean container for registering Jetty components
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
mbeanContainer.setDomain("org.eclipse.jetty");

// Register MBean container with server to automatically register components
server.addBean(mbeanContainer);

// Set up JMX remote connector for external access
JMXServiceURL serviceURL = new JMXServiceURL("rmi", null, 1099, "/jndi/rmi://localhost:1099/jmxrmi");
ConnectorServer connectorServer = new ConnectorServer(serviceURL, "org.eclipse.jetty:name=rmiconnectorserver");
server.addBean(connectorServer);

// Start server (this will automatically register MBeans and start JMX connector)
server.start();

// JMX is now available at: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi

Architecture

The jetty-jmx module provides three key components that work together:

  • MBeanContainer: Core component that automatically discovers and registers Jetty components as MBeans, implementing Container.InheritedListener for automatic component lifecycle tracking
  • ConnectorServer: Lifecycle wrapper for JMXConnectorServer providing remote JMX access with SSL support and RMI registry management
  • ObjectMBean: Dynamic MBean wrapper that exposes arbitrary Java objects through JMX using reflection and annotation-based metadata discovery

This architecture enables seamless integration with existing JMX monitoring tools and provides enterprise-grade management capabilities with minimal configuration overhead.

Capabilities

MBean Container Management

Core container for managing MBean registration and lifecycle, providing automatic discovery and registration of Jetty components through Container.InheritedListener interface.

@ManagedObject("The component that registers beans as MBeans")
public class MBeanContainer implements Container.InheritedListener, Dumpable, Destroyable {
    // Constructors
    public MBeanContainer(MBeanServer server);
    public MBeanContainer(MBeanServer server, boolean cacheOtherClassLoaders);
    
    // Core MBean server access
    public MBeanServer getMBeanServer();
    
    // Configuration methods
    @ManagedAttribute(value = "Whether to use the cache for MBeans loaded by other ClassLoaders", readonly = true)
    public boolean isUseCacheForOtherClassLoaders();
    public void setDomain(String domain);
    @ManagedAttribute("The default ObjectName domain")
    public String getDomain();
    
    // MBean creation and lookup
    public Object mbeanFor(Object o);
    public ObjectName findMBean(Object object);
    public Object findBean(ObjectName objectName);
    public String makeName(String basis);
    
    // Container.InheritedListener implementation
    @Override
    public void beanAdded(Container parent, Object obj);
    @Override
    public void beanRemoved(Container parent, Object obj);
    
    // Dumpable implementation
    @Override
    public void dump(Appendable out, String indent) throws IOException;
    @Override
    public String dump();
    
    // Destroyable implementation
    @Override
    public void destroy();
}

JMX Connector Server

LifeCycle wrapper for JMXConnectorServer providing remote JMX connectivity with SSL/TLS support and automatic RMI registry management.

public class ConnectorServer extends AbstractLifeCycle {
    // Constants
    public static final String RMI_REGISTRY_CLIENT_SOCKET_FACTORY_ATTRIBUTE = "com.sun.jndi.rmi.factory.socket";
    
    // Constructors
    public ConnectorServer(JMXServiceURL serviceURL, String objectName);
    public ConnectorServer(JMXServiceURL serviceURL, Map<String, ?> environment, String objectName);
    public ConnectorServer(JMXServiceURL serviceURL, Map<String, ?> environment, String objectName, SslContextFactory.Server sslContextFactory);
    
    // Configuration and access methods
    public JMXServiceURL getAddress();
    public void putAttribute(String name, Object value);
    public String getObjectName();
    public void setObjectName(String objectName);
    public SslContextFactory.Server getSslContextFactory();
    public void setSslContextFactory(SslContextFactory.Server sslContextFactory);
    
    // AbstractLifeCycle overrides
    @Override
    protected void doStart() throws Exception;
    @Override
    protected void doStop() throws Exception;
}

Dynamic MBean Wrapper

Dynamic MBean implementation that wraps arbitrary Java objects, exposing their methods and properties through JMX using reflection and JMX annotations.

public class ObjectMBean implements DynamicMBean {
    // Constructor
    public ObjectMBean(Object managedObject);
    
    // Managed object access
    public Object getManagedObject();
    
    // ObjectName customization hooks
    public ObjectName getObjectName();
    public String getObjectContextBasis();
    public String getObjectNameBasis();
    
    // Container access
    public MBeanContainer getMBeanContainer();
    protected void setMBeanContainer(MBeanContainer container);
    
    // DynamicMBean interface implementation
    @Override
    public MBeanInfo getMBeanInfo();
    @Override
    public Object getAttribute(String name) throws AttributeNotFoundException, ReflectionException, MBeanException;
    @Override
    public AttributeList getAttributes(String[] names);
    @Override
    public void setAttribute(Attribute attribute) throws AttributeNotFoundException, ReflectionException, MBeanException;
    @Override
    public AttributeList setAttributes(AttributeList attributes);
    @Override
    public Object invoke(String name, Object[] params, String[] signature) throws ReflectionException, MBeanException;
}

Types

// Standard JMX types from java.management
interface MBeanServer extends javax.management.MBeanServerConnection;
interface DynamicMBean;
class ObjectName implements java.io.Serializable;
class MBeanInfo implements java.io.Serializable;
class AttributeList extends java.util.ArrayList<Object>;
class Attribute implements java.io.Serializable;
class AttributeNotFoundException extends OperationsException;
class ReflectionException extends JMException;
class MBeanException extends JMException;

// Jetty component framework types from org.eclipse.jetty.util.component
interface Container;
interface Container.InheritedListener {
    void beanAdded(Container parent, Object child);
    void beanRemoved(Container parent, Object child);
}
abstract class AbstractLifeCycle implements LifeCycle;
interface Dumpable {
    void dump(Appendable out, String indent) throws java.io.IOException;
    String dump();
}
interface Destroyable {
    void destroy();
}

// JMX connectivity types from java.management.remote
class JMXServiceURL implements java.io.Serializable;
class JMXConnectorServer implements JMXConnector;

// SSL support from org.eclipse.jetty.util.ssl  
class SslContextFactory.Server extends SslContextFactory;

// Jetty annotation types from org.eclipse.jetty.util.annotation
@interface ManagedObject {
    String value() default "";
}
@interface ManagedAttribute {
    String value() default "";
    String name() default "";
    boolean readonly() default false;
    boolean proxied() default false;
    String setter() default "";
}

Usage Examples

Setting up MBean Container with Custom Domain

MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
mbeanContainer.setDomain("com.example.jetty");

// Add to server - this automatically registers all Jetty components
server.addBean(mbeanContainer);

Creating Custom MBeans

// Wrap any object as an MBean
MyCustomComponent component = new MyCustomComponent();
Object mbean = mbeanContainer.mbeanFor(component);

// Find registered MBeans
ObjectName objectName = mbeanContainer.findMBean(component);
Object retrievedBean = mbeanContainer.findBean(objectName);

Setting up Remote JMX Access with SSL

// Create SSL context factory
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath("/path/to/keystore.jks");
sslContextFactory.setKeyStorePassword("password");

// Create secure JMX connector
JMXServiceURL serviceURL = new JMXServiceURL("rmi", null, 1099, "/jndi/rmi://localhost:1099/jmxrmi");
Map<String, Object> environment = new HashMap<>();
ConnectorServer connectorServer = new ConnectorServer(serviceURL, environment, "org.eclipse.jetty:name=rmiconnectorserver", sslContextFactory);

server.addBean(connectorServer);

Working with Dynamic MBeans

// Create ObjectMBean for any object
MyComponent component = new MyComponent();
ObjectMBean objectMBean = new ObjectMBean(component);

// Access MBean metadata
MBeanInfo mbeanInfo = objectMBean.getMBeanInfo();
Object attributeValue = objectMBean.getAttribute("someProperty");

// Invoke operations
Object result = objectMBean.invoke("someMethod", new Object[]{"param"}, new String[]{"java.lang.String"});

Error Handling

The jetty-jmx module provides comprehensive error handling:

  • Registration Failures: Graceful degradation when MBean registration fails, with detailed logging
  • Connector Issues: Proper exception handling for RMI registry and JMX connector setup
  • Resource Cleanup: Automatic cleanup of registered MBeans and resources during component destruction
  • Thread Safety: Thread-safe operations with proper synchronization for concurrent access

Integration Notes

Jetty Container Integration

The MBeanContainer implements Container.InheritedListener, automatically registering and unregistering MBeans as Jetty components are added or removed from the container hierarchy.

JMX Annotations Support

ObjectMBean supports standard JMX annotations:

  • @ManagedObject - Marks classes for JMX exposure
  • @ManagedAttribute - Exposes getter/setter methods as MBean attributes
  • @ManagedOperation - Exposes methods as MBean operations

ClassLoader Handling

The module properly handles different ClassLoader contexts, with optional caching for improved performance when working with multiple ClassLoaders.