|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface ObjectNameTemplate
Annotation to allow an MBean to provide its name. This annotation can be used on the following types:
@MBean
annotation.@MXBean
annotation.The value of this annotation is used to build the ObjectName
when instances of the annotated type are registered in
an MBeanServer and no explicit name is given to the
createMBean or registerMBean method (the ObjectName
is null).
For Dynamic MBeans, which define their own MBeanInfo, you can
produce the same effect as this annotation by including a field
objectNameTemplate
in the Descriptor for the MBeanInfo returned by
DynamicMBean.getMBeanInfo().
For Standard MBeans and MXBeans, this annotation automatically produces
an objectNameTemplate field in the Descriptor.
The template can contain variables so that the name of the MBean
depends on the value of one or more of its attributes.
A variable that identifies an MBean attribute is of the form
{attribute name}. For example, to make an MBean name
depend on the Name attribute, use the variable
{Name}. Attribute names are case sensitive.
Naming attributes can be of any type. The String returned by
toString() is included in the constructed name.
If you need the attribute value to be quoted
by a call to ObjectName.quote,
surround the variable with quotes. Quoting only applies to key values.
For example, @ObjectNameTemplate("java.lang:type=MemoryPool,name=\"{Name}\""),
quotes the Name attribute value. You can notice the "\"
character needed to escape a quote within a String. A name
produced by this template might look like
java.lang:type=MemoryPool,name="Code Cache".
Variables can be used anywhere in the String.
Be sure to make the template derived name comply with
ObjectName syntax.
If an MBean is registered with a null name and it implements
MBeanRegistration, then
the computed name is provided to the preRegister method.
Similarly,
if the MBean uses resource
injection to discover its name, it is the computed name that will
be injected.
All of the above can be used with the StandardMBean class and
the annotation is effective in that case too.
If any exception occurs (such as unknown attribute, invalid syntax or
exception
thrown by the MBean) when the name is computed it is wrapped in a
NotCompliantMBeanException.
Some ObjectName template examples:
Name attribute is retrieved to compose the name
key value.InstanceName and InstanceId attributes are
retrieved to compose respectively
the name and id key values.ComplexName attribute is retrieved to compose the
name key quoted value.TypeKey attribute is retrieved to compose the
first key name.Domain attribute is retrieved to compose the
management domain.Naming attribute is retrieved to compose the
complete name.
| Modifier and Type | Required Element and Description |
|---|---|
String |
value
The MBean name template. |
| Element Detail |
|---|
@DescriptorKey(value="objectNameTemplate") public abstract String value
|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.