use of javax.management.modelmbean.ModelMBeanInfo in project kernel by exoplatform.
the class JMXManagementProvider method manage.
public Object manage(ManagedResource context) {
if (context == null) {
throw new IllegalArgumentException("The context cannot be null");
}
ExoModelMBean mbean = null;
try {
ExoMBeanInfoBuilder infoBuilder = new ExoMBeanInfoBuilder(context.getMetaData());
ModelMBeanInfo info = infoBuilder.build();
mbean = new ExoModelMBean(context, context.getResource(), info);
} catch (IllegalArgumentException e) {
LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
} catch (RuntimeOperationsException e) {
LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
} catch (InstanceNotFoundException e) {
LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
} catch (MBeanException e) {
LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
} catch (InvalidTargetObjectTypeException e) {
LOG.warn("Could not create the ExoModelMBean for the class " + context.getResource() == null ? null : context.getResource().getClass(), e);
}
//
if (mbean != null) {
ObjectName on = null;
PropertiesInfo oni = PropertiesInfo.resolve(context.getResource().getClass(), NameTemplate.class);
if (oni != null) {
try {
Map<String, String> foo = oni.resolve(context.getResource());
on = JMX.createObjectName("exo", foo);
} catch (MalformedObjectNameException e) {
LOG.warn("Could not create the ObjectName for the class " + context.getResource().getClass(), e);
}
}
if (on != null) {
// Merge with the container hierarchy context
try {
Map<String, String> props = new LinkedHashMap<String, String>();
// Merge scoping properties
List<MBeanScopingData> list = context.getScopingData(MBeanScopingData.class);
// Read in revert order because wee received list of parents in upward order
for (int i = list.size(); i > 0; i--) {
MBeanScopingData scopingData = list.get(i - 1);
props.putAll(scopingData);
}
// and a Hashtable<String, String> with Java 6.
for (Object o : on.getKeyPropertyList().entrySet()) {
Map.Entry entry = (Map.Entry) o;
String key = (String) entry.getKey();
String value = (String) entry.getValue();
props.put(key, value);
}
//
on = JMX.createObjectName(on.getDomain(), props);
//
attemptToRegister(on, mbean);
//
return on;
} catch (MalformedObjectNameException e) {
LOG.warn("Could not register the MBean for the class " + context.getResource().getClass(), e);
}
}
}
//
return null;
}
use of javax.management.modelmbean.ModelMBeanInfo in project kernel by exoplatform.
the class AbstractExoMBeanTest method register.
protected Bean register(String name, Class clazz) {
try {
ObjectName objectName = ObjectName.getInstance(name);
ModelMBeanInfo info = new ExoMBeanInfoBuilder(clazz).build();
RequiredModelMBean mbean = new RequiredModelMBean(info);
mbean.setManagedResource(clazz.newInstance(), "ObjectReference");
server.registerMBean(mbean, objectName);
return new Bean(objectName, (ModelMBeanInfo) server.getMBeanInfo(objectName));
} catch (Exception e) {
throw new AssertionError(e);
}
}
use of javax.management.modelmbean.ModelMBeanInfo in project cxf by apache.
the class RMEndpoint method initialise.
void initialise(RMConfiguration config, Conduit c, EndpointReferenceType r, org.apache.cxf.transport.Destination d, Message message) {
configuration = config;
conduit = c;
replyTo = r;
createServices();
createEndpoints(d);
setPolicies(message);
if (manager != null && manager.getBus() != null) {
managedEndpoint = new ManagedRMEndpoint(this);
instrumentationManager = manager.getBus().getExtension(InstrumentationManager.class);
if (instrumentationManager != null) {
ModelMBeanAssembler assembler = new ModelMBeanAssembler();
ModelMBeanInfo mbi = assembler.getModelMbeanInfo(managedEndpoint.getClass());
MBeanServer mbs = instrumentationManager.getMBeanServer();
if (mbs == null) {
LOG.log(Level.WARNING, "MBeanServer not available.");
} else {
try {
RequiredModelMBean rtMBean = (RequiredModelMBean) mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
rtMBean.setModelMBeanInfo(mbi);
try {
rtMBean.setManagedResource(managedEndpoint, "ObjectReference");
} catch (InvalidTargetObjectTypeException itotex) {
throw new JMException(itotex.getMessage());
}
ObjectName name = managedEndpoint.getObjectName();
instrumentationManager.register(rtMBean, name);
modelMBean = rtMBean;
} catch (JMException jmex) {
LOG.log(Level.WARNING, "Registering ManagedRMEndpoint failed.", jmex);
}
}
}
}
}
use of javax.management.modelmbean.ModelMBeanInfo in project voldemort by voldemort.
the class JmxUtils method createModelMBean.
/**
* Create a model mbean from an object using the description given in the
* Jmx annotation if present. Only operations are supported so far, no
* attributes, constructors, or notifications
*
* @param o The object to create an MBean for
* @return The ModelMBean for the given object
*/
public static ModelMBean createModelMBean(Object o) {
try {
ModelMBean mbean = new RequiredModelMBean();
JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
String description = annotation == null ? "" : annotation.description();
ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
mbean.setModelMBeanInfo(info);
mbean.setManagedResource(o, "ObjectReference");
return mbean;
} catch (MBeanException e) {
throw new VoldemortException(e);
} catch (InvalidTargetObjectTypeException e) {
throw new VoldemortException(e);
} catch (InstanceNotFoundException e) {
throw new VoldemortException(e);
}
}
use of javax.management.modelmbean.ModelMBeanInfo in project cxf by apache.
the class ModelMBeanAssemblerTest method testGetMBeanInfo.
@Test
public void testGetMBeanInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertNotNull("MBeanInfo should not be null", info);
}
Aggregations