changeset 109:b12e1c6dcd50

Cleanup: store outputHandler in base runner.
author shade
date Mon, 12 Aug 2013 13:01:43 +0400
parents 2ec65a76bbb8
children ec78e0017c10
files jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 3 files changed, 8 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Fri Aug 09 23:44:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Mon Aug 12 13:01:43 2013 +0400
@@ -53,10 +53,11 @@
     /** Class holding all our runtime options/arguments */
     private final BaseOptions options;
 
-    OutputFormat outputHandler = null;
+    protected final OutputFormat outputHandler;
 
-    public BaseRunner(BaseOptions options) {
+    public BaseRunner(BaseOptions options, OutputFormat handler) {
         this.options = options;
+        this.outputHandler = handler;
     }
 
     /**
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Fri Aug 09 23:44:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ForkedRunner.java	Mon Aug 12 13:01:43 2013 +0400
@@ -37,17 +37,11 @@
     private final ForkedOptions options;
 
     public ForkedRunner(ForkedOptions options) {
-        super(options);
+        super(options, OutputFormatFactory.createBinaryHook(options.getHostName(), options.getHostPort()));
         this.options = options;
-        this.outputHandler = null;
     }
 
     public void run() {
-        if (outputHandler == null) {
-            // override output handler
-            outputHandler = OutputFormatFactory.createBinaryHook(options.getHostName(), options.getHostPort());
-        }
-
         // expect the tuple from the parent process
         BenchmarkRecord benchmark = new BenchmarkRecord(options.getBenchmark());
         if (options.isVerbose()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Aug 09 23:44:46 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Aug 12 13:01:43 2013 +0400
@@ -71,25 +71,13 @@
 
     /**
      * Main constructor.
-     *
-     * @param options Option instance with options to use
+     * @param options
      */
     public Runner(HarnessOptions options) {
-        super(options);
+        super(options, createOutputHandler(options));
         this.options = options;
     }
 
-    /**
-     * Auxiliary constructor, used from test which are required custom outputHandler.
-     * @param options
-     * @param handler - custom outputHandler
-     */
-    public Runner(HarnessOptions options, OutputFormat handler) {
-        super(options);
-        this.options = options;
-        this.outputHandler = handler;
-    }
-
     public enum ExecutionMode {
         /**
          * classic mode:
@@ -122,7 +110,7 @@
     }
 
     /** Setup helper method, creates OutputHandler according to argv options. */
-    public static OutputFormat createOutputHandler(HarnessOptions options) throws RunnerException {
+    public static OutputFormat createOutputHandler(HarnessOptions options) {
         PrintStream out;
         // setup OutputHandler singleton
         if (options.getOutput() == null) {
@@ -133,7 +121,7 @@
                 System.setOut(out); // override to print everything to file
             } catch (FileNotFoundException ex) {
                 Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
-                throw new RunnerException(ex);
+                throw new IllegalStateException(ex);
             }
         }
 
@@ -142,11 +130,6 @@
 
     /** Main entry point */
     public void run(MicroBenchmarkList list) throws RunnerException {
-        if (outputHandler == null) {
-            // setup our output handler
-            outputHandler = createOutputHandler(options);
-        }
-
         Set<BenchmarkRecord> benchmarks;
 
         // get a list of benchmarks