use of org.superbiz.resource.jmx.factory.MBeanRegistrationException in project tomee by apache.
the class Alternative method postConstruct.
@PostConstruct
public <T> void postConstruct() throws MBeanRegistrationException {
final String name = properties.remove("name").toString();
final String iface = properties.remove("interface").toString();
final String prefix = properties.remove("prefix").toString();
requireNotNull(name);
requireNotNull(iface);
try {
final Class<T> ifaceCls = (Class<T>) Class.forName(iface, true, Thread.currentThread().getContextClassLoader());
final StandardMBean mBean = new StandardMBean((T) this, ifaceCls);
for (String attributeName : properties.stringPropertyNames()) {
final Object value = properties.remove(attributeName);
if (prefix != null) {
if (!attributeName.startsWith(prefix + ".")) {
continue;
} else {
attributeName = attributeName.substring(prefix.length() + 1);
}
}
final Class<?> targetType = findAttributeType(mBean.getMBeanInfo(), attributeName);
final Object targetValue = Converter.convert(value, targetType, null);
final Attribute attribute = new Attribute(attributeName, targetValue);
mBean.setAttribute(attribute);
}
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(name);
mbs.registerMBean(this, objectName);
} catch (final Exception e) {
LOGGER.severe("Unable to register mbean " + e.getMessage());
throw new MBeanRegistrationException(e);
}
}
use of org.superbiz.resource.jmx.factory.MBeanRegistrationException in project tomee by apache.
the class Alternative method preDestroy.
@PreDestroy
public void preDestroy() throws MBeanRegistrationException {
final String name = properties.getProperty("name");
requireNotNull(name);
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(name);
mbs.unregisterMBean(objectName);
} catch (final MalformedObjectNameException e) {
LOGGER.severe("Malformed MBean name: " + name);
throw new MBeanRegistrationException(e);
} catch (final javax.management.MBeanRegistrationException e) {
LOGGER.severe("Error unregistering " + name);
throw new MBeanRegistrationException(e);
} catch (InstanceNotFoundException e) {
LOGGER.severe("Error unregistering " + name);
throw new MBeanRegistrationException(e);
}
}
Aggregations