/* * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ package javax.management; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation to allow an MBean to provide its name. * This annotation can be used on the following types: *
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
* {@code createMBean} or {@code registerMBean} method (the {@code ObjectName}
* is {@code null}).
For Dynamic MBeans, which define their own {@code MBeanInfo}, you can * produce the same effect as this annotation by including a field * {@code objectNameTemplate} * in the {@link Descriptor} for the {@code MBeanInfo} returned by * {@link DynamicMBean#getMBeanInfo()}.
* *For Standard MBeans and MXBeans, this annotation automatically produces * an {@code objectNameTemplate} field in the {@code 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 {@link ObjectName#quote(String) 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
* {@code 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
* {@link ObjectName ObjectName} syntax.
If an MBean is registered with a null name and it implements
* {@link javax.management.MBeanRegistration 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 {@link 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.