Chapter 4. Tools

Table of Contents

Naming
Introduction
Deployment
Mailer MBean
Introduction
Configuration
Keyword expanding
Jython MBean
Introduction
Configuration
Built-in functions

Naming

Simone Bordet

Revision History
Revision $Revision: 1.1 $$Date: 2002/02/01 17:29:11 $

Introduction

The Naming MBean is an MBean that wraps the rmiregistry tool provided with the JDK.

It allows you to start the rmiregistry in the same JVM as other MBeans, such as the RMI MBean (see examples in the documentation), or the RMI adaptor.
The MBean's class is openjmx.tools.naming.NamingService.

The usage of the Naming MBean does not require additional libraries, as all the needed classes are already shipped with the JDK.

Deployment

The Naming MBean is easily deployed into a JMX Agent. The following code snippet shows how to deploy it into a JMX Agent.

Example 4.1. Deploying the Naming MBean

		
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName naming = new ObjectName("Naming:type=registry");
server.createMBean("openjmx.tools.naming.NamingService", naming, null);
		
		

To use the Naming MBean as rmiregistry, it must be started; the Naming MBean can be started and stopped at wish, simply by invoking the start() and stop() methods of the management interface.

Example 4.2. Starting and stopping the Naming MBean

		
NamingServiceMBean mbean = (NamingServiceMBean)StandardMBeanProxy.create(NamingServiceMBean.class, server, naming);
mbean.start();
...
mbean.stop();


or using the MBeanServer:


server.invoke(naming, "start", new Object[0], new String[0]);
...
server.invoke(naming, "stop", new Object[0], new String[0]);
		
		

It is also possible to specify the port on which the rmiregistry will run. Simply pass this parameter to the constructor of the Naming MBean. By default the rmiregistry runs on port 1099.

Example 4.3. Changing the default port

		
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName naming = new ObjectName("Naming:type=registry");

server.createMBean("openjmx.tools.naming.NamingService", naming, null, new Object[] {new Integer(2099)}, new String[] {"int"});


or


NamingService mbean = new NamingService(3099);
server.registerMBean(mbean, naming);


or via MLet file (specify the suitable codebase)


<MLET CODE="openjmx.tools.naming.NamingService"
      ARCHIVE="openjmx-tools.jar"
      CODEBASE="../lib/">
	<ARG TYPE="int" VALUE="4099">
</MLET>
		
		

It is also possible to change the rmiregistry port at runtime. Just start the Naming MBean, stop it after a while, change the port it runs on, and restarting it, so that it will accept requests on the new port.
Below you can see the steps needed to perform this change.

Example 4.4. Changing the port at runtime

		
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName naming = new ObjectName("Naming:type=registry");
server.createMBean("openjmx.tools.naming.NamingService", naming, null);
NamingServiceMBean mbean = (NamingServiceMBean)StandardMBeanProxy.create(NamingServiceMBean.class, server, naming);

mbean.start();
...
mbean.stop();
mbean.setPort(5099);
mbean.start();