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

some pmd fixes

parent c067f184
No related branches found
No related tags found
No related merge requests found
Showing with 24 additions and 136 deletions
...@@ -40,12 +40,13 @@ public class A2InvalidThreadAssignmentCheck { ...@@ -40,12 +40,13 @@ public class A2InvalidThreadAssignmentCheck {
public void check() { public void check() {
int color = DEFAULT_COLOR; int color = DEFAULT_COLOR;
ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>(); ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>();
ThreadPainter threadPainter = new ThreadPainter();
for (AbstractStage threadableStage : threadableStages) { for (AbstractStage threadableStage : threadableStages) {
color++; color++;
colors.put(threadableStage, color); colors.put(threadableStage, color);
ThreadPainter threadPainter = new ThreadPainter(colors, color, threadableStages); threadPainter.reset(colors, color, threadableStages);
Traverser traverser = new Traverser(threadPainter); Traverser traverser = new Traverser(threadPainter);
traverser.traverse(threadableStage); traverser.traverse(threadableStage);
} }
...@@ -53,12 +54,11 @@ public class A2InvalidThreadAssignmentCheck { ...@@ -53,12 +54,11 @@ public class A2InvalidThreadAssignmentCheck {
private static class ThreadPainter implements ITraverserVisitor { private static class ThreadPainter implements ITraverserVisitor {
private final ObjectIntMap<AbstractStage> colors; private ObjectIntMap<AbstractStage> colors;
private final int color; private int color;
private final Set<AbstractStage> threadableStages; private Set<AbstractStage> threadableStages;
public ThreadPainter(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) { public void reset(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) {
super();
this.colors = colors; this.colors = colors;
this.color = color; this.color = color;
this.threadableStages = threadableStages; this.threadableStages = threadableStages;
......
...@@ -66,11 +66,9 @@ public abstract class AbstractCompositeStage { ...@@ -66,11 +66,9 @@ public abstract class AbstractCompositeStage {
throw new IllegalArgumentException("1003 - targetPort may not be null"); throw new IllegalArgumentException("1003 - targetPort may not be null");
} }
if (sourcePort.getOwningStage().getInputPorts().size() == 0) { if (sourcePort.getOwningStage().getInputPorts().size() == 0 && sourcePort.getOwningStage().getOwningThread() == null) {
if (sourcePort.getOwningStage().getOwningThread() == null) {
sourcePort.getOwningStage().declareActive(); sourcePort.getOwningStage().declareActive();
} }
}
new InstantiationPipe<T>(sourcePort, targetPort, capacity); new InstantiationPipe<T>(sourcePort, targetPort, capacity);
} }
......
...@@ -17,7 +17,7 @@ package teetime.framework; ...@@ -17,7 +17,7 @@ package teetime.framework;
import teetime.framework.pipe.IPipe; import teetime.framework.pipe.IPipe;
public abstract class AbstractPort<T> { public class AbstractPort<T> {
protected IPipe<?> pipe; protected IPipe<?> pipe;
/** /**
......
...@@ -25,12 +25,6 @@ import java.util.Set; ...@@ -25,12 +25,6 @@ import java.util.Set;
*/ */
final class ConfigurationContext { final class ConfigurationContext {
// static final ConfigurationContext EMPTY_CONTEXT = new ConfigurationContext(null);
// private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationContext.class);
// private final Set<ConfigurationContext> children = new HashSet<ConfigurationContext>(); // parent-child-tree
private ThreadService threadService; private ThreadService threadService;
ConfigurationContext(final Configuration configuration) { ConfigurationContext(final Configuration configuration) {
......
...@@ -19,8 +19,10 @@ import java.util.List; ...@@ -19,8 +19,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Represents a exception, which is thrown by an analysis, if any problems occured within its execution. * Represents a exception, which is thrown by an analysis,
* A collection of thrown exceptions within the analysis can be retrieved with {@link #getThrownExceptions()}. * if any problems occured within its execution.
* A collection of thrown exceptions within the analysis
* can be retrieved with {@link #getThrownExceptions()}.
* *
* @since 2.0 * @since 2.0
*/ */
...@@ -37,7 +39,8 @@ public class ExecutionException extends RuntimeException { ...@@ -37,7 +39,8 @@ public class ExecutionException extends RuntimeException {
/** /**
* Returns all exceptions thrown within the execution. * Returns all exceptions thrown within the execution.
* These are passed on as pairs of threads and throwables, to indicate a exception's context. * These are passed on as pairs of threads and throwables,
* to indicate a exception's context.
* *
* @return a thread-exceptionlist-map * @return a thread-exceptionlist-map
*/ */
......
/**
* Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime-framework.github.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package teetime.framework;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import teetime.framework.pipe.InstantiationPipe;
import teetime.framework.pipe.UnsynchedPipe;
import teetime.framework.pipe.BoundedSynchedPipe;
import teetime.framework.pipe.UnboundedSynchedPipe;
class ExecutionInstantiation {
private static final int DEFAULT_COLOR = 0;
private final ConfigurationContext context;
private ExecutionInstantiation(final ConfigurationContext context) {
this.context = context;
}
void instantiatePipes() {
int color = DEFAULT_COLOR;
Map<AbstractStage, Integer> colors = new HashMap<AbstractStage, Integer>();
Set<AbstractStage> threadableStages = context.getThreadableStages();
for (AbstractStage threadableStage : threadableStages) {
color++;
colors.put(threadableStage, color);
ThreadPainter threadPainter = new ThreadPainter(colors, color, threadableStages);
threadPainter.colorAndConnectStages(threadableStage);
}
}
private static class ThreadPainter {
private final Map<AbstractStage, Integer> colors;
private final int color;
private final Set<AbstractStage> threadableStages;
public ThreadPainter(final Map<AbstractStage, Integer> colors, final int color, final Set<AbstractStage> threadableStages) {
super();
this.colors = colors;
this.color = color;
this.threadableStages = threadableStages;
}
public int colorAndConnectStages(final AbstractStage stage) {
int createdConnections = 0;
for (OutputPort<?> outputPort : stage.getOutputPorts()) {
if (outputPort.pipe != null && outputPort.pipe instanceof InstantiationPipe) {
InstantiationPipe<?> pipe = (InstantiationPipe<?>) outputPort.pipe;
createdConnections += processPipe(outputPort, pipe);
createdConnections++;
}
}
return createdConnections;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private int processPipe(final OutputPort outputPort, final InstantiationPipe pipe) {
int numCreatedConnections;
AbstractStage targetStage = pipe.getTargetPort().getOwningStage();
int targetColor = colors.containsKey(targetStage) ? colors.get(targetStage) : DEFAULT_COLOR;
if (threadableStages.contains(targetStage) && targetColor != color) {
if (pipe.capacity() != 0) {
new BoundedSynchedPipe(outputPort, pipe.getTargetPort(), pipe.capacity());
} else {
new UnboundedSynchedPipe(outputPort, pipe.getTargetPort());
}
numCreatedConnections = 0;
} else {
if (colors.containsKey(targetStage)) {
if (!colors.get(targetStage).equals(color)) {
throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread
// (but not its "headstage")
}
}
new UnsynchedPipe(outputPort, pipe.getTargetPort());
colors.put(targetStage, color);
numCreatedConnections = colorAndConnectStages(targetStage);
}
return numCreatedConnections;
}
}
}
...@@ -29,7 +29,7 @@ public class IntraStageCollector implements ITraverserVisitor { ...@@ -29,7 +29,7 @@ public class IntraStageCollector implements ITraverserVisitor {
@Override @Override
public VisitorBehavior visit(final AbstractStage stage) { public VisitorBehavior visit(final AbstractStage stage) {
if (stage == startStage || stage.getOwningThread() == null /* before execution */ if (stage.equals(startStage) || stage.getOwningThread() == null /* before execution */
|| stage.getOwningThread() == startStage.getOwningThread() /* while execution */) { || stage.getOwningThread() == startStage.getOwningThread() /* while execution */) {
return VisitorBehavior.CONTINUE; return VisitorBehavior.CONTINUE;
} }
......
...@@ -42,10 +42,12 @@ public class MonitoringThread extends Thread { ...@@ -42,10 +42,12 @@ public class MonitoringThread extends Thread {
final long pullThroughput = pipe.getPullThroughput(); final long pullThroughput = pipe.getPullThroughput();
final double ratio = (double) pushThroughput / pullThroughput; final double ratio = (double) pushThroughput / pullThroughput;
if (LOGGER.isInfoEnabled()) {
LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio)); LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio));
LOGGER.info("pushes: " + pushThroughput); LOGGER.info("pushes: " + pushThroughput);
LOGGER.info("pulls: " + pullThroughput); LOGGER.info("pulls: " + pullThroughput);
} }
}
LOGGER.info("------------------------------------"); LOGGER.info("------------------------------------");
try { try {
......
...@@ -59,7 +59,8 @@ public class OutputPort<T> extends AbstractPort<T> { ...@@ -59,7 +59,8 @@ public class OutputPort<T> extends AbstractPort<T> {
* @param element * @param element
* to be sent; May not be <code>null</code>. * to be sent; May not be <code>null</code>.
* *
* @return <code>true</code> iff the <code>element</code> was sent; <code>false</code> otherwise. * @return <code>true</code> iff the <code>element</code> was sent;
* <code>false</code> otherwise.
* *
* @since 1.1 * @since 1.1
*/ */
......
...@@ -75,8 +75,6 @@ class ThreadService extends AbstractService<ThreadService> { ...@@ -75,8 +75,6 @@ class ThreadService extends AbstractService<ThreadService> {
throw new IllegalStateException("The start stage may not be null."); throw new IllegalStateException("The start stage may not be null.");
} }
// TODO use decorator pattern to combine all analyzes so that only one traverser pass is necessary
A1ThreadableStageCollector stageCollector = new A1ThreadableStageCollector(); A1ThreadableStageCollector stageCollector = new A1ThreadableStageCollector();
Traverser traversor = new Traverser(stageCollector, Direction.BOTH); Traverser traversor = new Traverser(stageCollector, Direction.BOTH);
traversor.traverse(startStage); traversor.traverse(startStage);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment