Extending WebSphere Application Server with custom MBeans

 


Create custom JMX MBeans

You have some alternatives to select from, when creating MBeans to extend the WebSphere administrative system. One can use any existing JMX MBean from another application. One can register any MBean that you tested in a JMX MBeanServer outside of the WAS environment in a WAS process. Including Standard MBeans, Dynamic MBeans, Open MBeans, and Model MBeans.

In addition to any existing JMX MBeans, and ones that were written and tested outside of the WAS environment, you can use the special distributed extensions provided by WebSphere and create an ExtensionMBean provider, which implies that you supply an XML file that contains an MBean Descriptor based on the DTD shipped with the WAS. This descriptor tells the WebSphere system all of the attributes, operations, and notifications that your MBean supports. With this information, the WebSphere system can route remote requests to your MBean and register remote Listeners to receive your MBean event notifications.

All internal WebSphere MBeans follow the Model MBean pattern. Pure Java classes supply the real logic for management functions, and the MBeanFactory class:

  1. Reads the description of these functions from the XML MBean Descriptor
  2. Creates an instance of a ModelMBean that matches the descriptor
  3. Binds the instance to your Java classes
  4. Registers the instance with the MBeanServer running in the same process as your classes.

Your Java code now becomes callable from any WAS administrative client through the ModelMBean created and registered to represent it.

 

Register new MBeans

There are several ways to register your MBean with the MBeanServer in a WAS process. The following list describes the available options:

  • Go through the AdminService interface.

    One can call the registerMBean() method on the AdminService interface and the invocation is delegated to the underlying MBeanServer for the process, after appropriate security checks. One can obtain a reference to the AdminService using the getAdminService() method of the AdminServiceFactory class.

  • Get MBeanServer instances directly.

    One can get a direct reference to the JMX MBeanServer instance running in any WAS process, by calling the getMBeanServer() method of the MBeanFactory class. You get a reference to the MBeanFactory class by calling the getMBeanFactory() method of the AdminService interface. Registering the MBean directly with the MBeanServer instance can result in that MBean not participating fully in the distributed features of the WAS administrative system.

  • Go through the MBeanFactory class.

    If you want the greatest possible integration with the WAS system, then use the MBeanFactory class to manage the life cycle of your MBean through the activateMBean and deactivateMBean methods of the MBeanFactory class. Use these methods, by supplying a subclass of the RuntimeCollaborator abstract superclass and an XML MBean descriptor file. Using this approach, you supply a pure Java class that implements the management interface defined in the MBean descriptor. The MBeanFactory class creates the actual ModelMBean and registers it with the WAS administrative system on your behalf.

  • Use the JMXManageable and CustomService interface.

    One can make the process of integrating with WebSphere administration even easier, by implementing a CustomService interface, that also implements the JMXManageable interface. Using this approach, you can avoid supplying the RuntimeCollaborator. When your CustomService interface is initialized, the WebSphere MBeanFactory class reads your XML MBean descriptor file and creates, binds, and registers an MBean to your CustomService interface automatically. After the shutdown method of your CustomService is called, the WAS system automatically deactivates your MBean.

 


Security

Regardless of the approach used to create and register your MBean, set up proper Java 2 security permissions for your new MBean code. The WebSphere AdminService and MBeanServer are tightly protected using Java 2 security permissions and if you do not explicitly grant your code base permissions, security exceptions are thrown when you attempt to invoke methods of these classes. If you are supplying your MBean as part of your application, you can set the permissions in the was.policy file that you supply as part of your application metadata. If you are using a CustomService interface or other code that is not delivered as an application, you can edit the library.policy file in the node configuration, or even the server.policy file in the properties directory for a specific installation.


Java 2 security permissions

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.