Java 类javax.management.JMX 实例源码

项目:csap-core    文件:ServiceCollector.java   
private SimonManagerMXBean getSimonProxyBean (
                                                MBeanServerConnection mbeanConn,
                                                ServiceCollectionResults collectionResults ) {

    SimonManagerMXBean simonMgrMxBean = null;

    ServiceInstance service = collectionResults.getServiceInstance();
    if ( service.getSimonMbean().length() > 0 ) {

        try {
            simonMgrMxBean = JMX.newMXBeanProxy(
                mbeanConn, new ObjectName(
                    collectionResults.getServiceInstance().getSimonMbean() ),
                SimonManagerMXBean.class );
        } catch (Exception e) {
            logger.warn( "Failed to get simon proxy", CSAP.getCsapFilteredStackTrace( e ) );
        }

    }

    logger.debug( "{} type: {} Simon mbean name: {} ",
        service.getServiceName(), service.getServerType(), service.getSimonMbean() );

    return simonMgrMxBean;
}
项目:monarch    文件:AbstractCommandsController.java   
/**
 * 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);
  }
}
项目:monarch    文件:AbstractCommandsController.java   
/**
 * Lookup operation for the MemberMXBean representing the Manager in the GemFire cluster. This
 * method gets an instance fo the Platform MBeanServer for this JVM process and uses it to lookup
 * the MemberMXBean for the GemFire Manager based on the ObjectName declared in the
 * DistributedSystemMXBean.getManagerObjectName() operation.
 * 
 * @return a proxy instance to the MemberMXBean of the GemFire Manager.
 * @see #getMBeanServer()
 * @see #createMemberMXBeanForManagerUsingProxy(javax.management.MBeanServer,
 *      javax.management.ObjectName)
 * @see org.apache.geode.management.DistributedSystemMXBean
 * @see org.apache.geode.management.MemberMXBean
 */
protected synchronized MemberMXBean getManagingMemberMXBean() {
  if (managingMemberMXBeanProxy == null) {
    SystemManagementService service = (SystemManagementService) ManagementService
        .getExistingManagementService(GemFireCacheImpl.getInstance());
    MBeanServer mbs = getMBeanServer();

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

    managingMemberMXBeanProxy = createMemberMXBeanForManagerUsingProxy(mbs,
        distributedSystemMXBean.getMemberObjectName());
  }

  return managingMemberMXBeanProxy;
}
项目:monarch    文件:MBeanProxyInvocationHandler.java   
/**
 * 
 * @param member member to which this MBean belongs
 * @param monitoringRegion corresponding MonitoringRegion
 * @param objectName ObjectName of the MBean
 * @param interfaceClass on which interface the proxy to be exposed
 * @return Object
 * @throws ClassNotFoundException
 * @throws IntrospectionException
 */
public static Object newProxyInstance(DistributedMember member,
    Region<String, Object> monitoringRegion, ObjectName objectName, Class interfaceClass)
    throws ClassNotFoundException, IntrospectionException {
  boolean isMXBean = JMX.isMXBeanInterface(interfaceClass);
  boolean notificationBroadcaster =
      ((FederationComponent) monitoringRegion.get(objectName.toString())).isNotificationEmitter();

  InvocationHandler handler =
      new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean);

  Class[] interfaces;

  if (notificationBroadcaster) {
    interfaces =
        new Class[] {interfaceClass, ProxyInterface.class, NotificationBroadCasterProxy.class};
  } else {
    interfaces = new Class[] {interfaceClass, ProxyInterface.class};
  }

  Object proxy = Proxy.newProxyInstance(MBeanProxyInvocationHandler.class.getClassLoader(),
      interfaces, handler);

  return interfaceClass.cast(proxy);
}
项目:monarch    文件:MBeanServerConnectionRule.java   
/**
 * Retrieve a new proxy MBean
 *
 * @return A new proxy MBean of the same type with which the class was constructed
 */
