So far, we have talked only about the instrumentation level of the
JMX architecture. In this chapter, we will take a close look at the
core of the JMX architecture, the agent level. This chapter is for
those developers who want a deeper understanding of the JMX agent
level, are responsible for developing protocol adaptors and
connectors, or need to interact with a local
MBeanServer
instance.
First, we will take a quick look at the MBean
server’s role in the JMX agent level, how it is
implemented in the RI, how to get a reference to it, and what you can
do with that reference once you have it. Next, we will take a closer
look at the MBeanServerFactory
class and its
various methods for obtaining references to the MBean server. Then we
will look at the MBeanServer
interface, which is
how MBeans, JMX agents, and management applications interact with the
MBean server. In this section, we will also explore how to register
and unregister MBeans, how to use the MBean server to interact with
an MBean through its ObjectName
, how to register
interest in notifications, and how to query the MBean server to
return a subset of registered MBeans. This section will be followed
by a discussion of the MBeanRegistration
interface, which gives the instrumentation developer a means of
control over an MBean’s
ObjectName
, as well as exit points for additional
processing before and after the MBean is registered and deregistered.
The chapter will conclude with a look at
MBeanServerDelegate
, a class required by all
JMX-compliant implementations to provide metadata about that
particular JMX implementation.
The MBean server is at the
heart of the agent level of the JMX architecture. The primary
function of the MBean server is to act as a
registry for MBeans. It is through the MBean
server that MBeans, other parts of the JMX agent, and management
applications gain access to the MBeans that are
registered with the MBean server. Every
MBean must be registered with the MBean server in order to be
managed. This is achieved by first obtaining a reference to the MBean
server (we’ll see how to do that later in this
chapter) and then invoking the appropriate method of the
MBeanServer
interface. We will discuss the
MBeanServer
interface in more detail later in this
chapter.
A secondary function of the MBean server is to act as an intermediary to allow other JMX agents, management applications, and MBeans to monitor and manage MBeans without having a reference to the MBean object. As long as the object name of the MBean is known and the MBean is registered, an MBean can be indirectly manipulated through the MBean server in which the MBean is registered.
In the RI provided with the final release of the JMX 1.0
specification, the MBeanServer
interface is fully
implemented in a class called
MBeanServerImpl
, located in the
com.sun.management.jmx
package. If you are using
the RI and are curious about the internals of the MBean server
implementation, I encourage you to look at the source code for this
class.
As mentioned earlier, before an MBean can be registered with the
MBean server, a reference to the MBean server must be obtained. This
is achieved through
MBeanServerFactory
, a class located in the
javax.management
package that must be shipped with
every compliant JMX implementation. This class contains static
methods that allow you to create an instance of an MBean server and
find an instance of an MBean server that has already been created.
Each of the methods of the MBeanServerFactory
class will be discussed later in this chapter.
The MBean server implementation class
(MBeanServerImpl
, in the JMX 1.0 RI) should never
be instantiated directly! You should always use the static methods of
MBeanServerFactory
to obtain a reference to an
MBean server. In addition, once you obtain a reference to an MBean
server, you should never cast it to an
MBeanServerImpl
, even though this would work when
using the RI. You should always work with the MBean server through
the MBeanServer
interface.
We will look at the MBeanServer
interface in more
detail later in this chapter. Once you have a reference to an MBean
server, you can:
Register and deregister MBeans.
Register interest in MBean and MBean server notifications.
Manipulate MBeans by getting and setting their attribute values and invoking their management operations.
Query the MBean server to return subsets of the MBeans that are registered within it.
We will look at each of these actions in detail in the sections that follow.