use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method objectInstancesFromFilteredNamedObjects.
/**
* Applies the specified queries to the set of NamedObjects.
*/
private Set<ObjectInstance> objectInstancesFromFilteredNamedObjects(Set<NamedObject> list, QueryExp query) {
Set<ObjectInstance> result = new HashSet<ObjectInstance>();
// No query ...
if (query == null) {
for (NamedObject no : list) {
final DynamicMBean obj = no.getObject();
final String className = safeGetClassName(obj);
result.add(new ObjectInstance(no.getName(), className));
}
} else {
// Access the filter
MBeanServer oldServer = QueryEval.getMBeanServer();
query.setMBeanServer(server);
try {
for (NamedObject no : list) {
final DynamicMBean obj = no.getObject();
boolean res;
try {
res = query.apply(no.getName());
} catch (Exception e) {
res = false;
}
if (res) {
String className = safeGetClassName(obj);
result.add(new ObjectInstance(no.getName(), className));
}
}
} finally {
/*
* query.setMBeanServer is probably
* QueryEval.setMBeanServer so put back the old
* value. Since that method uses a ThreadLocal
* variable, this code is only needed for the
* unusual case where the user creates a custom
* QueryExp that calls a nested query on another
* MBeanServer.
*/
query.setMBeanServer(oldServer);
}
}
return result;
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class ScanManager method register.
/**
* Create and register a new singleton instance of the ScanManager
* MBean in the given {@link MBeanServerConnection}.
* @param mbs The MBeanServer in which the new singleton instance
* should be created.
* @throws JMException The MBeanServer connection raised an exception
* while trying to instantiate and register the singleton MBean
* instance.
* @throws IOException There was a connection problem while trying to
* communicate with the underlying MBeanServer.
* @return A proxy for the registered MBean.
**/
public static ScanManagerMXBean register(MBeanServerConnection mbs) throws IOException, JMException {
final ObjectInstance moi = mbs.createMBean(ScanManager.class.getName(), SCAN_MANAGER_NAME);
final ScanManagerMXBean proxy = JMX.newMXBeanProxy(mbs, moi.getObjectName(), ScanManagerMXBean.class, true);
return proxy;
}
use of javax.management.ObjectInstance in project hbase by apache.
the class TestStochasticBalancerJmxMetrics method readJmxMetrics.
/**
* Read the attributes from Hadoop->HBase->Master->Balancer in JMX
* @throws IOException
*/
private Set<String> readJmxMetrics() throws IOException {
JMXConnector connector = null;
ObjectName target = null;
MBeanServerConnection mb = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
mb = connector.getMBeanServerConnection();
Hashtable<String, String> pairs = new Hashtable<>();
pairs.put("service", "HBase");
pairs.put("name", "Master");
pairs.put("sub", "Balancer");
target = new ObjectName("Hadoop", pairs);
MBeanInfo beanInfo = mb.getMBeanInfo(target);
Set<String> existingAttrs = new HashSet<>();
for (MBeanAttributeInfo attrInfo : beanInfo.getAttributes()) {
existingAttrs.add(attrInfo.getName());
}
return existingAttrs;
} catch (Exception e) {
LOG.warn("Failed to get bean!!! " + target, e);
if (mb != null) {
Set<ObjectInstance> instances = mb.queryMBeans(null, null);
Iterator<ObjectInstance> iterator = instances.iterator();
System.out.println("MBean Found:");
while (iterator.hasNext()) {
ObjectInstance instance = iterator.next();
System.out.println("Class Name: " + instance.getClassName());
System.out.println("Object Name: " + instance.getObjectName());
}
}
} finally {
if (connector != null) {
try {
connector.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return null;
}
use of javax.management.ObjectInstance in project tomcat by apache.
the class StatusManagerServlet method init.
// --------------------------------------------------------- Public Methods
/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
// Retrieve the MBean server
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
try {
// Query protocol handlers
String onStr = "*:type=ProtocolHandler,*";
ObjectName objectName = new ObjectName(onStr);
Set<ObjectInstance> set = mBeanServer.queryMBeans(objectName, null);
Iterator<ObjectInstance> iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
protocolHandlers.addElement(oi.getObjectName());
}
// Query Thread Pools
onStr = "*:type=ThreadPool,*";
objectName = new ObjectName(onStr);
set = mBeanServer.queryMBeans(objectName, null);
iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
threadPools.addElement(oi.getObjectName());
}
// Query Global Request Processors
onStr = "*:type=GlobalRequestProcessor,*";
objectName = new ObjectName(onStr);
set = mBeanServer.queryMBeans(objectName, null);
iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
globalRequestProcessors.addElement(oi.getObjectName());
}
// Query Request Processors
onStr = "*:type=RequestProcessor,*";
objectName = new ObjectName(onStr);
set = mBeanServer.queryMBeans(objectName, null);
iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
requestProcessors.addElement(oi.getObjectName());
}
// Register with MBean server
onStr = "JMImplementation:type=MBeanServerDelegate";
objectName = new ObjectName(onStr);
mBeanServer.addNotificationListener(objectName, this, null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.management.ObjectInstance in project tomcat by apache.
the class StatusTransformer method writeContext.
/**
* Write context state.
* @param writer The output writer
* @param objectName The context MBean name
* @param mBeanServer MBean server
* @param mode Mode <code>0</code> will generate HTML.
* Mode <code>1</code> will generate XML.
* @throws Exception Propagated JMX error
*/
protected static void writeContext(PrintWriter writer, ObjectName objectName, MBeanServer mBeanServer, int mode) throws Exception {
if (mode == 0) {
String webModuleName = objectName.getKeyProperty("name");
String name = webModuleName;
if (name == null) {
return;
}
String hostName = null;
String contextName = null;
if (name.startsWith("//")) {
name = name.substring(2);
}
int slash = name.indexOf('/');
if (slash != -1) {
hostName = name.substring(0, slash);
contextName = name.substring(slash);
} else {
return;
}
ObjectName queryManager = new ObjectName(objectName.getDomain() + ":type=Manager,context=" + contextName + ",host=" + hostName + ",*");
Set<ObjectName> managersON = mBeanServer.queryNames(queryManager, null);
ObjectName managerON = null;
Iterator<ObjectName> iterator2 = managersON.iterator();
while (iterator2.hasNext()) {
managerON = iterator2.next();
}
ObjectName queryJspMonitor = new ObjectName(objectName.getDomain() + ":type=JspMonitor,WebModule=" + webModuleName + ",*");
Set<ObjectName> jspMonitorONs = mBeanServer.queryNames(queryJspMonitor, null);
// Special case for the root context
if (contextName.equals("/")) {
contextName = "";
}
writer.print("<h1>");
writer.print(filter(name));
writer.print("</h1>");
writer.print("</a>");
writer.print("<p>");
Object startTime = mBeanServer.getAttribute(objectName, "startTime");
writer.print(" Start time: " + new Date(((Long) startTime).longValue()));
writer.print(" Startup time: ");
writer.print(formatTime(mBeanServer.getAttribute(objectName, "startupTime"), false));
writer.print(" TLD scan time: ");
writer.print(formatTime(mBeanServer.getAttribute(objectName, "tldScanTime"), false));
if (managerON != null) {
writeManager(writer, managerON, mBeanServer, mode);
}
if (jspMonitorONs != null) {
writeJspMonitor(writer, jspMonitorONs, mBeanServer, mode);
}
writer.print("</p>");
String onStr = objectName.getDomain() + ":j2eeType=Servlet,WebModule=" + webModuleName + ",*";
ObjectName servletObjectName = new ObjectName(onStr);
Set<ObjectInstance> set = mBeanServer.queryMBeans(servletObjectName, null);
Iterator<ObjectInstance> iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
writeWrapper(writer, oi.getObjectName(), mBeanServer, mode);
}
} else if (mode == 1) {
// for now we don't write out the context in XML
}
}
Aggregations