Common code for those modules/tasks that can be configured via a ModuleParams. @param type of underlying implementation. @param type of statistics object.
| 43 | * @param <S> type of statistics object. |
| 44 | */ |
| 45 | public abstract class ParamsTask<P extends ModuleParams, S extends Statistics> implements IORunnable { |
| 46 | |
| 47 | protected P mParams; //see bug 1447 for why this is not final |
| 48 | protected final OutputStream mReportStream; |
| 49 | protected final UsageMetric mUsageMetric; |
| 50 | |
| 51 | /** Declared here to keep the testing boffins happy */ |
| 52 | protected S mStatistics; |
| 53 | |
| 54 | /** |
| 55 | * @param params parameters for the build and search. |
| 56 | * @param reportStream stream to write statistics to. |
| 57 | * @param stats statistics object to populate. |
| 58 | * @param usageMetric keeps track of usage for the current module. |
| 59 | */ |
| 60 | protected ParamsTask(final P params, final OutputStream reportStream, S stats, final UsageMetric usageMetric) { |
| 61 | assert params != null; |
| 62 | mParams = params; |
| 63 | mReportStream = reportStream; |
| 64 | mStatistics = stats; |
| 65 | mUsageMetric = usageMetric; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return usage counter. |
| 70 | */ |
| 71 | public long usage() { |
| 72 | return mUsageMetric.getMetric(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Execute the current task. Does not return until the task |
| 77 | * (including possible subtasks) have completed. This implementation |
| 78 | * manages creation of the output directory, calling the exec |
| 79 | * method, creating a done file, and closing the params upon |
| 80 | * completion. |
| 81 | * @throws IOException if there is a problem. |
| 82 | */ |
| 83 | @Override |
| 84 | public void run() throws IOException { |
| 85 | try { |
| 86 | FileUtils.ensureOutputDirectory(mParams.directory()); |
| 87 | exec(); |
| 88 | generateSummary(); |
| 89 | generateReport(); |
| 90 | } finally { |
| 91 | mParams.close(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Subclasses should do all their work here |
| 97 | * @throws IOException if there is a problem. |
| 98 | */ |
| 99 | protected abstract void exec() throws IOException; |
| 100 | |
| 101 | /** |
| 102 | * Default statistics output delegates to Statistics object |
nothing calls this directly
no outgoing calls
no test coverage detected