java类javax.management.JMX的实例源码

StreamsInstanceTracker.java 文件源码 项目:streamsx.jmxclients 阅读 27 收藏 0 点赞 0 评论 0
private synchronized void addJobToMap(BigInteger jobid) {
      InstanceMXBean instance = null;
      LOGGER.debug("AddJobToMap({})...", jobid);
      StopWatch sw = new StopWatch();
      sw.start();

      try {
          instance = this.jmxContext
                  .getBeanSourceProvider()
                  .getBeanSource()
                  .getInstanceBean(domainName,
                          this.instanceInfo.getInstanceName());

          ObjectName tJobNameObj = instance.registerJob(jobid);

          JobMXBean jobBean = JMX.newMXBeanProxy(jmxContext
                  .getBeanSourceProvider().getBeanSource()
                  .getMBeanServerConnection(), tJobNameObj, JobMXBean.class,
                  true);
          jobMap.addJobToMap(jobid, new JobDetails(this, jobid, jobBean));

      } catch (IOException e) {
          LOGGER.warn("New Job Initialization received IO Exception from JMX Connection Pool.  Resetting monitor.  Exception Message: "
                  + e.getLocalizedMessage());
          resetTracker();
      }

      sw.stop();
      LOGGER.debug("** addJobToMap (jobid: " + jobid + ") time: "
              + sw.getTime());

metricsExporter.getStreamsMetric("jobCount", StreamsObjectType.INSTANCE, this.domainName, this.instanceInfo.getInstanceName()).set(jobMap.size());

  }
JmxPasswordTest.java 文件源码 项目:tomcat7 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testPassword() throws Exception {
    Assert.assertEquals("Passwords should match when not using JMX.",password,datasource.getPoolProperties().getPassword());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ConnectionPoolMBean mbean = JMX.newMBeanProxy(mbs, oname, ConnectionPoolMBean.class);
    String jmxPassword = mbean.getPassword();
    Properties jmxProperties = mbean.getDbProperties();
    Assert.assertFalse("Passwords should not match.", password.equals(jmxPassword));
    Assert.assertFalse("Password property should be missing", jmxProperties.containsKey(PoolUtilities.PROP_PASSWORD));
}
MBeanClientInterceptor.java 文件源码 项目:lams 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Ensures that an {@code MBeanServerConnection} is configured and attempts
 * to detect a local connection if one is not supplied.
 */
