diff --git a/conf/quality-config/pmd-ruleset.xml b/conf/quality-config/pmd-ruleset.xml index 0a3cb9eea5af230b97bdf24ced3cf7e5550ded46..fc50ec03427c0110e270b88fb0cbffad64b5cbb0 100644 --- a/conf/quality-config/pmd-ruleset.xml +++ b/conf/quality-config/pmd-ruleset.xml @@ -54,6 +54,7 @@ <exclude name="AvoidUsingVolatile" /> <exclude name="CallSuperInConstructor" /> <exclude name="DefaultPackage" /> + <exclude name="UseConcurrentHashMap" /> </rule> <!-- UR means "undefined reference" which is already detected by the compiler. diff --git a/src/main/java/teetime/stage/Cache.java b/src/main/java/teetime/stage/Cache.java index 88ed055a6e6ce3352fd12d361ffbd04122dddd45..e3ca90e6a7b28898f55eda14b424e157f3291d84 100644 --- a/src/main/java/teetime/stage/Cache.java +++ b/src/main/java/teetime/stage/Cache.java @@ -35,7 +35,7 @@ public final class Cache<T> extends AbstractConsumerStage<T> { } @Override - public void onTerminating() throws Exception { + public void onTerminating() throws Exception { // NOPMD this.logger.debug("Emitting " + this.cachedObjects.size() + " cached elements..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); diff --git a/src/main/java/teetime/stage/Clock.java b/src/main/java/teetime/stage/Clock.java index 4dba23a5f3fa03d3dfb84ea58a9dd5735cc71ca8..216238d64fd2b20a6d7ac6c8f96bc337a0fb19ad 100644 --- a/src/main/java/teetime/stage/Clock.java +++ b/src/main/java/teetime/stage/Clock.java @@ -40,7 +40,7 @@ import teetime.framework.TerminationStrategy; */ public final class Clock extends AbstractProducerStage<Long> { - private boolean initialDelayExceeded = false; + private boolean initialDelayExceeded;// = false; /** * Waiting time span until first sent element. @@ -58,11 +58,11 @@ public final class Clock extends AbstractProducerStage<Long> { @Override protected void execute() { - if (!this.initialDelayExceeded) { + if (this.initialDelayExceeded) { + this.sleep(this.intervalDelayInMs); + } else { this.initialDelayExceeded = true; this.sleep(this.initialDelayInMs); - } else { - this.sleep(this.intervalDelayInMs); } // this.logger.debug("Emitting timestamp"); diff --git a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java b/src/main/java/teetime/stage/ElementDelayMeasuringStage.java index 7398b8238d9fdc3d3e4ae8bc3d510931f143b407..95bf4e76cfd43ea5b70f5801d10d6a5bcceddec4 100644 --- a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java +++ b/src/main/java/teetime/stage/ElementDelayMeasuringStage.java @@ -44,14 +44,14 @@ public final class ElementDelayMeasuringStage<T> extends AbstractConsumerStage<T } @Override - public void onStarting() throws Exception { + public void onStarting() throws Exception { // NOPMD super.onStarting(); this.resetTimestamp(System.nanoTime()); } private void computeElementDelay(final Long timestampInNs) { - long diffInNs = timestampInNs - this.lastTimestampInNs; if (this.numPassedElements > 0) { + long diffInNs = timestampInNs - this.lastTimestampInNs; long delayInNsPerElement = diffInNs / this.numPassedElements; this.delays.add(delayInNsPerElement); this.logger.info("Delay: " + delayInNsPerElement + " time units/element"); diff --git a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java b/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java index 19ea676dbabab961d89129c60113612083dfbba6..4aff2086a267235bcc103095d22b282e4a4bcf44 100644 --- a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java +++ b/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java @@ -45,7 +45,7 @@ public final class ElementThroughputMeasuringStage<T> extends AbstractConsumerSt } @Override - public void onStarting() throws Exception { + public void onStarting() throws Exception { // NOPMD super.onStarting(); this.resetTimestamp(System.nanoTime()); } diff --git a/src/main/java/teetime/stage/MappingCounter.java b/src/main/java/teetime/stage/MappingCounter.java index 70f9016e0c3d2395086073d0037d6931bcbe243e..37f24cc7f702f8c146d95641745de5cad3e1d92c 100644 --- a/src/main/java/teetime/stage/MappingCounter.java +++ b/src/main/java/teetime/stage/MappingCounter.java @@ -41,7 +41,7 @@ public final class MappingCounter<T> extends AbstractConsumerStage<T> { } @Override - public void onTerminating() throws Exception { + public void onTerminating() throws Exception { // NOPMD forced by super method port.send(counter); super.onTerminating(); } diff --git a/src/main/java/teetime/stage/MultipleInstanceOfFilter.java b/src/main/java/teetime/stage/MultipleInstanceOfFilter.java index a4e550199f4ba7c1716a1807c8cb66cdc2acd00f..ecef167ef20ea8d37d491ed0a007a7bf48e3f963 100644 --- a/src/main/java/teetime/stage/MultipleInstanceOfFilter.java +++ b/src/main/java/teetime/stage/MultipleInstanceOfFilter.java @@ -40,7 +40,7 @@ public final class MultipleInstanceOfFilter<I> extends AbstractConsumerStage<I> @Override @SuppressWarnings("unchecked") - public void onStarting() throws Exception { + public void onStarting() throws Exception { // NOPMD exception forced by super method super.onStarting(); // We cache the map to avoid the creating of iterators during runtime cachedOutputPortsMap = (Entry<Class<? extends I>, OutputPort<? super I>>[]) outputPortsMap.entrySet().toArray(new Entry<?, ?>[outputPortsMap.size()]); diff --git a/src/main/java/teetime/stage/ZipByteArray.java b/src/main/java/teetime/stage/ZipByteArray.java index b6c67cae77670934bf87c483630fd2019f02b77a..223f2c20e8e6282f44579905e35d5e208afe25cc 100644 --- a/src/main/java/teetime/stage/ZipByteArray.java +++ b/src/main/java/teetime/stage/ZipByteArray.java @@ -45,13 +45,11 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { @Override protected void execute(final byte[] element) { - byte[] streamBytes; try { - streamBytes = (mode == ZipMode.COMP) ? compress(element) : decompress(element); + outputPort.send((mode == ZipMode.COMP) ? compress(element) : decompress(element)); } catch (IOException e) { throw new IllegalStateException(e); } - outputPort.send(streamBytes); } private byte[] compress(final byte[] data) throws IOException { @@ -61,7 +59,7 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); deflater.finish(); - byte[] compressedBytes = new byte[1024]; + byte[] compressedBytes = new byte[1024]; // NOPMD while (!deflater.finished()) { int count = deflater.deflate(compressedBytes); // returns the generated code... index outputStream.write(compressedBytes, 0, count); @@ -79,7 +77,7 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); - byte[] uncompressedBytes = new byte[1024]; + byte[] uncompressedBytes = new byte[1024]; // NOPMD while (!inflater.finished()) { int count; try { diff --git a/src/main/java/teetime/stage/basic/Delay.java b/src/main/java/teetime/stage/basic/Delay.java index ed2297a892443783fda3049516513872e2ac0fa3..7dc9a24b141293ed76078522919c8dd8a471385f 100644 --- a/src/main/java/teetime/stage/basic/Delay.java +++ b/src/main/java/teetime/stage/basic/Delay.java @@ -53,15 +53,15 @@ public final class Delay<T> extends AbstractStage { } @Override - public void onTerminating() throws Exception { - while (null == timestampTriggerInputPort.receive()) { + public void onTerminating() throws Exception { // NOPMD + while (null == timestampTriggerInputPort.receive()) { // NOPMD flushes input // wait for the next trigger } sendAllBufferedEllements(); T element; - while (null != (element = inputPort.receive())) { + while (null != (element = inputPort.receive())) { // NOPMD outputPort.send(element); } diff --git a/src/main/java/teetime/stage/basic/Sink.java b/src/main/java/teetime/stage/basic/Sink.java index 7847acee14bbf25c409e3c87f52e3d34d92fde41..fe86d6768d5319528229af4e0b175831cf22d963 100644 --- a/src/main/java/teetime/stage/basic/Sink.java +++ b/src/main/java/teetime/stage/basic/Sink.java @@ -17,7 +17,7 @@ package teetime.stage.basic; import teetime.framework.AbstractConsumerStage; -public final class Sink<T> extends AbstractConsumerStage<T> { +public final class Sink<T> extends AbstractConsumerStage<T> { // NOPMD Sink suits perfectly as a name for this stage // PERFORMANCE let the sink remove all available input at once by using a new method receiveAll() that clears the pipe's buffer diff --git a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java index 1373e13013a51a06b99858b3dd7146cef3597312..2c13b883febaa569860456080e298a564c1e8b48 100644 --- a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java +++ b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java @@ -19,20 +19,18 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import teetime.framework.AbstractConsumerStage; - import com.google.common.io.Files; +import teetime.framework.AbstractConsumerStage; + public final class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { - private final File file; - private FileOutputStream fo; + private FileOutputStream fileOutput; public ByteArrayFileWriter(final File file) { - this.file = file; try { Files.touch(file); - fo = new FileOutputStream(this.file); + fileOutput = new FileOutputStream(file); } catch (IOException e) { throw new IllegalStateException(e); } @@ -41,8 +39,8 @@ public final class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { @Override protected void execute(final byte[] element) { try { - fo.write(element); - } catch (Exception e) { + fileOutput.write(element); + } catch (IOException e) { throw new IllegalStateException(e); } } @@ -50,7 +48,7 @@ public final class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { @Override public void onTerminating() { try { - fo.close(); + fileOutput.close(); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/teetime/stage/io/File2Lines.java b/src/main/java/teetime/stage/io/File2Lines.java index c63e0a01a75995355234b38630a307af0bf6f945..5a7c930eba92ce1b5df23d5d94f4571a9e2f08b8 100644 --- a/src/main/java/teetime/stage/io/File2Lines.java +++ b/src/main/java/teetime/stage/io/File2Lines.java @@ -56,13 +56,14 @@ public final class File2Lines extends AbstractConsumerStage<File> { this.charset = charset; } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") @Override protected void execute(final File textFile) { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(textFile), this.charset)); String line; - while ((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null) { // NOPMD line = line.trim(); if (line.length() != 0) { outputPort.send(line); diff --git a/src/main/java/teetime/stage/io/File2SeqOfWords.java b/src/main/java/teetime/stage/io/File2SeqOfWords.java index a8cc8c89524204236a8ad0f44ec6c243ede483b6..a88dea201e688272d340882d042e0e314a18ff1f 100644 --- a/src/main/java/teetime/stage/io/File2SeqOfWords.java +++ b/src/main/java/teetime/stage/io/File2SeqOfWords.java @@ -59,17 +59,15 @@ public final class File2SeqOfWords extends AbstractConsumerStage<File> { @Override protected void execute(final File textFile) { - BufferedReader reader = null; + BufferedReader reader = null; // NOPMD try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(textFile), this.charset)); CharBuffer charBuffer = CharBuffer.allocate(bufferCapacity); while (reader.read(charBuffer) != -1) { final int position = getPreviousWhitespacePosition(charBuffer); - if (-1 == position) { - if (logger.isErrorEnabled()) { - logger.error("A word in the following text file is bigger than the buffer's capacity: " + textFile.getAbsolutePath()); - return; - } + if (-1 == position && logger.isErrorEnabled()) { + logger.error("A word in the following text file is bigger than the buffer's capacity: " + textFile.getAbsolutePath()); + return; } final int limit = charBuffer.limit(); @@ -97,16 +95,16 @@ public final class File2SeqOfWords extends AbstractConsumerStage<File> { } private int getPreviousWhitespacePosition(final CharBuffer charBuffer) { - char[] characters = charBuffer.array(); + char[] characters = charBuffer.array(); // NOPMD Array issue int index = charBuffer.arrayOffset() + charBuffer.position() - 1; while (index >= 0) { - switch (characters[index]) { + switch (characters[index]) { // NOPMD break not needed case ' ': case '\n': case '\r': case '\t': - return index - charBuffer.arrayOffset(); + return index - charBuffer.arrayOffset(); // NOPMD default: index--; } diff --git a/src/main/java/teetime/stage/io/File2TextLinesFilter.java b/src/main/java/teetime/stage/io/File2TextLinesFilter.java index c09ce7d3fbaac664267056d5423175e3eded82a3..de77bb0e47c2592dd25afa941cf06d61a9222915 100644 --- a/src/main/java/teetime/stage/io/File2TextLinesFilter.java +++ b/src/main/java/teetime/stage/io/File2TextLinesFilter.java @@ -24,7 +24,7 @@ import java.io.InputStreamReader; import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; -import teetime.stage.util.TextLine; +import teetime.stage.util.TextLineContainer; /** * @author Christian Wulf @@ -34,7 +34,7 @@ import teetime.stage.util.TextLine; */ public final class File2TextLinesFilter extends AbstractConsumerStage<File> { - private final OutputPort<TextLine> outputPort = this.createOutputPort(); + private final OutputPort<TextLineContainer> outputPort = this.createOutputPort(); private final String charset; @@ -70,7 +70,7 @@ public final class File2TextLinesFilter extends AbstractConsumerStage<File> { while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() != 0) { - outputPort.send(new TextLine(textFile, line)); + outputPort.send(new TextLineContainer(textFile, line)); } // else: ignore empty line } } catch (final FileNotFoundException e) { @@ -92,7 +92,7 @@ public final class File2TextLinesFilter extends AbstractConsumerStage<File> { return this.charset; } - public OutputPort<TextLine> getOutputPort() { + public OutputPort<TextLineContainer> getOutputPort() { return outputPort; } diff --git a/src/main/java/teetime/stage/taskfarm/TaskFarmConfiguration.java b/src/main/java/teetime/stage/taskfarm/TaskFarmConfiguration.java index 32df2e64dc2ad57bd0e8ca655c770f6b27db692a..59940cb5eb0f5eda73aa71f7ac0b7ad9a234adf7 100644 --- a/src/main/java/teetime/stage/taskfarm/TaskFarmConfiguration.java +++ b/src/main/java/teetime/stage/taskfarm/TaskFarmConfiguration.java @@ -37,7 +37,7 @@ public class TaskFarmConfiguration<I, O, T extends ITaskFarmDuplicable<I, O>> { public static final int INIT_SAMPLES_UNTIL_REMOVE = -1; /** should the monitoring services be activated (does not affect the adaptation thread!)? **/ - private volatile boolean monitoringEnabled = false; + private volatile boolean monitoringEnabled;// = false; /** the waiting time between each iteration of the adaptation thread **/ private volatile int adaptationWaitingTimeMillis = 50; @@ -57,7 +57,7 @@ public class TaskFarmConfiguration<I, O, T extends ITaskFarmDuplicable<I, O>> { **/ private volatile int maxSamplesUntilRemove = 5; /** throughput boundary of this task farm **/ - private volatile double throughputScoreBoundary = 0.2d; + private volatile double throughputScoreBoundary = 0.2d; // NOPMD error in PMD /** pipe capacity of all pipes inside the task farm **/ private volatile int pipeCapacity = 100; @@ -65,7 +65,9 @@ public class TaskFarmConfiguration<I, O, T extends ITaskFarmDuplicable<I, O>> { /** the maximum number of worker stages the task farm may have **/ private volatile int maxNumberOfCores = Runtime.getRuntime().availableProcessors() - 2; - TaskFarmConfiguration() {} + TaskFarmConfiguration() { + // non-instantiable from outside + } /** * diff --git a/src/main/java/teetime/stage/taskfarm/TaskFarmStage.java b/src/main/java/teetime/stage/taskfarm/TaskFarmStage.java index d5cd237ecb7da203fe58e4ded8fe95624518a7a6..fd07396d189618d58c8df40a872a0011bd3ea631 100644 --- a/src/main/java/teetime/stage/taskfarm/TaskFarmStage.java +++ b/src/main/java/teetime/stage/taskfarm/TaskFarmStage.java @@ -94,13 +94,13 @@ public final class TaskFarmStage<I, O, T extends ITaskFarmDuplicable<I, O>> exte if (merger == null) { this.merger = new DynamicMerger<O>() { @Override - public void onStarting() throws Exception { + public void onStarting() throws Exception { // NOPMD adaptationThread.start(); super.onStarting(); } @Override - public void onTerminating() throws Exception { + public void onTerminating() throws Exception { // NOPMD adaptationThread.stopAdaptationThread(); super.onTerminating(); } diff --git a/src/main/java/teetime/stage/taskfarm/adaptation/analysis/TaskFarmAnalysisService.java b/src/main/java/teetime/stage/taskfarm/adaptation/analysis/TaskFarmAnalysisService.java index 563b9bf320f7b908e7ba305080950613e7555bce..2226b51f4def0c6f574cdcc73c1795cff8ff14dc 100644 --- a/src/main/java/teetime/stage/taskfarm/adaptation/analysis/TaskFarmAnalysisService.java +++ b/src/main/java/teetime/stage/taskfarm/adaptation/analysis/TaskFarmAnalysisService.java @@ -18,14 +18,14 @@ package teetime.stage.taskfarm.adaptation.analysis; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import com.google.common.base.Throwables; + import teetime.stage.taskfarm.ITaskFarmDuplicable; import teetime.stage.taskfarm.TaskFarmConfiguration; import teetime.stage.taskfarm.adaptation.history.TaskFarmHistoryService; import teetime.stage.taskfarm.adaptation.history.ThroughputHistory; import teetime.stage.taskfarm.exception.TaskFarmAnalysisException; -import com.google.common.base.Throwables; - /** * Represents an interface to call a throughput algorithm * by using the throughput algorithm class name. Also provides @@ -69,9 +69,7 @@ public class TaskFarmAnalysisService<I, O, T extends ITaskFarmDuplicable<I, O>> * specified throughput history */ public void analyze(final ThroughputHistory history) { - AbstractThroughputAlgorithm algorithm = null; - - algorithm = createAlgorithm(this.configuration.getThroughputAlgorithm()); + AbstractThroughputAlgorithm algorithm = createAlgorithm(this.configuration.getThroughputAlgorithm()); this.throughputScore = algorithm.getTroughputAnalysis(history); } @@ -86,7 +84,7 @@ public class TaskFarmAnalysisService<I, O, T extends ITaskFarmDuplicable<I, O>> private AbstractThroughputAlgorithm createAlgorithm(final String algorithmClassName) { String fullyQualifiedPath = THROUGHPUT_ALGORITHM_PATH + "." + algorithmClassName; - AbstractThroughputAlgorithm algorithm = null; + AbstractThroughputAlgorithm algorithm; try { // get throughput algorithm class by using reflection @@ -97,37 +95,37 @@ public class TaskFarmAnalysisService<I, O, T extends ITaskFarmDuplicable<I, O>> Constructor<?> algorithmConstructor = algorithmClass.getConstructor(constructorParameterClasses); - algorithm = (AbstractThroughputAlgorithm) algorithmConstructor.newInstance(constructorParameterObjects); + algorithm = (AbstractThroughputAlgorithm) algorithmConstructor.newInstance(constructorParameterObjects); // NOPMD: returns in outer block } catch (ClassNotFoundException e) { throw new TaskFarmAnalysisException("The ThroughputAlgorithm \"" + fullyQualifiedPath - + "\" could not be found."); + + "\" could not be found.", e); } catch (InstantiationException e) { throw new TaskFarmAnalysisException("The ThroughputAlgorithm \"" + fullyQualifiedPath - + "\" is declared as abstract and cannot be instantiated"); + + "\" is declared as abstract and cannot be instantiated", e); } catch (IllegalAccessException e) { throw new TaskFarmAnalysisException("The constructor of \"" + fullyQualifiedPath - + "\" could not be accessed."); + + "\" could not be accessed.", e); } catch (IllegalArgumentException e) { // should not happen at all throw new TaskFarmAnalysisException("The constructor of \"" + fullyQualifiedPath - + "\" has not been called with the correct amount of arguments."); + + "\" has not been called with the correct amount of arguments.", e); } catch (InvocationTargetException e) { throw new TaskFarmAnalysisException("The constructor of \"" + fullyQualifiedPath + "\" has thrown an exception:\n" - + Throwables.getStackTraceAsString(e)); + + Throwables.getStackTraceAsString(e), e); } catch (NoSuchMethodException e) { throw new TaskFarmAnalysisException("The ThroughputAlgorithm \"" + fullyQualifiedPath - + "\" does not have any constructor with exactly one TaskFarmConfiguration as its parameter."); + + "\" does not have any constructor with exactly one TaskFarmConfiguration as its parameter.", e); } catch (SecurityException e) { throw new TaskFarmAnalysisException("A Security Manager is present and \"" + fullyQualifiedPath - + "\"does not have the correct class loader."); + + "\"does not have the correct class loader.", e); } return algorithm; diff --git a/src/main/java/teetime/stage/taskfarm/adaptation/history/TaskFarmHistoryService.java b/src/main/java/teetime/stage/taskfarm/adaptation/history/TaskFarmHistoryService.java index 036e22f9046f76a7501c2eb8a708ce6694676190..f9c07bb691540c59c4e0bc627b770cb95360b677 100644 --- a/src/main/java/teetime/stage/taskfarm/adaptation/history/TaskFarmHistoryService.java +++ b/src/main/java/teetime/stage/taskfarm/adaptation/history/TaskFarmHistoryService.java @@ -75,7 +75,7 @@ public class TaskFarmHistoryService<I, O, T extends ITaskFarmDuplicable<I, O>> { private double getSumOfPipePushThroughputs() { this.lastPullThroughputs = new HashMap<IMonitorablePipe, Long>(); this.lastPushThroughputs = new HashMap<IMonitorablePipe, Long>(); - double sum = 0; + double sum = 0; // NOPMD try { for (ITaskFarmDuplicable<I, O> enclosedStage : this.taskFarmStage.getEnclosedStageInstances()) { @@ -107,7 +107,7 @@ public class TaskFarmHistoryService<I, O, T extends ITaskFarmDuplicable<I, O>> { * (zero if no throughput value for the pipe has been recorded at the last measurement) */ public long getLastPullThroughputOfPipe(final IMonitorablePipe pipe) { - long result = 0; + long result = 0; // NOPMD if (this.lastPullThroughputs.containsKey(pipe)) { result = this.lastPullThroughputs.get(pipe); } @@ -121,7 +121,7 @@ public class TaskFarmHistoryService<I, O, T extends ITaskFarmDuplicable<I, O>> { * (zero if no throughput value for the pipe has been recorded at the last measurement) */ public long getLastPushThroughputOfPipe(final IMonitorablePipe pipe) { - long result = 0; + long result = 0; // NOPMD if (this.lastPushThroughputs.containsKey(pipe)) { result = this.lastPushThroughputs.get(pipe); } diff --git a/src/main/java/teetime/stage/taskfarm/adaptation/history/ThroughputHistory.java b/src/main/java/teetime/stage/taskfarm/adaptation/history/ThroughputHistory.java index 02d0258ad690d5ca14730c3f33f675c76c1196a4..326f6bd04a11d7935a805e1b44c3d1e718feef22 100644 --- a/src/main/java/teetime/stage/taskfarm/adaptation/history/ThroughputHistory.java +++ b/src/main/java/teetime/stage/taskfarm/adaptation/history/ThroughputHistory.java @@ -32,7 +32,7 @@ public class ThroughputHistory { private final int maxEntries; /** throughput sums **/ - private final LinkedList<ThroughputEntry> entries = new LinkedList<ThroughputEntry>(); + private final LinkedList<ThroughputEntry> entries = new LinkedList<ThroughputEntry>(); // NOPMD LinkedList is needed as type in the code /** * Creates a new throughput history with the analysis window specified in the configuration. diff --git a/src/main/java/teetime/stage/taskfarm/adaptation/reconfiguration/TaskFarmReconfigurationCommandService.java b/src/main/java/teetime/stage/taskfarm/adaptation/reconfiguration/TaskFarmReconfigurationCommandService.java index 7ed5f5e17b2be44b1603148ac3131322b7e9909f..7a5ef2f1bf42f5ca86311c9c01ba2014da8472a7 100644 --- a/src/main/java/teetime/stage/taskfarm/adaptation/reconfiguration/TaskFarmReconfigurationCommandService.java +++ b/src/main/java/teetime/stage/taskfarm/adaptation/reconfiguration/TaskFarmReconfigurationCommandService.java @@ -62,22 +62,19 @@ class TaskFarmReconfigurationCommandService<I, O, T extends ITaskFarmDuplicable< * @return {@link TaskFarmReconfigurationCommand} showing if we want to add or remove a stage */ public TaskFarmReconfigurationCommand decideExecutionPlan(final double throughputScore) { - TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; + TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; // NOPMD - switch (this.currentMode) { - case ADDING: + if (this.currentMode == ReconfigurationMode.ADDING) { command = decideForAddingMode(throughputScore); - break; - case REMOVING: + } else { command = decideForRemovingMode(throughputScore); - break; } return command; } private TaskFarmReconfigurationCommand decideForAddingMode(final double throughputScore) { - TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; + TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; // NOPMD if (this.taskFarmStage.getEnclosedStageInstances().size() >= this.taskFarmStage.getConfiguration().getMaxNumberOfCores()) { // we do not want to parallelize more than we have (virtual) processors @@ -115,7 +112,7 @@ class TaskFarmReconfigurationCommandService<I, O, T extends ITaskFarmDuplicable< } private TaskFarmReconfigurationCommand decideForRemovingMode(final double throughputScore) { - TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; + TaskFarmReconfigurationCommand command = TaskFarmReconfigurationCommand.NONE; // NOPMD // we never want to remove the basic stage since it would destroy the pipeline for (int i = 1; i < this.taskFarmStage.getEnclosedStageInstances().size() - 1; i++) { diff --git a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmAnalysisException.java b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmAnalysisException.java index 7dbb031cb6cefb5c08b8acc2e6f3e56ba82aade2..0b4fd871b42e841d19f7bee830ba7af977a72da2 100644 --- a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmAnalysisException.java +++ b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmAnalysisException.java @@ -30,12 +30,12 @@ public class TaskFarmAnalysisException extends RuntimeException { * Represents an exception thrown by the task farm analysis component. It * gets thrown if the analysis component was unable to find the chosen * throughput algorithm. - * - * @param s + * + * @param message * error message */ - public TaskFarmAnalysisException(final String s) { - super(s); + public TaskFarmAnalysisException(final String message, final Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmControllerException.java b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmControllerException.java index d86220592e895df4c970f23ead5827a765eb597b..a2adea40a00fba2c03a4746953bc1381d510d035 100644 --- a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmControllerException.java +++ b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmControllerException.java @@ -31,11 +31,11 @@ public class TaskFarmControllerException extends RuntimeException { * gets thrown if the reconfiguration component is not able to add or remove a * worker stage. * - * @param s + * @param message * error message */ - public TaskFarmControllerException(final String s, final Throwable cause) { - super(s, cause); + public TaskFarmControllerException(final String message, final Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmInvalidPipeException.java b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmInvalidPipeException.java index 97cb43cf04bc8a7699b709f34ac5714e9aece6a1..f80ba38a69b850453212d59a57b73a81b81aab22 100644 --- a/src/main/java/teetime/stage/taskfarm/exception/TaskFarmInvalidPipeException.java +++ b/src/main/java/teetime/stage/taskfarm/exception/TaskFarmInvalidPipeException.java @@ -31,11 +31,11 @@ public class TaskFarmInvalidPipeException extends RuntimeException { * gets thrown if the user tries to monitor a pipe which * does not implement {@link teetime.framework.pipe.IMonitorablePipe IMonitorablePipe}. * - * @param s + * @param message * error message */ - public TaskFarmInvalidPipeException(final String s, final Throwable cause) { - super(s, cause); + public TaskFarmInvalidPipeException(final String message, final Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/PipeMonitoringService.java b/src/main/java/teetime/stage/taskfarm/monitoring/PipeMonitoringService.java index 715770fe19b2f2b5053af55f45d08a6234e428b3..7fe10b97271476bd15554470082db8be28e1a6af 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/PipeMonitoringService.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/PipeMonitoringService.java @@ -100,8 +100,7 @@ public class PipeMonitoringService implements IMonitoringService<IMonitorablePip pushThroughput, pullThroughput, pipe.getNumWaits(), - i - ); + i); container.addMonitoringData(monitoringData); } diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/SingleTaskFarmMonitoringService.java b/src/main/java/teetime/stage/taskfarm/monitoring/SingleTaskFarmMonitoringService.java index a85fd80c073d7720da988cf70744e39f14a3d4fe..d66ccc7e1ff512b95d87d0145f60a043e4cab0ae 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/SingleTaskFarmMonitoringService.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/SingleTaskFarmMonitoringService.java @@ -44,7 +44,7 @@ public class SingleTaskFarmMonitoringService implements IMonitoringService<TaskF private final TaskFarmHistoryService<?, ?, ?> history; /** maximum number of worker stages used by the task farm over its whole execution **/ - private int maxNumberOfStages = 0; + private int maxNumberOfStages; /** * Constructor. @@ -102,6 +102,7 @@ public class SingleTaskFarmMonitoringService implements IMonitoringService<TaskF PUSH, PULL } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") private double getMeanAndSumThroughput(final TaskFarmStage<?, ?, ?> taskFarmStage, final MeanThroughputType type, final boolean mean) { double sum = 0; double count = 0; @@ -143,10 +144,8 @@ public class SingleTaskFarmMonitoringService implements IMonitoringService<TaskF } // calculate the mean value if necessary - if (mean) { - if (count > 0) { - sum /= count; - } + if (mean && count > 0) { + sum /= count; } return sum; diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePullThroughput2D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePullThroughput2D.java index ea037a7741ee0f90e68df1a52e5344441850c421..3fc4b37d90066797a3b298520039ff9db36d467b 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePullThroughput2D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePullThroughput2D.java @@ -41,6 +41,7 @@ public class StackedTimePullThroughput2D extends AbstractStackedCSVExporter { super(pipeMonitoringService, taskFarmMonitoringService); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void addLineOfValuesToCSV(final Writer writer, final int maxNumberOfPipes, final PipeMonitoringDataContainer container) throws IOException { @@ -60,6 +61,7 @@ public class StackedTimePullThroughput2D extends AbstractStackedCSVExporter { addCSVLineToWriter(writer, entryStrings); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void createHeader(final Writer writer, final int maxNumberOfStages) throws IOException { String[] headerStrings = new String[maxNumberOfStages + 1]; diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePushThroughput2D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePushThroughput2D.java index 2c48a615d7659d5f91998531653a64743c0435c5..1c6c056f0ecc16856245d3d5abd50fcf077ec159 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePushThroughput2D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimePushThroughput2D.java @@ -41,6 +41,7 @@ public class StackedTimePushThroughput2D extends AbstractStackedCSVExporter { super(pipeMonitoringService, taskFarmMonitoringService); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void addLineOfValuesToCSV(final Writer writer, final int maxNumberOfPipes, final PipeMonitoringDataContainer container) throws IOException { @@ -60,6 +61,7 @@ public class StackedTimePushThroughput2D extends AbstractStackedCSVExporter { addCSVLineToWriter(writer, entryStrings); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void createHeader(final Writer writer, final int maxNumberOfStages) throws IOException { String[] headerStrings = new String[maxNumberOfStages + 1]; diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimeSizeWithCapacity2D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimeSizeWithCapacity2D.java index 27abca4230d06adde45b9d4db87511ccf6c54b40..51c195dbdc483c42140c85dbcec5666991ab2fe9 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimeSizeWithCapacity2D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/StackedTimeSizeWithCapacity2D.java @@ -42,6 +42,7 @@ public class StackedTimeSizeWithCapacity2D extends AbstractStackedCSVExporter { super(pipeMonitoringService, taskFarmMonitoringService); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void addLineOfValuesToCSV(final Writer writer, final int maxNumberOfPipes, final PipeMonitoringDataContainer container) throws IOException { @@ -62,6 +63,7 @@ public class StackedTimeSizeWithCapacity2D extends AbstractStackedCSVExporter { addCSVLineToWriter(writer, entryStrings); } + @SuppressWarnings("PMD.DataflowAnomalyAnalysis") // PMD does not recognize arrays correctly @Override protected void createHeader(final Writer writer, final int maxNumberOfPipes) throws IOException { String[] headerStrings = new String[maxNumberOfPipes + 2]; diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundary2D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundary2D.java index 990e6db00c799d6a7f7ca9f147031916aea754e8..efad7f4f78ceede838e8f2d9557fda17cdc53877 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundary2D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundary2D.java @@ -26,7 +26,7 @@ import teetime.stage.taskfarm.monitoring.TaskFarmMonitoringData; /** * Represents a CSV file containing one time-boundary pair, * showing the computation time with the given throughput boundary. - * + * * @author Christian Claus Wiechmann */ public class TimeBoundary2D extends AbstractGeneralCSVExporter { @@ -48,7 +48,7 @@ public class TimeBoundary2D extends AbstractGeneralCSVExporter { try { addCSVLineToWriter(writer, "time", "boundary"); - if (monitoredDataValues.size() > 0) { + if (!monitoredDataValues.isEmpty()) { // just add last time-boundary pair so that it will record the duration of the monitoring TaskFarmMonitoringData taskFarmMonitoringData = monitoredDataValues.get(monitoredDataValues.size() - 1); addCSVLineToWriter(writer, @@ -56,7 +56,7 @@ public class TimeBoundary2D extends AbstractGeneralCSVExporter { Double.toString(taskFarmMonitoringData.getThroughputBoundary())); } } catch (IOException e) { - throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage()); + throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage(), e); } } diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPullThroughput3D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPullThroughput3D.java index a5a4c7b344fc6b1e8324e21a653bb759379dee30..b14c0fd3fb75739a936d9ac3b69786c3b669aef2 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPullThroughput3D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPullThroughput3D.java @@ -25,7 +25,7 @@ import teetime.stage.taskfarm.monitoring.TaskFarmMonitoringData; /** * Represents a CSV file containing time-boundary-mean pull throughput-total pull throughput-tuples. - * + * * @author Christian Claus Wiechmann */ public class TimeBoundaryMSPullThroughput3D extends AbstractGeneralCSVExporter { @@ -55,7 +55,7 @@ public class TimeBoundaryMSPullThroughput3D extends AbstractGeneralCSVExporter { Double.toString(taskFarmMonitoringData.getSumOfPullThroughput())); } } catch (IOException e) { - throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage()); + throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage(), e); } } } diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPushThroughput3D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPushThroughput3D.java index 74a0704433ddb297e2b1a31ae4c798bf0dd13edd..01938830ec979836a17ca44d2f1e258dad23651c 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPushThroughput3D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryMSPushThroughput3D.java @@ -55,7 +55,7 @@ public class TimeBoundaryMSPushThroughput3D extends AbstractGeneralCSVExporter { Double.toString(taskFarmMonitoringData.getSumOfPushThroughput())); } } catch (IOException e) { - throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage()); + throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage(), e); } } } diff --git a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryStages3D.java b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryStages3D.java index a345a7d030b10d01a2007d3a84cc5b459d12e3e2..0c74cc165683e0573e2735414ec0de7e4f1c3d3d 100644 --- a/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryStages3D.java +++ b/src/main/java/teetime/stage/taskfarm/monitoring/extraction/TimeBoundaryStages3D.java @@ -54,7 +54,7 @@ public class TimeBoundaryStages3D extends AbstractGeneralCSVExporter { Integer.toString(taskFarmMonitoringData.getStages())); } } catch (IOException e) { - throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage()); + throw new IllegalArgumentException("The writer could not be written to: " + e.getMessage(), e); } } } diff --git a/src/main/java/teetime/stage/util/TextLine.java b/src/main/java/teetime/stage/util/TextLineContainer.java similarity index 89% rename from src/main/java/teetime/stage/util/TextLine.java rename to src/main/java/teetime/stage/util/TextLineContainer.java index 71cb05625178145abe5091fe83a7392a6ee3eb9e..beed3f5c112547e44263d9cdf37628464c7b10cb 100644 --- a/src/main/java/teetime/stage/util/TextLine.java +++ b/src/main/java/teetime/stage/util/TextLineContainer.java @@ -20,12 +20,12 @@ import java.io.File; /** * @author Christian Wulf */ -public final class TextLine { +public final class TextLineContainer { private final File textFile; private final String textLine; - public TextLine(final File textFile, final String textLine) { + public TextLineContainer(final File textFile, final String textLine) { this.textFile = textFile; this.textLine = textLine; }