建立 JMX MBean Liberty 服务器连接

可以使用基于 Jython 的脚本来建立 Java™ 管理扩展 (JMX) MBean Liberty 服务器连接。

开始之前

必须先获取并安装所选 Jython 版本,才能执行此过程。如果没有 Jython 运行时,那么指令会失败。

过程

  1. 设置环境。

    您需要的文件位于 liberty_home/clients/jython

    1. lib/restConnector.py 文件复制到 jython_home/Lib
    2. 设置 liberty_home/clients 中的 restConnector.jar 的类路径。
      set CLASSPATH=%CLASSPATH%;c:\wlp\clients\restConnector.jar
  2. 运行实用程序。
    示例 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()
    关闭连接

下一步做什么

与 MBean 服务器建立连接之后,您可以使用 invoke(...) 方法来调用 MBean 服务器。

注: 您可从 Liberty Repository 下载 Jython 脚本库。

用于指示主题类型的图标 任务主题

信息中心的条款和条件 | 反馈


时间戳记图标 最近一次更新时间: Wednesday, 2 September 2015
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_admin_serverconnection
文件名:twlp_admin_serverconnection.html