use of javax.management.Attribute in project jackrabbit-oak by apache.
the class OakOSGiRepositoryFactory method registerMBeanServer.
/**
* Registers the Platform MBeanServer as OSGi service. This would enable
* Aries JMX Whitboard support to then register the JMX MBean which are registered as OSGi service
* to be registered against the MBean server
*/
private static void registerMBeanServer(PojoServiceRegistry registry) {
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
try {
ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
AttributeList attrs = platformMBeanServer.getAttributes(beanName, new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion", "SpecificationVendor", "ImplementationName", "ImplementationVersion", "ImplementationVendor" });
for (Object object : attrs) {
Attribute attr = (Attribute) object;
if (attr.getValue() != null) {
mbeanProps.put(attr.getName(), attr.getValue().toString());
}
}
} catch (Exception je) {
log.info("Cannot set service properties of Platform MBeanServer service, registering without", je);
}
registry.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
}
use of javax.management.Attribute in project karaf by apache.
the class LogTest method setDebugViaMBean.
@Test
public void setDebugViaMBean() throws Exception {
assertSetLevel("INFO");
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("org.apache.karaf:type=log,name=root");
Attribute attribute = new Attribute("Level", "DEBUG");
mbeanServer.setAttribute(name, attribute);
String logLevel = (String) mbeanServer.getAttribute(name, "Level");
assertEquals("DEBUG", logLevel);
}
use of javax.management.Attribute in project samza by apache.
the class TestJmxAppender method testJmxAppender.
@Test
public void testJmxAppender() throws Exception {
MBeanServerConnection mbserver = JMXConnectorFactory.connect(URL).getMBeanServerConnection();
ObjectName objectName = new ObjectName(JmxAppender.JMX_OBJECT_DOMAIN + ":type=" + JmxAppender.JMX_OBJECT_TYPE + ",name=" + JmxAppender.JMX_OBJECT_NAME);
String level = null;
MockAppender mockAppender = new MockAppender();
Logger.getRootLogger().addAppender(mockAppender);
// Check INFO is set (from log4j.xml).
level = (String) mbserver.getAttribute(objectName, "Level");
assertEquals("INFO", level);
log.info("info1");
log.debug("debug1");
// Set to debug.
mbserver.setAttribute(objectName, new Attribute("Level", "debug"));
// Check DEBUG is set.
level = (String) mbserver.getAttribute(objectName, "Level");
assertEquals("DEBUG", level);
log.info("info2");
log.debug("debug2");
List<LoggingEvent> logLines = mockAppender.getLogLines();
// Should not have debug1 because log level is info at first.
Iterator<LoggingEvent> logLineIterator = logLines.iterator();
assertEquals(3, logLines.size());
assertEquals("info1", logLineIterator.next().getMessage());
assertEquals("info2", logLineIterator.next().getMessage());
assertEquals("debug2", logLineIterator.next().getMessage());
}
use of javax.management.Attribute in project sling by apache.
the class HealthCheckMBean method getAttribute.
@Override
public Object getAttribute(final String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
// we should call getAttributes - and not vice versa to have the result
// of a single check call - and not do a check call for each attribute
final AttributeList result = this.getAttributes(new String[] { attribute });
if (result.size() == 0) {
throw new AttributeNotFoundException(attribute);
}
final Attribute attr = (Attribute) result.get(0);
return attr.getValue();
}
use of javax.management.Attribute in project intellij-community by JetBrains.
the class CpuTimings method getProcessCpuLoad.
public static double getProcessCpuLoad() {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });
if (list.isEmpty())
return Double.NaN;
Attribute att = (Attribute) list.get(0);
Double value = (Double) att.getValue();
// usually takes a couple of seconds before we get real values
if (value == -1.0)
return Double.NaN;
// returns a percentage value with 1 decimal point precision
return ((int) (value * 1000) / 10.0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations