javax.management.JMX类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中javax.management.JMX类的一些代码示例,展示了JMX类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMX类的具体详情如下:
包路径:javax.management.JMX
类名称:JMX

JMX介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

private DiagnosticsReportSource newReportsBeanSource( String destination, ReportsInvoker reportsInvoker )
{
  return DiagnosticsReportSources.newDiagnosticsString( destination, () ->
  {
    try
    {
      ObjectName name = new ObjectName( "org.neo4j:instance=kernel#0,name=Reports" );
      Reports reportsBean = JMX.newMBeanProxy( mBeanServer, name, Reports.class );
      return reportsInvoker.invoke( reportsBean );
    }
    catch ( MalformedObjectNameException ignored )
    {
    }
    return "Unable to invoke ReportsBean";
  } );
}

代码示例来源:origin: apache/geode

public AccessControlMXBean getAccessControlMBean() throws Exception {
 return JMX.newMXBeanProxy(con, new ObjectName("GemFire:service=AccessControl,type=Distributed"),
   AccessControlMXBean.class);
}

代码示例来源:origin: apache/geode

this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT,
  checkAndConvertToCompatibleIPv6Syntax(host), String.valueOf(port)));
this.connector = JMXConnectorFactory.connect(url, env);
this.mbsc = connector.getMBeanServerConnection();
this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null);
this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc,
  MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
} else {
 this.managerMemberObjectName = this.distributedSystemMXBeanProxy.getMemberObjectName();
 if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) {
  logger.info("MemberMXBean with ObjectName " + this.managerMemberObjectName
    + " is not present on member with endpoints : " + endpoints);
 } else {
  this.memberMXBeanProxy =
    JMX.newMXBeanProxy(mbsc, managerMemberObjectName, MemberMXBean.class);
  this.fileUploadMBeanProxy = JMX.newMBeanProxy(mbsc,
    new ObjectName(ManagementConstants.OBJECTNAME__FILEUPLOADER_MBEAN),
    FileUploaderMBean.class);

代码示例来源:origin: apache/geode

@Override
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);
 }
}

代码示例来源:origin: camelinaction/camelinaction2

public void connect(String serviceUrl) throws Exception {
  JMXServiceURL url = new JMXServiceURL(serviceUrl);
  connector = JMXConnectorFactory.connect(url, null);
  connection = connector.getMBeanServerConnection();
  // create a mbean proxy so we can use the type safe api
  ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
  proxy = JMX.newMBeanProxy(connection, on, ManagedCamelContextMBean.class);
}

代码示例来源:origin: QSFT/Doradus

private synchronized void setConnection() throws IOException {
  if (connection == null) {
    jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
        + host + ":" + port + "/jmxrmi");
    JMXConnector jmxc = JMXConnectorFactory
        .connect(jmxServiceURL, null);
    connection = jmxc.getMBeanServerConnection();
    runtimeServiceProxy = (RuntimeMXBean) JMX.newMXBeanProxy(
        connection, runtimeServiceName, RuntimeMXBean.class);
    osServiceProxy = (OperatingSystemMXBean) JMX.newMXBeanProxy(
        connection, osServiceName, OperatingSystemMXBean.class);
    logger.info("MBean server connected.");
    
    lockedMessages.clear();
  }
}

代码示例来源:origin: org.jboss.jbossts.arjunacore/arjuna

/**
 * Construct a holder for Participant and Recovery Store proxies. There is one instance for each connection
 * to a JVM. In practice there will only ever be one instance.
 *
 * @param serviceUrl the url for the MBean server to connect to. Use default to connect to the local MBean Server
 * @param listener optionally register a listener for notifications
 * @throws JMException if there are JMX errors during registration of MBeans and notification listeners
 * @throws IOException if there are errors on the connection to the MBean Server
 */
private StoreManagerProxy(String serviceUrl, NotificationListener listener) throws JMException, IOException {
  if ("default".equals(serviceUrl)) {
    mbsc = JMXServer.getAgent().getServer();
  } else {
    // create an RMI connector
    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    // connect to the target MBean server
    jmxc = JMXConnectorFactory.connect(url, null);
    mbsc = jmxc.getMBeanServerConnection();
  }
  recoveryStoreON = ObjectName.getInstance(RECOVERY_BEAN_NAME);
  participantStoreON = ObjectName.getInstance(PARTICIPANT_BEAN_NAME);
  rsProxy = new RecoveryStoreProxy(JMX.newMBeanProxy( mbsc, recoveryStoreON, RecoveryStoreBeanMBean.class, true));
  psProxy = new ParticipantStoreProxy(JMX.newMBeanProxy( mbsc, participantStoreON, ParticipantStoreBeanMBean.class, true));
  if (listener != null) {
    mbsc.addNotificationListener(recoveryStoreON, listener, null, null);
    mbsc.addNotificationListener(participantStoreON, listener, null, null);
  }
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

private List<Entry<String, ColumnFamilyStoreMBean>> getCFSMBeans(MBeanServerConnection mbeanServerConn, String type)
    throws MalformedObjectNameException, IOException
{
  ObjectName query = new ObjectName("org.apache.cassandra.db:type=" + type +",*");
  Set<ObjectName> cfObjects = mbeanServerConn.queryNames(query, null);
  List<Entry<String, ColumnFamilyStoreMBean>> mbeans = new ArrayList<Entry<String, ColumnFamilyStoreMBean>>(cfObjects.size());
  for(ObjectName n : cfObjects)
  {
    String keyspaceName = n.getKeyProperty("keyspace");
    ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, n, ColumnFamilyStoreMBean.class);
    mbeans.add(new AbstractMap.SimpleImmutableEntry<String, ColumnFamilyStoreMBean>(keyspaceName, cfsProxy));
  }
  return mbeans;
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public ColumnFamilyStoreMBean getCfsProxy(String ks, String cf)
{
  ColumnFamilyStoreMBean cfsProxy = null;
  try
  {
    String type = cf.contains(".") ? "IndexColumnFamilies" : "ColumnFamilies";
    Set<ObjectName> beans = mbeanServerConn.queryNames(
        new ObjectName("org.apache.cassandra.db:type=*" + type +",keyspace=" + ks + ",columnfamily=" + cf), null);
    if (beans.isEmpty())
      throw new MalformedObjectNameException("couldn't find that bean");
    assert beans.size() == 1;
    for (ObjectName bean : beans)
      cfsProxy = JMX.newMBeanProxy(mbeanServerConn, bean, ColumnFamilyStoreMBean.class);
  }
  catch (MalformedObjectNameException mone)
  {
    System.err.println("ColumnFamilyStore for " + ks + "/" + cf + " not found.");
    System.exit(1);
  }
  catch (IOException e)
  {
    System.err.println("ColumnFamilyStore for " + ks + "/" + cf + " not found: " + e);
    System.exit(1);
  }
  return cfsProxy;
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

private NameNodeMXBean getNamenodeMxBean()
  throws IOException, MalformedObjectNameException {
 // Get an MBeanServerConnection on the remote VM.
 MBeanServerConnection remote = connector.getMBeanServerConnection();
 ObjectName mxbeanName = new ObjectName(
   "hadoop:service=NameNode,name=NameNodeInfo");
 return JMX.newMXBeanProxy(remote, mxbeanName, NameNodeMXBean.class);
}

代码示例来源:origin: org.drools/drools-compiler

LOG.debug("{}", mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null) );
KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(
    mbserver,
    DroolsManagementAgent.createObjectNameBy(kc1ID),
assertEquals(releaseId1.getVersion(), c1Monitor.getResolvedReleaseId().getVersion());
KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy(
    mbserver,
    DroolsManagementAgent.createObjectNameBy("Matteo"),
assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null).size());
kc.dispose();
assertEquals(0, mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null).size());

代码示例来源:origin: aragozin/jvm-tools

