JMXHelper.java 文件源码

java
阅读 17 收藏 0 点赞 0 评论 0

项目:gemfirexd-oss 作者:
public static void connectToDS(String host, int port) throws Exception
{
  String url =MessageFormat.format(JMX_URI,  new Object[] { host, 
                                            String.valueOf(port) });

  try {
    JMXServiceURL jmxurl = new JMXServiceURL(url);
    connector = JMXConnectorFactory.connect(jmxurl, null);
    mbsc = connector.getMBeanServerConnection();

    String[] domains = mbsc.getDomains();
    String domain = null;
    for (int i = 0; i < domains.length; i++) {
      if (domains[i].equalsIgnoreCase(MBEAN_DOMAIN_GEMFIRE_NAME)) {
        domain = domains[i];
        break;
      }
    }

    Set set = mbsc.queryNames(new ObjectName(domain + ":*"), null);
    ObjectName on = null;
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      on = (ObjectName)iter.next();
      String onType = on.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE);
      if (MBEAN_AGENT_TYPE.equalsIgnoreCase(onType))
        break;
    }
    agent = on;

    if (agent==null)
      throw new ServiceNotFoundException( MBEAN_AGENT_TYPE + 
                                         " could not be connected");

    String[] params = {}, signature = {};
    String method = "connectToSystem";
    ObjectName ret = null;

    ret = (ObjectName) mbsc.invoke(agent, method, params, signature);
    logger.info("Connected DS client");

    if (ret != null &&
        MBEAN_DISTRIBUTED_SYSTEM_TYPE.
          equalsIgnoreCase(ret.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE))) {
      distributedSys = ret;
    } else {
      ServiceNotFoundException ex = new ServiceNotFoundException(
          MBEAN_DISTRIBUTED_SYSTEM_TYPE + " could not be connected");
      throw ex;
    }
  }
  catch (NullPointerException nullEx) {
    logger.error(url + " is construed NULL", nullEx);
    throw nullEx;
  }
  catch (MalformedURLException malfEx) {
    logger.error(url + " is construed Malformed", malfEx);
    throw malfEx;
  }
  catch (SecurityException secuEx) {
    logger.error("Connection denied due to Security reasons", secuEx);
    throw secuEx;
  }
  catch (InstanceNotFoundException instEx) {
    logger.error("Did not find MBean Instance", instEx);
    throw instEx;
  }
  catch (MBeanException beanEx) {
    logger.error("Exception in MBean", beanEx.getCause());
    throw beanEx;
  }
  catch (ReflectionException reflEx) {
    logger.error("Could not get MBean Info", reflEx);
    throw reflEx;
  }
  catch (IOException ioEx) {
    logger.error("JMX Connection problem. Attempt opeartion Again", ioEx);
    throw ioEx;
  } finally {
    //shLock.unlock();
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号