public void prepare() {
    synchronized (this.preparationMonitor) {
        if (this.server != null) {
            this.serverToUse = this.server;
        }
        else {
            this.serverToUse = null;
            this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId);
        }
        this.invocationHandler = null;
        if (this.useStrictCasing) {
            // Use the JDK's own MBeanServerInvocationHandler,
            // in particular for native MXBean support on Java 6.
            if (JmxUtils.isMXBeanSupportAvailable()) {
                this.invocationHandler =
                        new MBeanServerInvocationHandler(this.serverToUse, this.objectName,
                                (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface)));
            }
            else {
                this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName);
            }
        }
        else {
            // Non-strict casing can only be achieved through custom
            // invocation handling. Only partial MXBean support available!
            retrieveMBeanInfo();
        }
    }
}
AbstractCommandsController.java 文件源码 项目:monarch 阅读 25 收藏 0 点赞 0 评论 0
protected synchronized ObjectName getMemberObjectName() {
  final MBeanServer platformMBeanServer = getMBeanServer();

  final DistributedSystemMXBean distributedSystemMXBean = JMX.newMXBeanProxy(platformMBeanServer,
      MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);

  return distributedSystemMXBean.getMemberObjectName();
}
JmxOperationInvoker.java 文件源码 项目:monarch 阅读 19 收藏 0 点赞 0 评论 0
public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) {
  if (DistributedSystemMXBean.class.equals(mbeanInterface)
      && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) {
    return mbeanInterface.cast(getDistributedSystemMXBean());
  } else if (JMX.isMXBeanInterface(mbeanInterface)) {
    return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
  } else {
    return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface);
  }
}
JMXMBeanDUnitTest.java 文件源码 项目:monarch 阅读 23 收藏 0 点赞 0 评论 0
private void connectAndValidateAsJmxClient(final int jmxPort, final String serverHostName,
    final boolean useSSL, final boolean useMulti) throws Exception {
  // JMX RMI

  Map<String, Object> environment = new HashMap();

  if (useSSL) {
    System.setProperty("javax.net.ssl.keyStore",
        useMulti ? getMultiKeyKeystore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.keyStoreType", "JKS");
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore",
        useMulti ? getMultiKeyTruststore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.trustStorePassword", "password");
    environment.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
  }

  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHostName + ":" + jmxPort
      + "/jndi/rmi://" + serverHostName + ":" + jmxPort + "/jmxrmi");
  JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);


  try {
    MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName("GemFire:service=System,type=Distributed");

    // Get MBean proxy instance that will be used to make calls to registered MBean
    DistributedSystemMXBean distributedSystemMXBean =
        JMX.newMBeanProxy(mbeanServerConnection, mbeanName, DistributedSystemMXBean.class, true);

    assertEquals(1, distributedSystemMXBean.getMemberCount());
    assertEquals(1, distributedSystemMXBean.getLocatorCount());

  } finally {
    jmxConnector.close();
  }
}
JMXMBeanDUnitTest.java 文件源码 项目:monarch 阅读 26 收藏 0 点赞 0 评论 0
private Properties configureJMXSSLProperties(final Properties properties, final boolean isLegacy,
    final boolean useMultiKey) {
  if (isLegacy) {
    properties.setProperty(JMX_MANAGER_SSL_CIPHERS, "any");
    properties.setProperty(JMX_MANAGER_SSL_PROTOCOLS, "any");
    properties.setProperty(JMX_MANAGER_SSL_ENABLED, "true");
    properties.setProperty(JMX_MANAGER_SSL_KEYSTORE, getSimpleSingleKeyKeystore());
    properties.setProperty(JMX_MANAGER_SSL_KEYSTORE_PASSWORD, "password");
    properties.setProperty(JMX_MANAGER_SSL_TRUSTSTORE, getSimpleSingleKeyKeystore());
    properties.setProperty(JMX_MANAGER_SSL_TRUSTSTORE_PASSWORD, "password");
  } else {
    {
      properties.setProperty(SSL_CIPHERS, "any");
      properties.setProperty(SSL_PROTOCOLS, "any");
      properties.setProperty(SSL_KEYSTORE_PASSWORD, "password");
      properties.setProperty(SSL_TRUSTSTORE_PASSWORD, "password");
      properties.setProperty(SSL_KEYSTORE, getSimpleSingleKeyKeystore());
      properties.setProperty(SSL_TRUSTSTORE, getSimpleSingleKeyKeystore());
      properties.setProperty(SSL_ENABLED_COMPONENTS,
          SecurableCommunicationChannel.JMX.getConstant());

      if (useMultiKey) {
        properties.setProperty(SSL_KEYSTORE, getMultiKeyKeystore());
        properties.setProperty(SSL_TRUSTSTORE, getMultiKeyTruststore());
        properties.setProperty(SSL_JMX_ALIAS, "jmxkey");
      }
    }
  }
  return properties;
}
JmxPasswordTest.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testPassword() throws Exception {
    Assert.assertEquals("Passwords should match when not using JMX.",password,datasource.getPoolProperties().getPassword());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ConnectionPoolMBean mbean = JMX.newMBeanProxy(mbs, oname, ConnectionPoolMBean.class);
    String jmxPassword = mbean.getPassword();
    Properties jmxProperties = mbean.getDbProperties();
    Assert.assertFalse("Passwords should not match.", password.equals(jmxPassword));
    Assert.assertFalse("Password property should be missing", jmxProperties.containsKey(PoolUtilities.PROP_PASSWORD));
}
ScanManager.java 文件源码 项目:jdk8u-jdk 阅读 28 收藏 0 点赞 0 评论 0
public ScanDirConfigMXBean createOtherConfigurationMBean(String name,
        String filename)
    throws JMException {
    final ScanDirConfig profile = new ScanDirConfig(filename);
    final ObjectName profName = makeScanDirConfigName(name);
    final ObjectInstance moi = mbeanServer.registerMBean(profile,profName);
    final ScanDirConfigMXBean proxy =
            JMX.newMXBeanProxy(mbeanServer,profName,
                ScanDirConfigMXBean.class,true);
    configmap.put(moi.getObjectName(),proxy);
    return proxy;
}
JMXProxyTest.java 文件源码 项目:jdk8u-jdk 阅读 18 收藏 0 点赞 0 评论 0
private static void testNonCompliant(Class<?> iface, boolean isMx) throws Exception {
    try {
        System.out.println("Creating a proxy for non-compliant " +
                           (isMx ? "MXBean" : "MBean") + " " +
                           iface.getName() + " ...");

        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
        ObjectName on = new ObjectName("test:type=Proxy");

        if (isMx) {
            JMX.newMXBeanProxy(mbs, on, iface);
        } else {
            JMX.newMBeanProxy(mbs, on, iface);
        }
        fail("Created a proxy for non-compliant " +
             (isMx ? "MXBean" : "MBean") + " - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            success("Proxy not created");
        } else {
            throw e;
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号