String jmxServerURI = "service:jmx:rmi:///jndi/rmi://localhost:" + jmxServerPort + "/jmxrmi";
// Connect to the JMX Server, configure checkpoint frequency, create MBean proxies for
// UIMA-AS MBeans and service input queues
monitor.initialize(jmxServerURI, samplingFrequency);
// Create formatter listener
JmxMonitorListener listener = null;
String formatterListenerClass = null;
// Check if a custom monitor formatter listener class is provided. The user provides this
// formatter by adding a -Duima.jmx.monitor.formatter=<class> parameter which specifies a class
// that implements {@link JmxMonitorListener} interface
if ((formatterListenerClass = System.getProperty(JmxMonitor.FormatterListener)) != null) {
Object object = null;
try {
// Instantiate the formatter listener class
Class formatterClass = Class.forName(formatterListenerClass);
object = formatterClass.newInstance();
} catch (ClassNotFoundException e) {
System.out
.println("Class Not Found:"
+ formatterListenerClass
+ ". Provide a Formatter Class Which Implements:org.apache.uima.aae.jmx.monitor.JmxMonitorListener");
throw e;
}
if (object instanceof JmxMonitorListener) {
listener = (JmxMonitorListener) object;
} else {
throw new InvalidClassException(
"Invalid Monitor Formatter Class:"
+ formatterListenerClass
+ ".The Monitor Requires a Formatter Which Implements:org.apache.uima.aae.jmx.monitor.JmxMonitorListener");
}
} else {
// The default formatter listener which logs to the UIMA log
listener = new BasicUimaJmxMonitorListener(monitor.getMaxServiceNameLength());
}
// Plug in the monitor listener
monitor.addJmxMonitorListener(listener);
// Create and start the monitor thread
monitorThread = new Thread(monitor);
// Start the monitor thread. It will run until the Spring container stops. When this happens
// the UIMA_Service receives notication via a {@code onApplicationEvent()} callback. There
// the monitor is stopped allowing the service to terminate.
monitorThread.start();
System.out.println(">>> Started JMX Monitor.\n\t>>> MBean Server Port:" + jmxServerPort
+ "\n\t>>> Monitor Sampling Interval:" + samplingFrequency
+ "\n\t>>> Monitor Formatter Class:" + listener.getClass().getName());
} else {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
"startMonitor", JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAJMS_no_jmx_port__WARNING", new Object[]{});