@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
protected int execute(final String[] args, final PrintWriter outputWriter) {
int returnValue;
final Context context = getContextInstance(new HashMap<String,String>());
CmdLineParser parser = new CmdLineParser(context);
// execute the app
try {
parser.parseArgument(args);
// capture start time
final long startTime = System.currentTimeMillis();
// build the config element
final ElementBuilder elementBuilder = getElementBuilderInstance();
final JMXEval jmxEval = (JMXEval) elementBuilder.build(context);
// process the evals
jmxEval.process(context);
// set elapsed time in seconds
final double elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
context.getResponse().addPerfData(new PerfDataResult(
"time", String.valueOf(elapsedTime), "s", null, null, null, null));
// print response
outputWriter.println(context.getResponse());
// return status value to indicate execution status
returnValue = context.getResponse().getStatus().getValue();
} catch (ConfigurationException e) {
// print exception
outputWriter.println(e.getMessage());
if (e.getCause() != null) {
outputWriter.println("Error details:");
e.printStackTrace(outputWriter);
}
// indicate error by returning a non-zero value
returnValue = Status.UNKNOWN.getValue();
} catch (EvalException e) {
// print exception
outputWriter.println(e.getMessage());
if (e.getCause() != null) {
outputWriter.println("Error details:");
e.printStackTrace(outputWriter);
}
// indicate error by returning a non-zero value
returnValue = e.getStatus().getValue();
} catch (CmdLineException e) {
e.printStackTrace();
// print usage information
System.err.println(e.getMessage());
System.err.print("java -jar jmxeval.jar ");
parser.printSingleLineUsage(System.err);
System.err.println();
parser.printUsage(System.err);
returnValue = Status.UNKNOWN.getValue();
}
return returnValue;
}