use of javax.management.StandardMBean in project derby by apache.
the class JMXManagementService method registerMBean.
/**
* Registers an MBean with the MBean server as a StandardMBean.
* Use of the StandardMBean allows the implementation details
* of Derby's mbeans to be hidden from JMX, thus only exposing
* the MBean's interface in org.apache.derby.mbeans.
*
* @param bean The MBean to wrap with a StandardMBean and register
* @param beanInterface The management interface for the MBean.
* @param keyProperties The String representation of the MBean's key properties,
* they will be added into the ObjectName with Derby's domain. Key
* type should be first with a short name for the bean, typically the
* class name without the package.
*/
public synchronized <T> Object registerMBean(final T bean, final Class<T> beanInterface, final String keyProperties) throws StandardException {
try {
final ObjectName beanName = new ObjectName(DERBY_JMX_DOMAIN + ":" + keyProperties + ",system=" + systemIdentifier);
final StandardMBean standardMBean = new StandardMBean(bean, beanInterface) {
/**
* Hide the implementation name from JMX clients
* by providing the interface name as the class
* name for the MBean. Allows the permissions
* in a policy file to be granted to the public
* MBean interfaces.
*/
protected String getClassName(MBeanInfo info) {
return beanInterface.getName();
}
};
// new StandardMBean(bean, beanInterface);
registeredMbeans.put(beanName, standardMBean);
if (mbeanServer != null)
jmxRegister(standardMBean, beanName);
return beanName;
} catch (JMException jme) {
throw StandardException.plainWrapException(jme);
}
}
use of javax.management.StandardMBean in project derby by apache.
the class JMXManagementService method boot.
/**
* Start the management service if derby.system.jmx is true.
* <P>
* Starting the service means:
* <UL>
* <LI> getting the platform MBeanServer which may require starting it
* <LI> registering a Version mbean representing the system
* </UL>
*/
public synchronized void boot(boolean create, Properties properties) throws StandardException {
registeredMbeans = new HashMap<ObjectName, StandardMBean>();
systemIdentifier = getMonitor().getUUIDFactory().createUUID().toString();
findServer();
myManagementBean = (ObjectName) registerMBean(this, ManagementMBean.class, "type=Management");
myManagementServer = mbeanServer;
registerMBean(new Version(getMonitor().getEngineVersion(), SystemPermission.ENGINE), VersionMBean.class, "type=Version,jar=derby.jar");
}
use of javax.management.StandardMBean in project jvm-breakglass by matlux.
the class MBeanRegistration method registerMBean.
private static void registerMBean(MBeanServer mbs, ObjectName objectName, NreplMBean nreplServer) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
StandardMBean mbean = new StandardMBean(nreplServer, NreplMBean.class, false);
mbs.registerMBean(mbean, objectName);
}
use of javax.management.StandardMBean 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 javax.management.StandardMBean in project tomee by apache.
the class JMXBeanCreator method create.
public <T> Object create() throws MBeanRegistrationException {
final String code = (String) properties.remove("code");
final String name = (String) properties.remove("name");
final String iface = (String) properties.remove("interface");
final String prefix = (String) properties.remove("prefix");
requireNotNull(code);
requireNotNull(name);
requireNotNull(iface);
try {
final Class<? extends T> cls = (Class<? extends T>) Class.forName(code, true, Thread.currentThread().getContextClassLoader());
final Class<T> ifaceCls = (Class<T>) Class.forName(iface, true, Thread.currentThread().getContextClassLoader());
final T instance = (T) cls.newInstance();
final StandardMBean mBean = new StandardMBean(instance, 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(instance, objectName);
return instance;
} catch (final Exception e) {
e.printStackTrace();
LOGGER.severe("Unable to register mbean " + e.getMessage());
throw new MBeanRegistrationException(e);
}
}
Aggregations