建立 JMX MBean Liberty 服务器连接
可以使用基于 Jython 的脚本来建立 Java™ 管理扩展 (JMX) MBean Liberty 服务器连接。
开始之前
过程
- 设置环境。
您需要的文件位于 liberty_home/clients/jython。
- 将 lib/restConnector.py 文件复制到 jython_home/Lib。
- 设置 liberty_home/clients 中的 restConnector.jar 的类路径。
set CLASSPATH=%CLASSPATH%;c:\wlp\clients\restConnector.jar
- 运行实用程序。 示例 1:使用 connector.connect(host,port,user,password) 获取简单连接
from restConnector import JMXRESTConnector JMXRESTConnector.trustStore = "c:/key.jks" JMXRESTConnector.trustStorePassword = "Liberty" connector = JMXRESTConnector() connector.connect("foo.bar.com",9443,"theUser","thePassword") mconnection = connector.getMBeanServerConnection() # mconnection.invoke(...) connector.disconnect()
示例 2:使用 connector.connect(host,port,map) 以及用户提供的属性来获取高级连接import java import javax import jarray import com.ibm.websphere.jmx.connector.rest import com.ibm.ws.jmx.connector.client.rest map=java.util.HashMap() map.put("jmx.remote.provider.pkgs","com.ibm.ws.jmx.connector.client") map.put(javax.management.remote.JMXConnector.CREDENTIALS,jarray.array(["theUser","thePassword"],java.lang.String)) map.put(com.ibm.ws.jmx.connector.client.rest.ClientProvider.READ_TIMEOUT,2*60*1000) map.put(com.ibm.websphere.jmx.connector.rest.ConnectorSettings.DISABLE_HOSTNAME_VERIFICATION, True) connector = JMXRESTConnector() connector.connect("foo.bar.com",9443,map) mconnection = connector.getMBeanServerConnection() # mconnection.invoke(...) connector.disconnect()
示例 3:注册通知侦听器import java import javax from restConnector import JMXRESTConnector from restConnector import BaseNotificationListener class SampleNotificationListener(BaseNotificationListener): def __init__(self): pass def handleNotification(self,notification,handback): print "Notification received:" print " Source: " + notification.getSource().toString() print " Type: " + notification.getType() print " Message: " + notification.getMessage() # main starts here JMXRESTConnector.trustStore = "c:/key.jks" JMXRESTConnector.trustStorePassword = "Liberty" connector=JMXRESTConnector() connector.connect("foo.bar.com",9443,"theUser","thePassword") mconnection=connector.getMBeanServerConnection() listener=SampleNotificationListener() handback=java.lang.Object() notifier1=javax.management.ObjectName("web:name=Notifier1") mconnection.addNotificationListener(notifier1,listener,None,handback)
- JMXRESTConnector.trustStore
- 设置 SSL 密钥文件存储在的路径
- JMXRESTConnector.trustStorePassword
- 设置密钥的密码
- JMXRESTConnector.connect(host,port,user,password)
- 对服务器创建连接器
- JMXRESTConnector.connect(host,port,map)
- 创建具有用户属性的连接器
- JMXRESTConnector.getMBeanServerConnection
- 获取与 MBean 服务器的连接
- JMXRESTConnector.disconnect()
- 关闭连接
父主题: 手动管理 Liberty


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_admin_serverconnection
文件名:twlp_admin_serverconnection.html