From 37ceeadbf294cb2719ac04f2e3f525c589144334 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Thu, 4 Feb 2016 14:11:42 +0100 Subject: [PATCH] pmg thingies and removed UseConcurrentHashMap rule --- conf/quality-config/pmd-ruleset.xml | 1 + src/main/java/teetime/stage/Cache.java | 2 +- src/main/java/teetime/stage/Clock.java | 8 +++--- .../stage/ElementDelayMeasuringStage.java | 4 +-- .../ElementThroughputMeasuringStage.java | 2 +- .../java/teetime/stage/MappingCounter.java | 2 +- .../stage/MultipleInstanceOfFilter.java | 2 +- src/main/java/teetime/stage/ZipByteArray.java | 8 +++--- src/main/java/teetime/stage/basic/Delay.java | 6 ++--- src/main/java/teetime/stage/basic/Sink.java | 2 +- .../teetime/stage/io/ByteArrayFileWriter.java | 16 +++++------- .../java/teetime/stage/io/File2Lines.java | 3 ++- .../teetime/stage/io/File2SeqOfWords.java | 16 +++++------- .../stage/io/File2TextLinesFilter.java | 8 +++--- .../stage/taskfarm/TaskFarmConfiguration.java | 8 +++--- .../teetime/stage/taskfarm/TaskFarmStage.java | 4 +-- .../analysis/TaskFarmAnalysisService.java | 26 +++++++++---------- .../history/TaskFarmHistoryService.java | 6 ++--- .../adaptation/history/ThroughputHistory.java | 2 +- ...TaskFarmReconfigurationCommandService.java | 13 ++++------ .../exception/TaskFarmAnalysisException.java | 8 +++--- .../TaskFarmControllerException.java | 6 ++--- .../TaskFarmInvalidPipeException.java | 6 ++--- .../monitoring/PipeMonitoringService.java | 3 +-- .../SingleTaskFarmMonitoringService.java | 9 +++---- .../StackedTimePullThroughput2D.java | 2 ++ .../StackedTimePushThroughput2D.java | 2 ++ .../StackedTimeSizeWithCapacity2D.java | 2 ++ .../monitoring/extraction/TimeBoundary2D.java | 6 ++--- .../TimeBoundaryMSPullThroughput3D.java | 4 +-- .../TimeBoundaryMSPushThroughput3D.java | 2 +- .../extraction/TimeBoundaryStages3D.java | 2 +- .../{TextLine.java => TextLineContainer.java} | 4 +-- 33 files changed, 96 insertions(+), 99 deletions(-) rename src/main/java/teetime/stage/util/{TextLine.java => TextLineContainer.java} (89%) diff --git a/conf/quality-config/pmd-ruleset.xml b/conf/quality-config/pmd-ruleset.xml index 0a3cb9ee..fc50ec03 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 88ed055a..e3ca90e6 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 4dba23a5..216238d6 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 7398b823..95bf4e76 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 19ea676d..4aff2086 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 70f9016e..37f24cc7 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 a4e55019..ecef167e 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 b6c67cae..223f2c20 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 ed2297a8..7dc9a24b 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 7847acee..fe86d676 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 1373e130..2c13b883 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 c63e0a01..5a7c930e 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 a8cc8c89..a88dea20 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 c09ce7d3..de77bb0e 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 32df2e64..59940cb5 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 d5cd237e..fd07396d 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 563b9bf3..2226b51f 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 036e22f9..f9c07bb6 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 02d0258a..326f6bd0 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 7ed5f5e1..7a5ef2f1 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 7dbb031c..0b4fd871 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 d8622059..a2adea40 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 97cb43cf..f80ba38a 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 715770fe..7fe10b97 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 a85fd80c..d66ccc7e 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 ea037a77..3fc4b37d 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 2c48a615..1c6c056f 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 27abca42..51c195db 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 990e6db0..efad7f4f 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 a5a4c7b3..b14c0fd3 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 74a07044..01938830 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 a345a7d0..0c74cc16 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 71cb0562..beed3f5c 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; } -- GitLab