public MemoryPoolPoller(MBeanServerConnection mserver, MemoryPoolEventConsumer consumer) {
  this.consumer = consumer;
  try {
    ObjectName name = new ObjectName("java.lang:type=MemoryPool,name=*");
    for(ObjectName on: mserver.queryNames(name, null)) {
      
      MemoryPoolMXBean mpool = JMX.newMXBeanProxy(mserver, on, MemoryPoolMXBean.class);
      MemPoolTracker tracker = init(mpool);
      trackers.put(tracker.poolName, tracker);
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: Evolveum/midpoint

private QuartzSchedulerMBean getMBeanProxy(String nodeName, MBeanServerConnection mbsc) throws MalformedObjectNameException {
  String mbeanNameAsString = "quartz:type=QuartzScheduler,name=midPointScheduler,instance=" + nodeName;
  ObjectName mbeanName = new ObjectName(mbeanNameAsString);
  try {
    if (mbsc.isRegistered(mbeanName)) {
      return JMX.newMBeanProxy(mbsc, mbeanName, QuartzSchedulerMBean.class, true);
    } else {
      LOGGER.trace("MBean " + mbeanNameAsString + " is not registered at " + nodeName);
      return null;
    }
  } catch (IOException e) {
    LoggingUtils.logUnexpectedException(LOGGER, "Cannot communicate with remote node via JMX", e);
    return null;
  }
}

代码示例来源:origin: io.takari.nexus/nexus-perf

public Agent(final JMXServiceURL jmxServiceURL) {
 this.jmxServiceURL = jmxServiceURL;
 try {
  log.info("Connecting to {}...", jmxServiceURL);
  JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL, null);
  connection = connector.getMBeanServerConnection();
  ObjectName controlBeanName = new ObjectName(PerformanceTestMBean.class.getPackage().getName(), "name", "control");
  controlBean = JMX.newMBeanProxy(connection, controlBeanName, PerformanceTestMBean.class, false);
  connection.addNotificationListener(controlBeanName, (notification, handback) -> {
   if (notification instanceof AttributeChangeNotification) {
    AttributeChangeNotification acn = (AttributeChangeNotification) notification;
    if ("running".equals(acn.getAttributeName())
      && Boolean.FALSE.equals(acn.getNewValue()) && Boolean.TRUE.equals(acn.getOldValue())) {
     if (finishSignal != null) {
      finishSignal.countDown();
     }
    }
   }
  }, null, null);
 }
 catch (Exception e) {
  log.debug("Could not connect to {}: {}", jmxServiceURL, e.toString());
  throw Throwables.propagate(e);
 }
}

代码示例来源:origin: lsc-project/lsc

/**
 * Bind to the JMX Server 
 */
public boolean jmxBind() {
  try {
    String sUrl = "service:jmx:rmi:///jndi/rmi://" + hostname + ":" + port + "/jmxrmi";
    LOGGER.info("Connecting to remote engine on : " + sUrl);
    url = new JMXServiceURL(sUrl);
    jmxC = new RMIConnector(url, null);
    jmxC.connect();
    jmxc = jmxC.getMBeanServerConnection();
    ObjectName lscServerName = new ObjectName("org.lsc.jmx:type=LscServer");
    lscServer = JMX.newMXBeanProxy(jmxc, lscServerName, LscServer.class, true);
    return true;
  } catch (MalformedObjectNameException e) {
    LOGGER.error(e.toString(), e);
  } catch (NullPointerException e) {
    LOGGER.error(e.toString(), e);
  } catch (MalformedURLException e) {
    LOGGER.error(e.toString(), e);
  } catch (IOException e) {
    LOGGER.error(e.toString(), e);
  }
  return false;
}

代码示例来源:origin: io.snappydata/gemfire-core

this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT, checkAndConvertToCompatibleIPv6Syntax(host), String.valueOf(port)));
this.connector = JMXConnectorFactory.connect(url, env);
this.mbsc = connector.getMBeanServerConnection();
this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null);
this.connector.connect(); // TODO this call to connect is not needed
this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
if (this.distributedSystemMXBeanProxy == null || !JMX.isMXBeanInterface(DistributedSystemMXBean.class)) {
 LogWrapper.getInstance().info("DistributedSystemMXBean is not present on member with endpoints : "+this.endpoints);
 connector.close();
 if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) {
  LogWrapper.getInstance().info("MemberMXBean with ObjectName "+this.managerMemberObjectName+" is not present on member with endpoints : "+endpoints);
  this.connector.close();
  this.memberMXBeanProxy = JMX.newMXBeanProxy(mbsc, managerMemberObjectName, MemberMXBean.class);

代码示例来源:origin: Talend/tesb-rt-se

public FeaturesServiceMBean createFeaturesServiceMBeanProxy(
    MBeanServerConnection mbsc) throws MalformedObjectNameException,
    NullPointerException, InstanceNotFoundException, IOException {
  echo("\n>>> Create FeatureService MBean <<<");
  ObjectName mbeanName = new ObjectName(
      "org.apache.karaf:type=features,name=trun");
  FeaturesServiceMBean featuresServiceMBeanProxy = JMX.newMBeanProxy(
      mbsc, mbeanName, FeaturesServiceMBean.class, true);
  echo("\n>>> Add notification listener to FeatureService MBean <<<");
  mbsc.addNotificationListener(mbeanName, clientListener, null, null);
  return featuresServiceMBeanProxy;
}

代码示例来源:origin: io.fabric8.itests/fabric-itests-common

@Override
  public Object call() throws Exception {
    long time = 0;
    while (time <= timeout) {
      try {
        JMXServiceURL url = new JMXServiceURL(container.getJmxUrl());
        Map env = new HashMap();
        String[] creds = {"admin", "admin"};
        env.put(JMXConnector.CREDENTIALS, creds);
        JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        mbsc.getObjectInstance(mbeanName);
        return JMX.newMBeanProxy(mbsc, mbeanName, clazz, true);
      } catch (Exception e) {
        Thread.sleep(2000L);
        time += 2000L;
      }
    }
    return null;
  }
});

代码示例来源:origin: spotify/cassandra-opstools

private static DynamicEndpointSnitchMBean getDSnitchMbean(JMXServiceURL jmxUrl, Map<String, Object> env) throws IOException, MalformedObjectNameException {
 JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl, env);
 MBeanServerConnection mbeanServerConn = jmxc.getMBeanServerConnection();
 Set<ObjectName> objs = mbeanServerConn.queryNames(null, null);
 ObjectName realName = null;
 // in cassandra 1.1, the mbean has a "random" instance number, listing mbeans and finding the real one.
 for (ObjectName ob : objs) {
  if (ob.getCanonicalName().contains("DynamicEndpointSnitch"))
   realName = ob;
 }
 if (realName != null)
  return JMX.newMBeanProxy(mbeanServerConn, realName, DynamicEndpointSnitchMBean.class);
 else
  throw new RuntimeException("Could not find the DynamicEndpointSnitch mbean!");
}

代码示例来源:origin: org.apache.geode/gemfire-core

Class interfaceClass) throws ClassNotFoundException,
 IntrospectionException {
boolean isMXBean = JMX.isMXBeanInterface(interfaceClass);
boolean notificationBroadcaster = ((FederationComponent) monitoringRegion
  .get(objectName.toString())).isNotificationEmitter();

相关文章