本文整理汇总了Java中javax.management.MBeanServerConnection.queryNames方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.queryNames方法的具体用法?Java MBeanServerConnection.queryNames怎么用?Java MBeanServerConnection.queryNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.queryNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printMBeans
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Prints all MBeans of domain java.lang.
* They are MBeans related to the JSR 174 that defines
* package java.lang.management.
*/
private static void printMBeans(MBeanServerConnection mbsc) throws Exception {
ObjectName filterName = new ObjectName("java.lang:*");
Set<ObjectName> set = mbsc.queryNames(filterName, null);
if ( set.size() == 0 ) {
throw new RuntimeException("(ERROR) No MBean found with filter "
+ filterName);
}
System.out.println("---- MBeans found in domain java.lang :");
for (Iterator<ObjectName> iter = set.iterator(); iter.hasNext(); ) {
System.out.println(iter.next().toString());
}
System.out.println("\n") ;
}
示例2: findObjectName
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Find the first MBean with given canonical name and type.
* @param mbs MBeanServerConnection to corresponding server
* @param canonicalNamePart canonical name you are looking for
* @param type given type for the object
* @return ObjectName or null (default)
*/
public static ObjectName findObjectName(final MBeanServerConnection mbs, final String canonicalNamePart, final String type){
try{
for(final ObjectName on: mbs.queryNames(null,null)){
final String fullObjectName = on.getCanonicalName();
if(fullObjectName.contains(canonicalNamePart)){ //check if the canonicalNamePart is ok
if(fullObjectName.contains(":type")){//make sure its a "valid" objectname
if(fullObjectName.split(":type")[1].contains(type)){//found your type
return on;
}
}
}
}
} catch (final IOException e) {
log.log(Level.WARNING, "IO Exception during browse for ObjectNames with canonicalNamePart and given type. \n"
+ "See Stacktrace for more Information",e);
}
return null;
}
示例3: testDataNode
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* test JMX connection to DataNode..
* @throws Exception
*/
@Test
public void testDataNode() throws Exception {
int numDatanodes = 2;
cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
cluster.waitActive();
writeFile(cluster.getFileSystem(), new Path("/test"), 2);
JMXGet jmx = new JMXGet();
String serviceName = "DataNode";
jmx.setService(serviceName);
jmx.init();
assertEquals(fileSize, Integer.parseInt(jmx.getValue("BytesWritten")));
cluster.shutdown();
MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
ObjectName query = new ObjectName("Hadoop:service=" + serviceName + ",*");
Set<ObjectName> names = mbsc.queryNames(query, null);
assertTrue("No beans should be registered for " + serviceName, names.isEmpty());
}
示例4: printAttrs
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void printAttrs(
MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
Set<ObjectName> names = mbsc1.queryNames(null, null);
for (ObjectName name : names) {
System.out.println(name + ":");
MBeanInfo mbi = mbsc1.getMBeanInfo(name);
MBeanAttributeInfo[] mbais = mbi.getAttributes();
for (MBeanAttributeInfo mbai : mbais) {
String attr = mbai.getName();
Object value;
try {
value = mbsc1.getAttribute(name, attr);
} catch (Exception e) {
if (expectX != null && expectX.isInstance(e))
value = "<" + e + ">";
else
throw e;
}
String s = " " + attr + " = " + value;
if (s.length() > 80)
s = s.substring(0, 77) + "...";
System.out.println(s);
}
}
}
示例5: dumpConnection
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData
* objects in MBean attribute values are handled.
*
* @param connection
* the server connection (or server itself)
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void dumpConnection(MBeanServerConnection connection, PrintWriter out) throws IOException
{
JmxDumpUtil.showStartBanner(out);
// Get all the object names
Set<ObjectName> objectNames = connection.queryNames(null, null);
// Sort the names (don't assume ObjectName implements Comparable in JDK 1.5)
Set<ObjectName> newObjectNames = new TreeSet<ObjectName>(new Comparator<ObjectName>()
{
public int compare(ObjectName o1, ObjectName o2)
{
return o1.toString().compareTo(o2.toString());
}
});
newObjectNames.addAll(objectNames);
objectNames = newObjectNames;
// Dump each MBean
for (ObjectName objectName : objectNames)
{
try
{
printMBeanInfo(connection, objectName, out);
}
catch (JMException e)
{
// Sometimes beans can disappear while we are examining them
}
}
}
示例6: jmxQuery
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Call Mbean server for some mbeans with same domain, attributes.
* with <em>attributebinding=true</em> you can save all attributes from all found objects
* as your ant properties
* @param jmxServerConnection
* @param qry
* @return The query result
*/
protected String jmxQuery(MBeanServerConnection jmxServerConnection,
String qry) {
String isError = null;
Set<ObjectName> names = null;
String resultproperty = getResultproperty();
try {
names = jmxServerConnection.queryNames(new ObjectName(qry), null);
if (resultproperty != null) {
setProperty(resultproperty + ".Length",Integer.toString(names.size()));
}
} catch (Exception e) {
if (isEcho())
handleErrorOutput(e.getMessage());
return "Can't query mbeans " + qry;
}
if (resultproperty != null) {
Iterator<ObjectName> it = names.iterator();
int oindex = 0;
String pname = null;
while (it.hasNext()) {
ObjectName oname = it.next();
pname = resultproperty + "." + Integer.toString(oindex) + ".";
oindex++;
setProperty(pname + "Name", oname.toString());
if (isAttributebinding()) {
bindAttributes(jmxServerConnection, resultproperty, pname, oname);
}
}
}
return isError;
}
示例7: getMemberId
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort,
final String memberName) throws Exception {
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
"service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertFalse(objectNames.isEmpty());
assertEquals(1, objectNames.size());
// final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
// memberName);
ObjectName objectName = objectNames.iterator().next();
// System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName,
// objectName);
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
} finally {
IOUtils.close(connector);
}
}
示例8: testNameNode
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* test JMX connection to NameNode..
* @throws Exception
*/
@Test
public void testNameNode() throws Exception {
int numDatanodes = 2;
cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
cluster.waitActive();
writeFile(cluster.getFileSystem(), new Path("/test1"), 2);
JMXGet jmx = new JMXGet();
String serviceName = "NameNode";
jmx.setService(serviceName);
jmx.init(); // default lists namenode mbeans only
assertTrue("error printAllValues", checkPrintAllValues(jmx));
//get some data from different source
assertEquals(numDatanodes, Integer.parseInt(
jmx.getValue("NumLiveDataNodes")));
assertGauge("CorruptBlocks", Long.parseLong(jmx.getValue("CorruptBlocks")),
getMetrics("FSNamesystem"));
assertEquals(numDatanodes, Integer.parseInt(
jmx.getValue("NumOpenConnections")));
cluster.shutdown();
MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
ObjectName query = new ObjectName("Hadoop:service=" + serviceName + ",*");
Set<ObjectName> names = mbsc.queryNames(query, null);
assertTrue("No beans should be registered for " + serviceName, names.isEmpty());
}
示例9: getMetricObjectNames
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private Set<ObjectName> getMetricObjectNames(MBeanServerConnection mbs) {
Set<ObjectName> objectNames = null;
try {
objectNames = mbs.queryNames(null, null);
} catch (IOException e) {
LOG.error("Failed to get object names", e);
}
return objectNames;
}
示例10: doGarbageCollectorMXBeanTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private final int doGarbageCollectorMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- GarbageCollectorMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName garbageName = iter.next() ;
System.out.println("-------- " + garbageName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(garbageName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t" + mbInfo);
GarbageCollectorMXBean garbage = null ;
garbage =
JMX.newMXBeanProxy(mbsc,
garbageName,
GarbageCollectorMXBean.class) ;
System.out.println("getCollectionCount\t\t"
+ garbage.getCollectionCount());
System.out.println("getCollectionTime\t\t"
+ garbage.getCollectionTime());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
示例11: doMemoryManagerMXBeanTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private final int doMemoryManagerMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- MemoryManagerMXBean") ;
try {
ObjectName filterName =
new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
+ ",*");
Set<ObjectName> onSet = mbsc.queryNames(filterName, null);
for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) {
ObjectName memoryManagerName = iter.next() ;
System.out.println("-------- " + memoryManagerName) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryManagerName);
System.out.println("getMBeanInfo\t\t" + mbInfo);
errorCount += checkNonEmpty(mbInfo);
MemoryManagerMXBean memoryManager = null;
memoryManager =
JMX.newMXBeanProxy(mbsc,
memoryManagerName,
MemoryManagerMXBean.class) ;
System.out.println("getMemoryPoolNames\t\t"
+ Arrays.deepToString(memoryManager.getMemoryPoolNames()));
System.out.println("getName\t\t"
+ memoryManager.getName());
System.out.println("isValid\t\t"
+ memoryManager.isValid());
}
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
示例12: printMBeans
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Prints all MBeans whatever the domain is.
*/
private static void printMBeans(MBeanServerConnection mbsc) throws Exception {
Set<ObjectName> set = mbsc.queryNames(null, null);
System.out.println("---- MBeans found :");
for (Iterator<ObjectName> iter = set.iterator(); iter.hasNext(); ) {
System.out.println(iter.next().toString());
}
System.out.println("\n") ;
}
示例13: jmxQuery
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Call Mbean server for some mbeans with same domain, attributes. with
* <em>attributebinding=true</em> you can save all attributes from all found
* objects as your ant properties
*
* @param jmxServerConnection
* @param qry
* @return The query result
*/
protected String jmxQuery(MBeanServerConnection jmxServerConnection, String qry) {
String isError = null;
Set<ObjectName> names = null;
String resultproperty = getResultproperty();
try {
names = jmxServerConnection.queryNames(new ObjectName(qry), null);
if (resultproperty != null) {
setProperty(resultproperty + ".Length", Integer.toString(names.size()));
}
} catch (Exception e) {
if (isEcho())
handleErrorOutput(e.getMessage());
return "Can't query mbeans " + qry;
}
if (resultproperty != null) {
Iterator<ObjectName> it = names.iterator();
int oindex = 0;
String pname = null;
while (it.hasNext()) {
ObjectName oname = it.next();
pname = resultproperty + "." + Integer.toString(oindex) + ".";
oindex++;
setProperty(pname + "Name", oname.toString());
if (isAttributebinding()) {
bindAttributes(jmxServerConnection, resultproperty, pname, oname);
}
}
}
return isError;
}
示例14: findObjectNames
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Find all MBeans with the given canonical name in it.
* Used for looking which MBeans are registered to one namespace.
* eg. java.net.xyz
* @param mbs MBeanServerConnection to corresponding server.
* @param canonicalNamePart canonical name you are looking for.
* @return ObjectName or Null
*/
public static List<ObjectName> findObjectNames(final MBeanServerConnection mbs, final String canonicalNamePart){
final List<ObjectName> names = new ArrayList<ObjectName>();
try{
for(final ObjectName on: mbs.queryNames(null,null)){
if(on.getCanonicalName().contains(canonicalNamePart))
names.add(on);
}
return names;
} catch (final IOException e) {
log.log(Level.WARNING, "IO Exception during browse for ObjectNames with canonicalNamePart. \n"
+ "See Stacktrace for more Information",e);
}
return null;
}
示例15: expandMBeanNames
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* The Configuration may contain MBean ObjectNames that are querys that need to be expanded before we can get the attributes for them.
* If a configName starts with the {@value #OBJECT_NAME_QUERY_PREFIX} then the rest of the string is interpreted as a query to be run.
* @param connection
* @param config
* @throws MalformedObjectNameException
* @throws IOException
* @return
*/
private static HashMap<String, String[]> expandMBeanNames(MBeanServerConnection connection, HashMap<String, String[]> config) throws MalformedObjectNameException, IOException {
HashMap<String, String[]> expandedConfig = new LinkedHashMap<String, String[]>(config.size());
// Expand any Query config items at the beginning
String[] configNames = config.keySet().toArray(new String[0]);
for (String configName : configNames) {
if (configName.startsWith(OBJECT_NAME_QUERY_PREFIX)) {
Set<ObjectName> realNames = connection.queryNames(new ObjectName(configName.substring(OBJECT_NAME_QUERY_PREFIX.length())), null);
if (realNames.size() > 0) {
for(ObjectName realName : realNames) {
System.err.printf("Query Found MBean %s\n", realName.getCanonicalName());
expandedConfig.put(realName.getCanonicalName(), config.get(configName));
}
}
else {
System.err.printf("Query Found zero (0) MBeans : %s\n", configName);
}
}
else {
expandedConfig.put(configName, config.get(configName));
}
}
return expandedConfig;
}