public <T> T getProxyMBean(Class<T> proxyClass, String beanQueryName)
    throws MalformedObjectNameException, IOException {
  ObjectName name = null;
  QueryExp query = null;

  if (proxyClass != null) {
    query = Query.isInstanceOf(Query.value(proxyClass.getName()));
  }

  if (beanQueryName != null) {
    name = ObjectName.getInstance(beanQueryName);
  }

  Set<ObjectInstance> beans = con.queryMBeans(name, query);
  assertEquals("failed to find only one instance of type " + proxyClass.getName() + " with name "
      + beanQueryName, 1, beans.size());

  return JMX.newMXBeanProxy(con, ((ObjectInstance) beans.toArray()[0]).getObjectName(),
      proxyClass);
}
项目:jdk8u-jdk    文件:TestUtils.java   
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
项目:jdk8u-jdk    文件:JMXProxyFallbackTest.java   
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
项目:jdk8u-jdk    文件:ExceptionDiagnosisTest.java   
private static void testCaseProb() throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(new CaseProbImpl(), name);
    CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class);
    try {
        CaseProb prob = proxy.getCaseProb();
        fail("No exception from proxy method getCaseProb");
    } catch (IllegalArgumentException e) {
        String messageChain = messageChain(e);
        if (messageChain.contains("URLPath")) {
            System.out.println("Message chain contains URLPath as required: "
                    + messageChain);
        } else {
            fail("Exception chain for CaseProb does not mention property" +
                    " URLPath differing only in case");
            System.out.println("Full stack trace:");
            e.printStackTrace(System.out);
        }
    }
}
项目:jdk8u-jdk    文件:RandomMXBeanTest.java   
private static <T> void test(MBeanServer mbs, Class<T> c) throws Exception {
    System.out.println("Testing " + c.getName());
    T merlin = c.cast(
        Proxy.newProxyInstance(c.getClassLoader(),
            new Class<?>[] {c},
            new DullInvocationHandler()));
    ObjectName merlinName = new ObjectName("a:type=" + c.getName());
    mbs.registerMBean(merlin, merlinName);
    System.out.println(mbs.getMBeanInfo(merlinName));
    T merlinProxy = JMX.newMXBeanProxy(mbs, merlinName, c);
    Method[] merlinMethods = c.getMethods();
    for (Method m : merlinMethods) {
        Class<?>[] types = m.getParameterTypes();
        Object[] params = new Object[types.length];
        for (int i = 0; i < types.length; i++)
            params[i] = DullInvocationHandler.zeroFor(types[i]);
        System.out.println("Invoking " + m.getName());
        m.invoke(merlinProxy, (Object[]) params);
    }
}
项目:openjdk-jdk10    文件:JMXProxyFallbackTest.java   
private static void testPrivate(Class<?> iface) throws Exception {
    try {
        System.out.println("Creating a proxy for private M(X)Bean " +
                            iface.getName() + " ...");

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

        JMX.newMBeanProxy(mbs, on, iface);
        success("Created a proxy for private M(X)Bean - " + iface.getName());
    } catch (Exception e) {
        Throwable t = e;
        while (t != null && !(t instanceof NotCompliantMBeanException)) {
            t = t.getCause();
        }
        if (t != null) {
            fail("Proxy not created");
        } else {
            throw e;
        }
    }
}
项目:openjdk-jdk10    文件:ExceptionDiagnosisTest.java   
private static void testCaseProb() throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    mbs.registerMBean(new CaseProbImpl(), name);
    CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class);
    try {
        CaseProb prob = proxy.getCaseProb();
        fail("No exception from proxy method getCaseProb");
    } catch (IllegalArgumentException e) {
        String messageChain = messageChain(e);
        if (messageChain.contains("URLPath")) {
            System.out.println("Message chain contains URLPath as required: "
                    + messageChain);
        } else {
            fail("Exception chain for CaseProb does not mention property" +
                    " URLPath differing only in case");
            System.out.println("Full stack trace:");
            e.printStackTrace(System.out);
        }
    }
}
项目:openjdk-jdk10    文件:RandomMXBeanTest.java   
private static <T> void test(MBeanServer mbs, Class<T> c) throws Exception {
    System.out.println("Testing " + c.getName());
    T merlin = c.cast(
        Proxy.newProxyInstance(c.getClassLoader(),
            new Class<?>[] {c},
            new DullInvocationHandler()));
    ObjectName merlinName = new ObjectName("a:type=" + c.getName());
    mbs.registerMBean(merlin, merlinName);
    System.out.println(mbs.getMBeanInfo(merlinName));
    T merlinProxy = JMX.newMXBeanProxy(mbs, merlinName, c);
    Method[] merlinMethods = c.getMethods();
    for (Method m : merlinMethods) {
        Class<?>[] types = m.getParameterTypes();
        Object[] params = new Object[types.length];
        for (int i = 0; i < types.length; i++)
            params[i] = DullInvocationHandler.zeroFor(types[i]);
        System.out.println("Invoking " + m.getName());
        m.invoke(merlinProxy, (Object[]) params);
    }
}
项目:hashsdn-controller    文件:AbstractDynamicWrapperTest.java   
@Test
public void testReadAttributes() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);

    assertEquals(threadCount, proxy.getAttribute(THREAD_COUNT));

    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(),
            proxy.getAttribute(TRIGGER_NEW_INSTANCE_CREATION));

    AttributeList attributes = proxy.getAttributes(new String[] { THREAD_COUNT, TRIGGER_NEW_INSTANCE_CREATION });
    assertEquals(2, attributes.size());
    Attribute threadCountAttr = (Attribute) attributes.get(0);
    assertEquals(THREAD_COUNT, threadCountAttr.getName());
    assertEquals(threadCount, threadCountAttr.getValue());
    Attribute boolTestAttr = (Attribute) attributes.get(1);
    assertEquals(TRIGGER_NEW_INSTANCE_CREATION, boolTestAttr.getName());
    assertEquals(threadPoolConfigBean.isTriggerNewInstanceCreation(), boolTestAttr.getValue());

    MBeanInfo beanInfo = proxy.getMBeanInfo();
    assertEquals(2, beanInfo.getAttributes().length);
}
项目:hashsdn-controller    文件:DynamicWritableWrapperTest.java   
@Test
public void testSetAttribute() throws Exception {
    DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer, threadPoolDynamicWrapperON, DynamicMBean.class);

    proxy.setAttribute(new Attribute(THREAD_COUNT, newThreadCount));

    assertEquals(newThreadCount, proxy.getAttribute(THREAD_COUNT));
    assertEquals(newThreadCount, threadPoolConfigBean.getThreadCount());

    AttributeList attributeList = new AttributeList();
    attributeList.add(new Attribute(THREAD_COUNT, threadCount));
    boolean bool = true;
    attributeList.add(new Attribute(TRIGGER_NEW_INSTANCE_CREATION, bool));
    proxy.setAttributes(attributeList);

    assertEquals(threadCount, threadPoolConfigBean.getThreadCount());
    assertEquals(bool, threadPoolConfigBean.isTriggerNewInstanceCreation());
}
项目:hashsdn-controller    文件:DynamicWritableWrapperTest.java   
@Test
public void testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON() throws Exception {
    TestingParallelAPSPModuleFactory testingParallelAPSPConfigBeanFactory = new TestingParallelAPSPModuleFactory();
    TestingParallelAPSPModule apspConfigBean = testingParallelAPSPConfigBeanFactory.createModule("", null, null);
    ModuleIdentifier moduleIdentifier2 = new ModuleIdentifier("apsp", "parallel");
    ObjectName dynON2 = ObjectNameUtil.createReadOnlyModuleON(moduleIdentifier2);
    AbstractDynamicWrapper dyn = getDynamicWrapper(apspConfigBean, moduleIdentifier2);
    platformMBeanServer.registerMBean(dyn, dynON2);
    try {
        TestingParallelAPSPConfigMXBean proxy = JMX.newMBeanProxy(platformMBeanServer, dynON2,
                TestingParallelAPSPConfigMXBean.class);
        ObjectName withTransactionName = ObjectNameUtil.createTransactionModuleON("transaction1", "moduleName",
                "instanceName");
        proxy.setThreadPool(withTransactionName);
        ObjectName withoutTransactionName = ObjectNameUtil.withoutTransactionName(withTransactionName);
        assertEquals(withoutTransactionName, proxy.getThreadPool());
    } finally {
        platformMBeanServer.unregisterMBean(dynON2);
    }
}
项目:sstable-adaptor    文件:ThreadPoolMetrics.java   
public static Object getJmxMetric(MBeanServerConnection mbeanServerConn, String jmxPath, String poolName, String metricName)
{
    String name = String.format("org.apache.cassandra.metrics:type=ThreadPools,path=%s,scope=%s,name=%s", jmxPath, poolName, metricName);

    try
    {
        ObjectName oName = new ObjectName(name);
        if (!mbeanServerConn.isRegistered(oName))
        {
            return "N/A";
        }

        switch (metricName)
        {
            case "ActiveTasks":
            case "PendingTasks":
            case "CompletedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxGaugeMBean.class).getValue();
            case "TotalBlockedTasks":
            case "CurrentlyBlockedTasks":
                return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxCounterMBean.class).getCount();
            default:
                throw new AssertionError("Unknown metric name " + metricName);
        }
    }
    catch (Exception e)
    {
        throw new RuntimeException("Error reading: " + name, e);
    }
}
项目:log4j2-redis-appender    文件:RedisThrottler.java   
private RedisThrottlerJmxBean registerOrGetJmxBean() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        synchronized (jmxBeanReferenceCountByName) {

            // Get the reference count for the JMX bean.
            Integer jmxBeanReferenceCount = jmxBeanReferenceCountByName.get(jmxBeanName);
            if (jmxBeanReferenceCount == null) {
                jmxBeanReferenceCount = 0;
            }

            // Create or get the JMX bean.
            RedisThrottlerJmxBean jmxBean;
            try {
                jmxBean = new RedisThrottlerInternalJmxBean();
                StandardMBean jmxBeanWrapper = new StandardMBean(jmxBean, RedisThrottlerJmxBean.class);
                mbs.registerMBean(jmxBeanWrapper, jmxBeanName);
            } catch (InstanceAlreadyExistsException ignored) {
                jmxBean = JMX.newMBeanProxy(mbs, jmxBeanName, RedisThrottlerJmxBean.class);
            }

            // Increment the reference count and return the JMX bean.
            jmxBeanReferenceCountByName.put(jmxBeanName, jmxBeanReferenceCount + 1);
            return jmxBean;

        }
    } catch (Throwable error) {
        String message = String.format("failed accessing the JMX bean (jmxBeanName=%s)", jmxBeanName);
        throw new RuntimeException(message, error);
    }
}
项目:Pogamut3    文件:AbstractJMXAgentObserver.java   
/**
 * Creates JMX wrapper for agent on specified adress and adds it to the list
 * of all connected agents.
 * @param serviceUrl URL of the JMX service where remote agent resides eg. service:jmx:rmi:///jndi/rmi://localhost:9999/server
 * @param objectName name of the MBean representing agent eg. myDomain:name=MyAgent1
 */
