建立 JMX MBean Liberty 伺服器連線
您可以利用 Jython 型 Script 來建立「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()
- 關閉連線
下一步
建立通往 MBean 伺服器的連線之後,您可以利用 invoke(...) 方法來呼叫 MBean 伺服器。
註: 您可以從 Liberty Repository 下載 Jython Script 的程式庫。
上層主題: 手動管理 Liberty


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