MBeanValidatorpublic final class MBeanValidator extends Object A class to validate if nothing changes, it would be possible to register given custom MBean
in a JMX MBeanServer. It is used to decide, with a reasonable confidence, whether
the MBean would be registration-capable when time comes to actually register it.
This is to ensure (statically) that at the runtime, there are no unforeseen problems with
the registration. If this class indicates that an MBean could be registered, it should
imply that the MBean that user is trying to create is good . This approach is
selected to avoid any duplication of work in validating an MBean. A JMX
MBeanServer is the best judge to decide if an MBean implementation class and its management
interface is something that can be an MBean. In other words, it is simulating the actual
MBean registration by doing a dummy registration with all the bells and whistles. It is important
the the callers of this class carefully destroy the instance of this class. For a given MBean it
always makes sense to create an instance of this class, try registration, unregistration and then
cleanup serially. |
Fields Summary |
---|
private final MBeanServer | mbs |
Constructors Summary |
---|
public MBeanValidator()Creates a new instance of MBeanValidator
mbs = MBeanServerFactory.newMBeanServer();
|
Methods Summary |
---|
public static javax.management.ObjectName | formDefaultObjectName(java.util.Map params)
final String domain = CustomMBeanConstants.CUSTOM_MBEAN_DOMAIN;
//form the mandatory class-name property, can be safely assumed to be available here.
final Map<String, String> onProperties = new HashMap<String, String> ();
if (params.containsKey(CustomMBeanConstants.IMPL_CLASS_NAME_KEY))
onProperties.put(CustomMBeanConstants.IMPL_CLASS_NAME_KEY, params.get(CustomMBeanConstants.IMPL_CLASS_NAME_KEY));
if (params.containsKey(CustomMBeanConstants.NAME_KEY))
onProperties.put(CustomMBeanConstants.NAME_KEY, params.get(CustomMBeanConstants.NAME_KEY));
final ObjectName on = new ObjectName(domain, new Hashtable<String, String>(onProperties));
return ( on );
| private static com.sun.enterprise.config.serverbeans.ElementProperty[] | map2Properties(java.util.Map attributes)
final ElementProperty[] props = new ElementProperty[attributes.size()];
int i = 0;
for (String n : attributes.keySet()) {
final ElementProperty prop = new ElementProperty();
prop.setName(n);
prop.setValue(attributes.get(n));
props[i] = prop;
i++;
}
return ( props ) ;
| public javax.management.ObjectName | registerTestMBean(java.util.Map params, java.util.Map attributes)
try {
CustomMBeanRegistration cmr = new CustomMBeanRegistrationImpl(mbs);
final Mbean m = toMbean(params, attributes, true);
final ObjectName ron = cmr.registerMBean(m);
return ( ron );
} catch (final Exception e) {
throw new RuntimeException(e);
}
| public static final com.sun.enterprise.config.serverbeans.Mbean | toMbean(java.util.Map params, java.util.Map attributes, boolean enabledNotUsed)A convenience method to create a config bean @{link Mbean} corresponding a the given
map of input parameters. It is not guaranteed that this Mbean passes validation.
final Mbean cmb = new Mbean();
final String name = params.get(CustomMBeanConstants.NAME_KEY);
final String cName = params.get(CustomMBeanConstants.IMPL_CLASS_NAME_KEY);
final String on = params.get(CustomMBeanConstants.OBJECT_NAME_KEY);
final String ot = params.get(CustomMBeanConstants.OBJECT_TYPE_KEY);
final String enabledString = params.get(CustomMBeanConstants.ENABLED_KEY);
boolean enabled = true;
if(enabledString != null)
enabled = Boolean.valueOf(enabledString);
cmb.setName(name);
cmb.setImplClassName(cName);
cmb.setObjectName(on);
cmb.setObjectType(ot);
cmb.setEnabled(enabled);
cmb.setElementProperty(map2Properties(attributes));
return ( cmb );
| public void | unregisterTestMBean(javax.management.ObjectName ron)
try {
if (mbs.isRegistered(ron))
mbs.unregisterMBean(ron);
} catch (final Exception e) {
throw new RuntimeException(e);
}
|
|