本文整理汇总了Java中javax.management.MBeanServer.queryNames方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.queryNames方法的具体用法?Java MBeanServer.queryNames怎么用?Java MBeanServer.queryNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServer
的用法示例。
在下文中一共展示了MBeanServer.queryNames方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServer
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static String getServer() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ArrayList<String> endPoints = new ArrayList<String>();
try {
Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext(); ) {
ObjectName obj = i.next();
String scheme = mbs.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
for (InetAddress addr : addresses) {
String host = addr.getHostAddress();
String ep = scheme + "://" + host + ":" + port;
endPoints.add(ep);
}
}
} catch (Exception e) {
return "";
}
if (endPoints.size() > 0) {
return endPoints.get(0);
} else {
return "";
}
}
示例2: writeDetailedState
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Write applications state.
*/
public static void writeDetailedState(PrintWriter writer,
MBeanServer mBeanServer, int mode)
throws Exception {
if (mode == 0){
ObjectName queryHosts = new ObjectName("*:j2eeType=WebModule,*");
Set hostsON = mBeanServer.queryNames(queryHosts, null);
// Webapp list
int count = 0;
Iterator iterator = hostsON.iterator();
while (iterator.hasNext()) {
ObjectName contextON = (ObjectName) iterator.next();
writer.print("<a name=\"" + (count++) + ".0\">");
writeContext(writer, contextON, mBeanServer, mode);
}
} else if (mode == 1){
// for now we don't write out the Detailed state in XML
}
}
示例3: getMemberMXBean
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Gets the MemberMXBean from the JVM Platform MBeanServer for the specified member, identified by
* name or ID in the GemFire cluster.
*
* @param memberNameId a String indicating the name or ID of the GemFire member.
* @return a proxy to the GemFire member's MemberMXBean.
* @throws IllegalStateException if no MemberMXBean could be found for GemFire member with ID or
* name.
* @throws RuntimeException wrapping the MalformedObjectNameException if the ObjectName pattern is
* malformed.
* @see #getMBeanServer()
* @see #isMemberMXBeanFound(java.util.Collection)
* @see javax.management.ObjectName
* @see javax.management.QueryExp
* @see javax.management.MBeanServer#queryNames(javax.management.ObjectName,
* javax.management.QueryExp)
* @see javax.management.JMX#newMXBeanProxy(javax.management.MBeanServerConnection,
* javax.management.ObjectName, Class)
* @see org.apache.geode.management.MemberMXBean
*/
protected MemberMXBean getMemberMXBean(final String memberNameId) {
try {
final MBeanServer connection = getMBeanServer();
final String objectNamePattern =
ManagementConstants.OBJECTNAME__PREFIX.concat("type=Member,*");
// NOTE throws a MalformedObjectNameException, but this should not happen since we constructed
// the ObjectName above
final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(memberNameId)),
Query.eq(Query.attr("Id"), Query.value(memberNameId)));
final Set<ObjectName> objectNames = connection.queryNames(objectName, query);
assertState(isMemberMXBeanFound(objectNames),
"No MemberMXBean with ObjectName (%1$s) based on Query (%2$s) was found in the Platform MBeanServer for member (%3$s)!",
objectName, query, memberNameId);
return JMX.newMXBeanProxy(connection, objectNames.iterator().next(), MemberMXBean.class);
} catch (MalformedObjectNameException e) {
throw new RuntimeException(e);
}
}
示例4: mbeanQuery
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static int mbeanQuery(MBeanServer mbs,
String name,
Set<ObjectName> expectedSet)
throws Exception {
int error = 0;
System.out.println("Test: queryNames(" + name + ")");
Set<ObjectName> returnedSet =
mbs.queryNames(ObjectName.getInstance(name), null);
System.out.println("ReturnedSet = " + new TreeSet(returnedSet));
System.out.println("ExpectedSet = " + new TreeSet(expectedSet));
if (returnedSet.equals(expectedSet)) {
System.out.println("Test passed!");
} else {
error++;
System.out.println("Test failed!");
}
return error;
}
示例5: testBug54170
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void testBug54170() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "HelloWorld", new HelloWorldServlet());
ctx.addServletMapping("/", "HelloWorld");
// Add a filter with a name that should be escaped if used in a JMX
// object name
FilterDef filterDef = new FilterDef();
filterDef.setFilterClass(AddDefaultCharsetFilter.class.getName());
filterDef.setFilterName("bug54170*");
ctx.addFilterDef(filterDef);
tomcat.start();
final MBeanServer mbeanServer =
Registry.getRegistry(null, null).getMBeanServer();
// There should be one Servlet MBean registered
Set<ObjectName> servlets = mbeanServer.queryNames(
new ObjectName("Tomcat:j2eeType=Servlet,*"), null);
Assert.assertEquals(1, servlets.size());
// There should be one Filter MBean registered
Set<ObjectName> filters = mbeanServer.queryNames(
new ObjectName("Tomcat:j2eeType=Filter,*"), null);
Assert.assertEquals(1, filters.size());
}
示例6: writeAppList
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Write applications state.
*/
public static void writeAppList(PrintWriter writer,
MBeanServer mBeanServer, int mode)
throws Exception {
if (mode == 0){
ObjectName queryHosts = new ObjectName("*:j2eeType=WebModule,*");
Set hostsON = mBeanServer.queryNames(queryHosts, null);
// Navigation menu
writer.print("<dt>Application list</dt>");
int count = 0;
Iterator iterator = hostsON.iterator();
while (iterator.hasNext()) {
writer.print("<dd>");
ObjectName contextON = (ObjectName) iterator.next();
String webModuleName = contextON.getKeyProperty("name");
if (webModuleName.startsWith("//")) {
webModuleName = webModuleName.substring(2);
}
int slash = webModuleName.indexOf("/");
if (slash == -1) {
count++;
continue;
}
writer.print("<a href=\"#" + (count++) + ".0\">");
writer.print(webModuleName);
writer.print("</a>");
writer.print("</dd>");
}
} else if (mode == 1){
// for now we don't write out the Detailed state in XML
}
}
示例7: shutdownAll
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void shutdownAll() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName objectName = new ObjectName(DOMAIN + ":*");
Set<ObjectName> entries = mbs.queryNames(objectName, null);
for (ObjectName name : entries) {
if (mbs.isRegistered(name)) {
mbs.unregisterMBean(name);
}
}
} catch (Exception e) {
logger.warn("AvalonInstanceMediator shutdownAll error", e);
}
}
示例8: destroy
import javax.management.MBeanServer; //导入方法依赖的package包/类
public void destroy() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
String quote = quote(instance.getName());
ObjectName objectName = new ObjectName(DOMAIN + ":instance=" + quote + ",*");
Set<ObjectName> entries = mbs.queryNames(objectName, null);
for (ObjectName name : entries) {
if (mbs.isRegistered(name)) {
mbs.unregisterMBean(name);
}
}
} catch (Exception e) {
logger.warn("ManagementService destroy error", e);
}
}
示例9: main
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Standalone entry point.
*
* Run the test and report to stdout.
*/
public static void main(String args[]) throws Exception {
echo(">>> Create MBeanServer");
MBeanServer server = MBeanServerFactory.newMBeanServer();
echo(">>> Default Domain: " + server.getDefaultDomain());
echo(">>> Create and register Test MBean");
Test mbean = new Test();
ObjectName name = ObjectName.getInstance(":type=Test");
server.registerMBean(mbean, name);
echo(">>> Set entered flag to false in Test MBean");
mbean.entered = false;
echo(">>> Query Names:");
Set<ObjectName> names = server.queryNames(null, null);
for (ObjectName on : names) {
echo("\t" + on.toString());
}
echo(">>> Entered flag = " + mbean.entered);
if (mbean.entered) {
echo(">>> Test FAILED!");
throw new IllegalArgumentException("getMBeanInfo got called");
} else {
echo(">>> Test PASSED!");
}
}
示例10: run
import javax.management.MBeanServer; //导入方法依赖的package包/类
public void run(TestStream ts) {
// start recording traces and trigger creation of the platform
// MBeanServer to produce some. This won't work if the platform
// MBeanServer was already initialized - so it's important to
// run this test in its own JVM.
ts.startRecording();
MBeanServer platform = ManagementFactory.getPlatformMBeanServer();
ts.stopRecording();
String printed = ts.bos.toString();
ts.bos.reset();
// Check that the Platform MBeanServer is emitting the expected
// log traces. This can be a bit fragile because debug traces
// could be changed without notice - in which case this test will
// need to be updated.
// For each registered MBean we expect to see three traces.
// If the messages logged by the MBeanServer change then these checks
// may need to be revisited.
List<String> checkTraces =
List.of("ObjectName = %s", "name = %s", "JMX.mbean.registered %s");
for (ObjectName o : platform.queryNames(ObjectName.WILDCARD, null)) {
String n = o.toString();
System.out.println("Checking log for: " + n);
for (String check : checkTraces) {
String s = String.format(check, n);
if (!printed.contains(s)) {
throw new RuntimeException("Trace not found: " + s);
}
}
}
}
示例11: doHealthCheck
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Override
protected void doHealthCheck(Builder builder) throws Exception
{
final MBeanServer server = getMBeanServer();
if (server != null)
{
final ObjectName on = new ObjectName("Q2:type=qbean,service=*");
final Set<ObjectName> names = server.queryNames(on, null);
final Stream<ObjectName> s = names.stream();
final long muxInTransitCount = getMuxInTransitCount(server, names);
final long tmInTransitCount = getTmInTransitCount(server, names);
builder.withDetail("mux.in-transit", String.valueOf(muxInTransitCount));
builder.withDetail("tm.in-transit", String.valueOf(tmInTransitCount));
builder.withDetail("in-transit", String.valueOf(Math.max(muxInTransitCount, tmInTransitCount)));
if (s.allMatch(name -> getStatus(server, name) == QBean.STARTED))
{
builder.up();
}
else if (s.anyMatch(name -> getStatus(server, name) == QBean.FAILED))
{
long cnt = s.filter(name -> getStatus(server, name) == QBean.FAILED).count();
Set<String> objs = s.filter(name -> getStatus(server, name) == QBean.FAILED)
.map(ObjectName::getCanonicalName)
.collect(Collectors.toSet());
String failedServices = StringUtils.collectionToCommaDelimitedString(objs);
builder.withDetail("failed-count", String.valueOf(cnt));
builder.withDetail("failed-services", failedServices);
builder.status("failed");
}
else if (s.allMatch(name -> getStatus(server, name) == QBean.DESTROYED))
{
builder.outOfService();
}
else if (s.allMatch(name -> getStatus(server, name) == QBean.STOPPED))
{
builder.down();
}
else
{
builder.unknown();
}
}
else
{
builder.unknown();
}
}
示例12: main
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Random rand = new Random();
// allocate a few direct buffers
int bufferCount = 5 + rand.nextInt(20);
buffers = new ArrayList<ByteBuffer>(bufferCount);
long totalCapacity = 0L;
for (int i=0; i<bufferCount; i++) {
int cap = 1024 + rand.nextInt(4096);
buffers.add( ByteBuffer.allocateDirect(cap) );
totalCapacity += cap;
}
// create a mapped buffer
Path tmpfile = Files.createTempFile("blah", null);
tmpfile.toFile().deleteOnExit();
try (FileChannel fc = FileChannel.open(tmpfile, READ, WRITE)) {
mbb = fc.map(FileChannel.MapMode.READ_WRITE, 10, 100);
bufferCount++;
totalCapacity += mbb.capacity();
}
// use platform MXBeans directly
List<BufferPoolMXBean> pools =
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
check(pools, bufferCount, totalCapacity);
// use MBeanServer
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> mbeans = server.queryNames(
new ObjectName("java.nio:type=BufferPool,*"), null);
pools = new ArrayList<BufferPoolMXBean>();
for (ObjectName name: mbeans) {
BufferPoolMXBean pool = ManagementFactory
.newPlatformMXBeanProxy(server, name.toString(), BufferPoolMXBean.class);
pools.add(pool);
}
check(pools, bufferCount, totalCapacity);
// attempt to unmap mapped buffer
WeakReference<MappedByteBuffer> ref = new WeakReference<>(mbb);
mbb = null;
do {
System.gc();
Thread.sleep(250);
} while (ref.get() != null);
}
示例13: checkStandardMBeans
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static void checkStandardMBeans(MBeanServer mbs) throws Exception {
checkMBean(mbs, CLASS_LOADING_MXBEAN_NAME);
checkMBean(mbs, MEMORY_MXBEAN_NAME);
checkMBean(mbs, OPERATING_SYSTEM_MXBEAN_NAME);
checkMBean(mbs, RUNTIME_MXBEAN_NAME);
checkMBean(mbs, THREAD_MXBEAN_NAME);
if (ManagementFactory.getCompilationMXBean() != null) {
checkMBean(mbs, COMPILATION_MXBEAN_NAME);
}
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (ListIterator iter = pools.listIterator(); iter.hasNext(); ) {
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
checkMBean(mbs, MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + p.getName());
}
// Check the number of memory pools in the mbs
Set set = mbs.queryNames(new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"), null);
if (set.size() != pools.size()) {
throw new RuntimeException("Unexpected number of memory pools:" +
"MBeanServer has " + set.size() +
". Expected = " + pools.size());
}
List mgrs = ManagementFactory.getMemoryManagerMXBeans();
int num_mgrs = 0;
for (ListIterator iter = mgrs.listIterator(); iter.hasNext(); ) {
MemoryManagerMXBean m = (MemoryManagerMXBean) iter.next();
if (m instanceof GarbageCollectorMXBean) {
checkMBean(mbs, GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",name=" + m.getName());
} else {
checkMBean(mbs, MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
+ ",name=" + m.getName());
num_mgrs++;
}
}
List gcs = ManagementFactory.getGarbageCollectorMXBeans();
for (ListIterator iter = gcs.listIterator(); iter.hasNext(); ) {
GarbageCollectorMXBean gc = (GarbageCollectorMXBean) iter.next();
checkMBean(mbs, GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
+ ",name=" + gc.getName());
}
// Check the number of memory managers and garbage collectors in the mbs
set = mbs.queryNames(new ObjectName(MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"), null);
if (set.size() != num_mgrs) {
throw new RuntimeException("Unexpected number of memory managers:" +
"MBeanServer has " + set.size() +
". Expected = " + num_mgrs);
}
set = mbs.queryNames(new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"), null);
if (set.size() != gcs.size()) {
throw new RuntimeException("Unexpected number of garbage collectors:" +
"MBeanServer has " + set.size() +
". Expected = " + gcs.size());
}
}
示例14: printMBeans
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static void printMBeans(MBeanServer mbs) throws Exception {
Set set = mbs.queryNames(null, null);
for (Iterator iter = set.iterator(); iter.hasNext(); ) {
System.out.println(iter.next());
}
}