Skip to content
Snippets Groups Projects
Commit 56dc86bc authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

even more PMD fixes

parent d5d5fc27
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 27 deletions
......@@ -180,11 +180,17 @@ public final class Execution<T extends Configuration> {
instances.add((Configuration) obj);
}
} catch (ClassNotFoundException e) {
LOGGER.error("Could not find class " + each);
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Could not find class " + each);
}
} catch (InstantiationException e) {
LOGGER.error("Could not instantiate class " + each, e);
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Could not instantiate class " + each, e);
}
} catch (IllegalAccessException e) {
LOGGER.error("IllegalAccessException arised while instantiating class " + each, e);
if (LOGGER.isErrorEnabled()) {
LOGGER.error("IllegalAccessException arised while instantiating class " + each, e);
}
}
}
return instances;
......
......@@ -26,7 +26,8 @@ import teetime.framework.AbstractStage;
/**
* Represents a minimalistic StageExceptionListener.
* Listener which extend from this one, must a least implement this functionality.
* This abstract class provides a Logger {@link #logger} and the method {@link #onStageException(Exception, AbstractStage)} which is called on every raised exception.
* This abstract class provides a Logger {@link #logger} and the method {@link #onStageException(Exception, AbstractStage)} which is called on every raised
* exception.
*/
public abstract class AbstractExceptionListener {
......
......@@ -25,7 +25,9 @@ class LoggingExceptionListener extends AbstractExceptionListener {
@Override
public FurtherExecution onStageException(final Exception e, final AbstractStage throwingStage) {
logger.warn("Exception occurred in " + throwingStage.getId(), e);
if (logger.isWarnEnabled()) {
logger.warn("Exception occurred in " + throwingStage.getId(), e);
}
return FurtherExecution.CONTINUE;
}
......
......@@ -93,7 +93,8 @@ public class TaskFarmHistoryService<I, O, T extends ITaskFarmDuplicable<I, O>> {
} catch (ClassCastException e) {
throw new TaskFarmInvalidPipeException(
"The input pipe of an enclosed stage instance inside a Task Farm"
+ " does not implement IMonitorablePipe, which is required.");
+ " does not implement IMonitorablePipe, which is required.",
e);
}
return sum;
......
......@@ -70,7 +70,9 @@ class TaskFarmController<I, O> {
* @throws InterruptedException
*/
public void addStageToTaskFarm() throws InterruptedException {
LOGGER.debug("Add stage (current amount of stages: " + this.taskFarmStage.getEnclosedStageInstances().size() + ")");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Add stage (current amount of stages: " + this.taskFarmStage.getEnclosedStageInstances().size() + ")");
}
ITaskFarmDuplicable<I, O> newStage = this.taskFarmStage.getBasicEnclosedStage().duplicate();
final CreatePortActionDistributor<I> distributorPortAction = new CreatePortActionDistributor<I>(newStage.getInputPort(),
......@@ -105,7 +107,7 @@ class TaskFarmController<I, O> {
try {
this.taskFarmStage.getPipeMonitoringService().addMonitoredItem((IMonitorablePipe) newStage.getInputPort().getPipe());
} catch (ClassCastException e) {
throw new TaskFarmControllerException("A generated pipe is not monitorable.");
throw new TaskFarmControllerException("A generated pipe is not monitorable.", e);
}
}
}
......@@ -120,10 +122,11 @@ class TaskFarmController<I, O> {
return;
}
LOGGER.debug("Remove stage (current amount of stages: " + this.taskFarmStage.getEnclosedStageInstances().size() + ")");
ITaskFarmDuplicable<I, O> stageToBeRemoved = null;
OutputPort<?> distributorOutputPort = null;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Remove stage (current amount of stages: " + this.taskFarmStage.getEnclosedStageInstances().size() + ")");
}
ITaskFarmDuplicable<I, O> stageToBeRemoved;
OutputPort<?> distributorOutputPort;
stageToBeRemoved = this.getStageToBeRemoved();
distributorOutputPort = this.getRemoveableDistributorOutputPort(stageToBeRemoved);
......@@ -140,7 +143,7 @@ class TaskFarmController<I, O> {
return;
}
} catch (ClassCastException e) {
throw new TaskFarmControllerException("Merger and Distributor have a different type than the Task Farm or the Task Farm Controller.");
throw new TaskFarmControllerException("Merger and Distributor have a different type than the Task Farm or the Task Farm Controller.", e);
}
}
......@@ -161,14 +164,14 @@ class TaskFarmController<I, O> {
}
private int getStageIndexWithLeastRemainingInput() {
int currentMinimum = Integer.MAX_VALUE;
int currentMinumumStageIndex = this.taskFarmStage.getEnclosedStageInstances().size() - 1;
int currentMinimum = Integer.MAX_VALUE; // NOPMD DU caused by loop
int currentMinumumStageIndex = this.taskFarmStage.getEnclosedStageInstances().size() - 1; // NOPMD
// do not remove basic stage
for (int i = 1; i < this.taskFarmStage.getEnclosedStageInstances().size(); i++) {
ITaskFarmDuplicable<I, O> instance = this.taskFarmStage.getEnclosedStageInstances().get(i);
InputPort<I> port = instance.getInputPort();
IMonitorablePipe monitorablePipe = null;
IMonitorablePipe monitorablePipe;
try {
monitorablePipe = (IMonitorablePipe) port.getPipe();
......@@ -176,13 +179,14 @@ class TaskFarmController<I, O> {
throw new TaskFarmInvalidPipeException(
"The input pipe of an enclosed stage instance inside a Task Farm"
+ " does not implement IMonitorablePipe, which is required. Instead, the type is "
+ port.getPipe().getClass().getSimpleName() + ".");
+ port.getPipe().getClass().getSimpleName() + ".",
e);
}
if (monitorablePipe != null && monitorablePipe.size() < currentMinimum) {
currentMinimum = monitorablePipe.size();
currentMinumumStageIndex = i;
}
}
return currentMinumumStageIndex;
......
......@@ -30,12 +30,12 @@ public class TaskFarmControllerException extends RuntimeException {
* Represents an exception thrown by the task farm reconfiguration component. It
* gets thrown if the reconfiguration component is not able to add or remove a
* worker stage.
*
*
* @param s
* error message
*/
public TaskFarmControllerException(final String s) {
super(s);
public TaskFarmControllerException(final String s, final Throwable cause) {
super(s, cause);
}
}
......@@ -30,12 +30,12 @@ public class TaskFarmInvalidPipeException extends RuntimeException {
* Represents an exception thrown by the task farm. It
* gets thrown if the user tries to monitor a pipe which
* does not implement {@link teetime.framework.pipe.IMonitorablePipe IMonitorablePipe}.
*
*
* @param s
* error message
*/
public TaskFarmInvalidPipeException(final String s) {
super(s);
public TaskFarmInvalidPipeException(final String s, final Throwable cause) {
super(s, cause);
}
}
......@@ -138,7 +138,8 @@ public class SingleTaskFarmMonitoringService implements IMonitoringService<TaskF
} catch (ClassCastException e) {
throw new TaskFarmInvalidPipeException(
"The input pipe of an enclosed stage instance inside a Task Farm"
+ " does not implement IMonitorablePipe, which is required.");
+ " does not implement IMonitorablePipe, which is required.",
e);
}
// calculate the mean value if necessary
......
......@@ -20,9 +20,9 @@ import java.util.List;
public final class ListContainerPool<T> implements ObjectPool<ListContainer<T>> {
private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>();
private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>();
public ListContainerPool(int initialPoolSize) {
public ListContainerPool(int initialPoolSize) { // NOPMD
while (initialPoolSize-- > 0) {
this.pool.add(this.createNew());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment