Java Reference
In-Depth Information
hostname, but as a rule of thumb, you should try to provide some meaning in
the name. That way, you will be able to look at an
ObjectName
value and possibly
understand something about its MBean.
As you can tell from figure 2.4, the domain name
does not even have to be specified. If it's left blank,
the MBean server provides a default domain name.
The same is true for the
MBeanServerFactory
class.
If you use
createMBeanServer()
without a domain
name parameter, the factory will provide you with
an
MBeanServer
with a default domain.
Right about now, you may have noticed that both
MBeanServer
objects and MBeans (through the
ObjectName
) are associated with a domain. In fact,
MBeans of a certain domain can be registered on an
MBeanServer
containing a dif-
ferent domain name. This situation is acceptable because domain names do not
impose any rules or constraints on which MBeans can be registered on an
MBean-
Server
object.
Figure 2.4 The structure of an
ObjectName
value
Key/value property list
The key/value list portion of the object name is a set of comma-separated prop-
erty values that provide the mechanism for uniquely identifying MBeans within
an MBean server. The properties do not have to be actual MBean attributes; the
only requirement is that they are unique when compared to other instances of
ObjectName
. In each
ObjectName
, you must specify at least one property value that
makes it distinct from all other
ObjectName
instances in an MBean server.
The
ObjectName
class provides three constructors that build the name
String
with various parameters. In the
HelloAgent
class, you create an
Object-
Name
as follows:
helloWorldName = new ObjectName( "HelloAgent:name=helloWorld1" );
This
ObjectName
uniquely identifies the
HelloWorld
instance by giving it an
attribute of
name
and value
helloWorld1
. If you register any other MBeans, you
cannot use this property value on its own again; instead, you'll need an addi-
tional property combined with it.
Registering object name conflicts
You can think of the registry function like a more complex
Hashtable
. You put
objects into the table and associated them with a key. The key in this case is the
ObjectName
object. To register the MBean, the
HelloAgent
class invokes the