当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServer.invoke方法代码示例

本文整理汇总了Java中javax.management.MBeanServer.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.invoke方法的具体用法?Java MBeanServer.invoke怎么用?Java MBeanServer.invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServer的用法示例。


在下文中一共展示了MBeanServer.invoke方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRMIRegistry

import javax.management.MBeanServer; //导入方法依赖的package包/类
private void createRMIRegistry() throws Exception {
  if (!this.agentConfig.isRmiRegistryEnabled()) {
    return;
  }
  MBeanServer mbs = getMBeanServer();
  String host = this.agentConfig.getRmiBindAddress();
  int port = this.agentConfig.getRmiPort();

  /*
   * Register and start the rmi-registry naming MBean, which is needed by JSR 160
   * RMIConnectorServer
   */
  ObjectName registryName = getRMIRegistryNamingName();
  try {
    RMIRegistryService registryNamingService = null;
    if (host != null && !("".equals(host.trim()))) {
      registryNamingService = new RMIRegistryService(host, port);
    } else {
      registryNamingService = new RMIRegistryService(port);
    }
    mbs.registerMBean(registryNamingService, registryName);
  } catch (javax.management.InstanceAlreadyExistsException e) {
    logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_0__IS_ALREADY_REGISTERED,
        registryName));
  }
  mbs.invoke(registryName, "start", null, null);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:28,代码来源:AgentImpl.java

示例2: invoke

