public NodeMBeanServiceImpl(){
try {
objectName = new ObjectName(MBEAN_NAME);
} catch (Exception e) {
throw new ManagerException(e);
}
GenericMapMaker mapMaker = null;
mapMaker = new MapMaker().expireAfterAccess(5, TimeUnit.MINUTES)
.softValues()
.evictionListener(new MapEvictionListener<Long, MBeanServerConnection>() {
public void onEviction(Long nid, MBeanServerConnection mbeanServer) {
// do nothing
}
});
mbeanServers = mapMaker.makeComputingMap(new Function<Long, MBeanServerConnection>() {
public MBeanServerConnection apply(Long nid) {
Node node = nodeService.findById(nid);
String ip = node.getIp();
if (node.getParameters().getUseExternalIp()) {
ip = node.getParameters().getExternalIp();
}
int port = node.getPort().intValue() + 1;
Integer mbeanPort = node.getParameters().getMbeanPort();
if (mbeanPort != null && mbeanPort != 0) {// 做个兼容处理,<=4.2.2版本没有mbeanPort设置
port = mbeanPort;
}
try {
JMXServiceURL serviceURL = new JMXServiceURL(MessageFormat.format(SERVICE_URL,
ip,
String.valueOf(port)));
JMXConnector cntor = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
return mbsc;
} catch (Exception e) {
throw new ManagerException(e);
}
}
});
}