Invoking the FileNotificationMBean from a Java program
zosConnect-2.0 Applies to zosConnect-2.0.
Javadoc for the
FileNotificationMBean is provided in the file
<installation_path>/wlp/dev/api/ibm/javadoc/com.ibm.websphere.appserver.api.basics_1.4-javadoc.zip.
Before studying this topic, you should be familiar with the information in Using an MBean to trigger updates.
The following Java™ code snippet provides an example of
using the REST connector to invoke the
FileNotificationMBean method
notifyFileChanges. This example updates the running server configuration with
changes that are made to either of two server configuration files:
/var/zosconnect/servers/serverName/server.xml and
/var/zosconnect/servers/serverName/includedConfig.xml.
/** z/OS Connect Server hostname */
private final static String hostname = "companyhost.company.com";
/** z/OS Connect Server HTTPS port */
private final static String httpsPort = "9443";
/** z/OS Connect Server administration role user */
private final static String adminUserid = "adminUser";
/** z/OS Connect Server administration role user's password */
private final static String adminPassword = "adminPswd";
/** Truststore containing z/OS Connect Server's public certificate */
private final static String trustStoreLocation = "/mydir/trust.p12";
/** Truststore password */
private final static String trustStorePassword = "truststorePswd";
/** Absolute paths of configuration files to monitor */
private final static String configFilePath1 = "/var/zosconnect/servers/serverName/server.xml";
private final static String configFilePath2 = "/var/zosconnect/servers/serverName/includedConfig.xml";
/** FileNotificationMBean name */
private final static String MBEAN_FILE_NOTIFICATION = "WebSphere:service=com.ibm.ws.kernel.filemonitor.FileNotificationMBean";
/** FileNotificationMBean method notifyFileChanges signature */
private final static String[] MBEAN_FILE_NOTIFICATION_NOTIFYFILECHANGES_SIGNATURE = new String[] {
Collection.class.getName(),
Collection.class.getName(),
Collection.class.getName() };
/** JMX service URL*/
private static String jmxServiceURL = "service:jmx:rest://" + hostname + ":" + httpsPort + "/IBMJMXConnectorREST";
...
public void invokeFileNotificationMBean() {
...
// Get secure remote JMX MBean server connection
System.setProperty("javax.net.ssl.trustStore", trustStoreLocation);
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
HashMap<String, Object> environment = new HashMap<String, Object>();
environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client");
environment.put("com.ibm.ws.jmx.connector.client.disableURLHostnameVerification", Boolean.TRUE);
environment.put(JMXConnector.CREDENTIALS, new String[] { adminUserid , adminPassword });
JMXServiceURL url = new JMXServiceURL(jmxServiceURL);
JMXConnector jmxConnector = JMXConnectorFactory.newJMXConnector(url, environment);
jmxConnector.connect();
MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
// Invoke FileNotificationMBean
ObjectName fileMonitorMBeanName = new ObjectName(MBEAN_FILE_NOTIFICATION);
if (mbsc.isRegistered(fileMonitorMBeanName)) {
// Create a list of absolute paths of each file to be checked
List<String> modifiedFilePaths = new ArrayList<String>();
modifiedFilePaths.add(configFilePath1);
modifiedFilePaths.add(configFilePath2);
// Set MBean method notifyFileChanges parameters (createdFiles, modifiedFiles, deletedFiles)
Object[] params = new Object[] { null, modifiedFilePaths, null };
// Invoke FileNotificationMBean method notifyFileChanges
mbsc.invoke(fileMonitorMBeanName, "notifyFileChanges", params,
MBEAN_FILE_NOTIFICATION_NOTIFYFILECHANGES_SIGNATURE);
}
else {
System.err.println("MBean invoke request failed " + MBEAN_FILE_NOTIFICATION + " is not registered.");
}
...
// Close the JMX connection
jmxConnector.close();
...
}
Note: The client-side REST connector, which is provided in
wlp/clients/restConnector.jar, must be in the class path that is used to
compile and run a Java application that invokes an
MBean.