我的服务器中有一些JMX配置。现在,当我想要它时,我从groovy中调用它:
GroovyMBean mbean = new GroovyMBean(server, application)
mbean.invokeMethod(function,parameter)
java中的GroovyMBean
相当于什么,因为现在我想从java代码中调用此配置?
答案 0 :(得分:0)
如果我正确理解您的问题,此代码段将在Java中用于连接到JMXServer。
JMXConnector jmxConnector = null;
MBeanServerConnection mbeanConn = null;
try {
String url = "service:jmx:rmi:///jndi/rmi://" + this.server + ":" + this.port + "/jmxrmi";
JMXServiceURL serviceUrl;
serviceUrl = new JMXServiceURL(url);
jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
mbeanConn = jmxConnector.getMBeanServerConnection();
}catch(Exception e)
{
}
finally
{
//close jmx connector.
}
答案 1 :(得分:0)
MBeanServerConnection connection = null;
HashMap<String,String[]> jmxEnv = new HashMap<String, String[]>();
String[] credentials = new String[2];
credentials[0] = JMX_User;
credentials[1] = JMX_Password;
jmxEnv.put(JMXConnector.CREDENTIALS,credentials);
JMXServiceURL serverUrl = null;
serverUrl = new JMXServiceURL("service:jmx:rmi://"+JMX_Server+":"+JMX_Port+"/jndi/rmi://"+JMX_Server+":"+JMX_Registry_Port+"/server");
connection = JMXConnectorFactory.connect(serverUrl, jmxEnv).getMBeanServerConnection();
ObjectName beanName = null;
beanName = new ObjectName("ObjectName");
Object[] params = new Object[1];
params[0]=fileName;
String[] signature = new String[0];
connection.invoke(beanName, "methodName", params, signature);