JMX MBean Liberty サーバー接続の確立
Jython ベースのスクリプトを使用して、Java™ Management Extensions (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(ホスト、ポート、ユーザー、パスワード)
- サーバーへのコネクターを作成します
- JMXRESTConnector.connect(ホスト、ポート、マップ)
- ユーザー・プロパティーでコネクターを作成します
- JMXRESTConnector.getMBeanServerConnection
- MBean サーバーへの接続を取得します
- JMXRESTConnector.disconnect()
- 接続をクローズします
次の作業
MBean サーバーへの接続が確立されたら、invoke(...)
メソッドを使用して MBean サーバーを呼び出すことができます。