Example of setting up a JMX routing environment
You can use Liberty to call Java™ Management Extensions (JMX) management beans (MBeans) on a collective member server through a collective controller server.
Note: The
collectiveController-1.0
feature and its
capabilities are available only in WebSphere® Application Server Network Deployment Liberty
and WebSphere Application Server for z/OS® Liberty. The feature is not
available in WebSphere Application Server Liberty, or WebSphere Application Server Liberty Core. If you have a WebSphere Application Server Network Deployment Liberty installation, you can use its
collectiveController-1.0
feature to work with collective members from WebSphere Application Server Liberty, WebSphere Application Server Express® Liberty, or WebSphere Application Server Liberty Core installations.The
collectiveMember-1.0
feature enables a server to be managed by a collective
controller (the collectiveController-1.0
feature) . After a server is configured to
be managed by a collective controller, you can directly call any MBeans on the collective member
through the collective controller server.
The following is an example of how to call MBeans on a collective member through a collective controller server.
// 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");
}
If
the routing context is configured correctly, all future calls to this
MBeanServerConnection
will be routed to target collective member server.