import javax.management.MBeanServer; //导入方法依赖的package包/类
private Object invoke(String objectName, String method, Object[] params, String[] types) throws Exception {
    MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
    ObjectName mbean = new ObjectName(objectName);

    if (server == null) {
        throw new Exception("Can't find mbean server");
    }

    getLog().info("invoking " + method);
    return server.invoke(mbean, method, params, types);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:12,代码来源:JMXInvokerJob.java

示例3: timeNotif

import javax.management.MBeanServer; //导入方法依赖的package包/类
private static final long timeNotif(MBeanServer mbs) {
    try {
        startTime = System.nanoTime();
        nnotifs = 0;
        mbs.invoke(testObjectName, "send", null, null);
        sema.acquire();
        return elapsed;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ListenerScaleTest.java

示例4: writeWrapper

import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
 * Write detailed information about a wrapper.
 */
public static void writeWrapper(PrintWriter writer, ObjectName objectName,
                                MBeanServer mBeanServer, int mode)
    throws Exception {

    if (mode == 0) {
        String servletName = objectName.getKeyProperty("name");
        
        String[] mappings = (String[]) 
            mBeanServer.invoke(objectName, "findMappings", null, null);
        
        writer.print("<h2>");
        writer.print(filter(servletName));
        if ((mappings != null) && (mappings.length > 0)) {
            writer.print(" [ ");
            for (int i = 0; i < mappings.length; i++) {
                writer.print(filter(mappings[i]));
                if (i < mappings.length - 1) {
                    writer.print(" , ");
                }
            }
            writer.print(" ] ");
        }
        writer.print("</h2>");
        
        writer.print("<p>");
        writer.print(" Processing time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "processingTime"), true));
        writer.print(" Max time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "maxTime"), false));
        writer.print(" Request count: ");
        writer.print(mBeanServer.getAttribute(objectName, "requestCount"));
        writer.print(" Error count: ");
        writer.print(mBeanServer.getAttribute(objectName, "errorCount"));
        writer.print(" Load time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "loadTime"), false));
        writer.print(" Classloading time: ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "classLoadTime"), false));
        writer.print("</p>");
    } else if (mode == 1){
        // for now we don't write out the wrapper details
    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:51,代码来源:StatusTransformer.java

示例5: writeWrapper

import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
 * Write detailed information about a wrapper.
 */
public static void writeWrapper(PrintWriter writer, ObjectName objectName,
                                MBeanServer mBeanServer, int mode)
    throws Exception {

    if (mode == 0) {
        String servletName = objectName.getKeyProperty("name");
        
        String[] mappings = (String[]) 
            mBeanServer.invoke(objectName, "findMappings", null, null);
        
        writer.print("<h2>");
        writer.print(servletName);
        if ((mappings != null) && (mappings.length > 0)) {
            writer.print(" [ ");
            for (int i = 0; i < mappings.length; i++) {
                writer.print(mappings[i]);
                if (i < mappings.length - 1) {
                    writer.print(" , ");
                }
            }
            writer.print(" ] ");
        }
        writer.print("</h2>");
        
        writer.print("<p>");
        writer.print(" <strong>Processing time:</strong> ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "processingTime"), true));
        writer.print(" <br><strong>Max time:</strong> ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "maxTime"), false));
        writer.print(" <br><strong>Request count:</strong> ");
        writer.print(mBeanServer.getAttribute(objectName, "requestCount"));
        writer.print(" <br><strong>Error count:</strong> ");
        writer.print(mBeanServer.getAttribute(objectName, "errorCount"));
        writer.print(" <br><strong>Load time:</strong> ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "loadTime"), false));
        writer.print(" <br><strong>Classloading time:</strong> ");
        writer.print(formatTime(mBeanServer.getAttribute
                                (objectName, "classLoadTime"), false));
        writer.print("</p>");
    } else if (mode == 1){
        // for now we don't write out the wrapper details
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:51,代码来源:StatusTransformer.java

示例6: main

import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName pointName = new ObjectName("a:type=Point");
    PointMXBean pointmx = new PointImpl();
    mbs.registerMBean(pointmx, pointName);
    Point point = new Point(1, 2);
    PointMXBean pointproxy =
        JMX.newMXBeanProxy(mbs, pointName, PointMXBean.class);
    Point point1 = pointproxy.identity(point);
    if (point1.getX() != point.getX() || point1.getY() != point.getY())
        throw new Exception("Point doesn't match");
    System.out.println("Point test passed");

    ObjectName evolveName = new ObjectName("a:type=Evolve");
    EvolveMXBean evolvemx = new EvolveImpl();
    mbs.registerMBean(evolvemx, evolveName);
    Evolve evolve =
        new Evolve(59, "tralala", Collections.singletonList("tiddly"));
    EvolveMXBean evolveProxy =
        JMX.newMXBeanProxy(mbs, evolveName, EvolveMXBean.class);
    Evolve evolve1 = evolveProxy.identity(evolve);
    if (evolve1.getOldInt() != evolve.getOldInt()
            || !evolve1.getNewString().equals(evolve.getNewString())
            || !evolve1.getNewerList().equals(evolve.getNewerList()))
        throw new Exception("Evolve doesn't match");
    System.out.println("Evolve test passed");

    ObjectName evolvedName = new ObjectName("a:type=Evolved");
    EvolveMXBean evolvedmx = new EvolveImpl();
    mbs.registerMBean(evolvedmx, evolvedName);
    CompositeType evolvedType =
        new CompositeType("Evolved", "descr", new String[] {"oldInt"},
                          new String[] {"oldInt descr"},
                          new OpenType[] {SimpleType.INTEGER});
    CompositeData evolvedData =
        new CompositeDataSupport(evolvedType, new String[] {"oldInt"},
                                 new Object[] {5});
    CompositeData evolved1 = (CompositeData)
        mbs.invoke(evolvedName, "identity", new Object[] {evolvedData},
                   new String[] {CompositeData.class.getName()});
    if ((Integer) evolved1.get("oldInt") != 5
            || !evolved1.get("newString").equals("defaultString")
            || ((String[]) evolved1.get("newerList")).length != 0)
        throw new Exception("Evolved doesn't match: " + evolved1);
    System.out.println("Evolved test passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:PropertyNamesTest.java

示例7: main

import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:60,代码来源:NotifReconnectDeadlockTest.java

示例8: dumpOperation

import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void dumpOperation() throws Exception {
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));

    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);

    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);

    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    final MBeanOperationInfo[] arr = info.getOperations();
    assertEquals("Currently three overloads", 3, arr.length);
    MBeanOperationInfo dumpOp = null;
    for (int i = 0; i < arr.length; i++) {
        assertEquals("dumpMethod", arr[i].getName());
        if (arr[i].getSignature().length == 3) {
            dumpOp = arr[i];
        }
    }
    assertNotNull("three args variant found", dumpOp);

    server.invoke(name, "dumpMethod", new Object[]{
                    "java.util.Arrays", "asList", ":3"
    }, null);

    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), "");
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals("", after);

    OptionValues empty = new OptionValues(EconomicMap.create());
    OptionValues unsetDump = realBean.optionsFor(empty, null);
    final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
    final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
    assertNotSame(unsetDump, forMethod);
    Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", nothing);

    Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
    assertEquals(":3", specialValue);

    OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
    Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", noSpecialValue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:HotSpotGraalMBeanTest.java

示例9: writeWrapper

import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
 * Write detailed information about a wrapper.
 */
public static void writeWrapper(PrintWriter writer, ObjectName objectName, MBeanServer mBeanServer, int mode)
		throws Exception {

	if (mode == 0) {
		String servletName = objectName.getKeyProperty("name");

		String[] mappings = (String[]) mBeanServer.invoke(objectName, "findMappings", null, null);

		writer.print("<h2>");
		writer.print(filter(servletName));
		if ((mappings != null) && (mappings.length > 0)) {
			writer.print(" [ ");
			for (int i = 0; i < mappings.length; i++) {
				writer.print(filter(mappings[i]));
				if (i < mappings.length - 1) {
					writer.print(" , ");
				}
			}
			writer.print(" ] ");
		}
		writer.print("</h2>");

		writer.print("<p>");
		writer.print(" Processing time: ");
		writer.print(formatTime(mBeanServer.getAttribute(objectName, "processingTime"), true));
		writer.print(" Max time: ");
		writer.print(formatTime(mBeanServer.getAttribute(objectName, "maxTime"), false));
		writer.print(" Request count: ");
		writer.print(mBeanServer.getAttribute(objectName, "requestCount"));
		writer.print(" Error count: ");
		writer.print(mBeanServer.getAttribute(objectName, "errorCount"));
		writer.print(" Load time: ");
		writer.print(formatTime(mBeanServer.getAttribute(objectName, "loadTime"), false));
		writer.print(" Classloading time: ");
		writer.print(formatTime(mBeanServer.getAttribute(objectName, "classLoadTime"), false));
		writer.print("</p>");
	} else if (mode == 1) {
		// for now we don't write out the wrapper details
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:45,代码来源:StatusTransformer.java


注:本文中的javax.management.MBeanServer.invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。