Liberty: JMX ルーティング環境のセットアップ例
Liberty を使用して、集合コントローラー・サーバーを経由して集合メンバー・サーバーで Java™ Management Extensions (JMX) 管理 Bean (MBean) を呼び出すことができます。


collectiveMember-1.0 フィーチャーにより、サーバーを集合コントローラー (collectiveController-1.0 フィーチャー) によって管理できるようになります。サーバーが集合コントローラーによって管理されるよう構成すると、集合コントローラー・サーバーを経由して、集合メンバーで任意の MBean を直接呼び出すことができます。
以下は、集合コントローラー・サーバーを経由して集合メンバーで MBeanを呼び出す方法の例です。
// Set up the trust store to the collective controller server.
System.setProperty("javax.net.ssl.trustStore", "<trustStore for https connection to collective controller>");
System.setProperty("javax.net.ssl.trustStorePassword", "<trustStore password>");
Map<String, Object> environment = new HashMap<String, Object>();
environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client");
environment.put(JMXConnector.CREDENTIALS, new String[] { "<username>", "<password>" });
environment.put(ClientProvider.DISABLE_HOSTNAME_VERIFICATION, true);
environment.put(ClientProvider.READ_TIMEOUT, 2 * 60 * 1000);
JMXServiceURL url = new JMXServiceURL(
"REST", "<hostname of collective controller server>", <https port>, "/IBMJMXConnectorREST");
jmxConnector = JMXConnectorFactory.connect(url, environment);
MBeanServerConnection exmbsc = jmxConnector.getMBeanServerConnection();
// You have a MBeanServerConnection now; at this point, however, all of your MBean calls
// are on the collective controller server.
// The next few lines of code are to set up the routing context so that all calls
// can be routed to a collective member.
ObjectName rmObjectName = new ObjectName(
"WebSphere:feature=collectiveController,type=RoutingContext,name=RoutingContext");
// Call the MBeanRoutingContext MBean to set up the routing context.
Object rcObj = connection.invoke(rmObjectName, "assignServerContext",
new Object[] {
"<hostname of the collective member>", "<collective member server usr dir>", "<collective member server name>"
},
// With the collective-member server usr dir and collective-member server name,
// the managed server can be uniquely identified on a host.
new String[] { "java.lang.String", "java.lang.String", "java.lang.String" });
if (rcObj instanceof Boolean) {
Boolean result = (Boolean) rcObj;
if (result.booleanValue()) {
System.out.println("routing context is configured correctly");
}
Or if (!result.booleanValue()) {
System.out.println("routing context result is false");
}
} else {
System.out.println("failed to configure routing context");
}
ルーティング・コンテキストが正しく構成されていれば、今後この MBeanServerConnection に対する呼び出しは、ターゲットの集合メンバー・サーバーにルーティングされます。