建立 JMX MBean Liberty 伺服器連線

您可以利用 Jython 型 Script 來建立「Java™ 管理延伸 (JMX)」MBean Liberty 伺服器連線。

開始之前

執行這個程序之前,您必須先取得及安裝您選擇的 Jython 版本。 若沒有 Jython 執行時期,指示會失敗。

程序

  1. 設定環境。

    您需要的檔案在 liberty_home/clients/jython 中。

    1. lib/restConnector.py 檔複製到 jython_home/Lib 中。
    2. 設定 liberty_home/clientsrestConnector.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 儲存庫下載 Jython Script 的程式庫。

指示主題類型的圖示 作業主題

資訊中心條款 | 意見


「時間戳記」圖示 前次更新: 2015 年 6 月 22 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_admin_serverconnection
檔名:twlp_admin_serverconnection.html