protected void addJMXAgentFromAdress(String serviceUrl, ObjectName objectName) throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    IAgent agent = JMX.newMXBeanProxy(mbsc, objectName, IAgent.class);

    agents.add(agent);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public JobMXBean getJobBean(String domainId, String instanceId,
        BigInteger jobId) {
    ObjectName objName = ObjectNameBuilder.job(domainId, instanceId,
            jobId);

    return JMX.newMXBeanProxy(connection, objName, JobMXBean.class,
            true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public PeMXBean getPeBean(String domainId, String instanceId,
        BigInteger peId) {
    ObjectName objName = ObjectNameBuilder.pe(domainId, instanceId,
            peId);
    return JMX
            .newMXBeanProxy(connection, objName, PeMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public DomainMXBean getDomainBean(String domainId) {
    ObjectName objName = ObjectNameBuilder.domain(domainId);

    return JMX.newMXBeanProxy(connection, objName, DomainMXBean.class,
            true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public InstanceMXBean getInstanceBean(String domainId, String instanceId) {
    ObjectName objName = ObjectNameBuilder.instance(domainId,
            instanceId);
    return JMX.newMXBeanProxy(connection, objName,
            InstanceMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public ResourceMXBean getResourceBean(String domainId, String resourceId) {
    ObjectName resourceObjectName = ObjectNameBuilder.resource(
            domainId, resourceId);

    return JMX.newMXBeanProxy(connection, resourceObjectName,
            ResourceMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public DomainServiceMXBean getDomainServiceBean(String domainId,
        Type serviceType) {
    ObjectName serviceObjectName = ObjectNameBuilder.domainService(
            domainId, serviceType);
    return JMX.newMXBeanProxy(connection, serviceObjectName,
            DomainServiceMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public InstanceServiceMXBean getInstanceServiceMXBean(
        String domainId,
        String instanceId,
        com.ibm.streams.management.instance.InstanceServiceMXBean.Type serviceType) {
    ObjectName serviceObjectName = ObjectNameBuilder.instanceService(
            domainId, instanceId, serviceType);
    return JMX.newMXBeanProxy(connection, serviceObjectName,
            InstanceServiceMXBean.class, true);
}
项目:hashsdn-controller    文件:ShutdownTest.java   
@Test
public void testWrongSecret() throws Exception {
    setSecret("secret");
    try {
        ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class);
        runtime.shutdown("foo", 60000L, null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Invalid secret", e.getMessage());
    }
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public OperatorInputPortMXBean getOperatorInputPortMXBean(
        String domainId, String instanceId, BigInteger jobId,
        String operator, int indexWithinOperator) {
    ObjectName inputPortName = ObjectNameBuilder.operatorInputPort(
            domainId, instanceId, jobId, operator, indexWithinOperator);
    return JMX.newMXBeanProxy(connection, inputPortName,
            OperatorInputPortMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public OperatorOutputPortMXBean getOperatorOutputPortMXBean(
        String domainId, String instanceId, BigInteger jobId,
        String operator, int indexWithinOperator) {
    ObjectName outputPortName = ObjectNameBuilder.operatorOutputPort(
            domainId, instanceId, jobId, operator, indexWithinOperator);
    return JMX.newMXBeanProxy(connection, outputPortName,
            OperatorOutputPortMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public PeInputPortMXBean getPeInputPortMXBean(String domainId,
        String instanceId, BigInteger peId, int indexWithinPe) {
    ObjectName inputPortName = ObjectNameBuilder.peInputPort(domainId,
            instanceId, peId, indexWithinPe);
    return JMX.newMXBeanProxy(connection, inputPortName,
            PeInputPortMXBean.class, true);
}
项目:streamsx.jmxclients    文件:JmxConnectionPool.java   
@Override
public PeOutputPortMXBean getPeOutputPortMXBean(String domainId,
        String instanceId, BigInteger peId, int indexWithinPe) {
    ObjectName outputPortName = ObjectNameBuilder.peOutputPort(
            domainId, instanceId, peId, indexWithinPe);
    return JMX.newMXBeanProxy(connection, outputPortName,
            PeOutputPortMXBean.class, true);
}
项目:streamsx.jmxclients    文件:StreamsInstanceTracker.java   
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());

  }
项目:tomcat7    文件:JmxPasswordTest.java   
@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));
}
项目:lams    文件:MBeanClientInterceptor.java   
/**
 * 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();
        }
    }
}
项目:monarch    文件:AbstractCommandsController.java   
protected synchronized ObjectName getMemberObjectName() {
  final MBeanServer platformMBeanServer = getMBeanServer();

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

  return distributedSystemMXBean.getMemberObjectName();
}
项目:monarch    文件:JmxOperationInvoker.java   
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);
  }
}
项目:monarch    文件:JMXMBeanDUnitTest.java   
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();
  }
}
项目:monarch    文件:JMXMBeanDUnitTest.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:JmxPasswordTest.java   
@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));
}
项目:jdk8u-jdk    文件:ScanManager.java   
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;
}
项目:jdk8u-jdk    文件:JMXProxyTest.java   
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;
        }
    }
}