diff --git a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java index 60e33dae10ab10252bc290054ff44827fd3cbff2..a592b39a945c02406cbbd5c7c14c8e95b7e107d8 100644 --- a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java +++ b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java @@ -40,12 +40,13 @@ public class A2InvalidThreadAssignmentCheck { public void check() { int color = DEFAULT_COLOR; ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>(); + ThreadPainter threadPainter = new ThreadPainter(); for (AbstractStage threadableStage : threadableStages) { color++; colors.put(threadableStage, color); - ThreadPainter threadPainter = new ThreadPainter(colors, color, threadableStages); + threadPainter.reset(colors, color, threadableStages); Traverser traverser = new Traverser(threadPainter); traverser.traverse(threadableStage); } @@ -53,12 +54,11 @@ public class A2InvalidThreadAssignmentCheck { private static class ThreadPainter implements ITraverserVisitor { - private final ObjectIntMap<AbstractStage> colors; - private final int color; - private final Set<AbstractStage> threadableStages; + private ObjectIntMap<AbstractStage> colors; + private int color; + private Set<AbstractStage> threadableStages; - public ThreadPainter(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) { - super(); + public void reset(final ObjectIntMap<AbstractStage> colors, final int color, final Set<AbstractStage> threadableStages) { this.colors = colors; this.color = color; this.threadableStages = threadableStages; diff --git a/src/main/java/teetime/framework/AbstractCompositeStage.java b/src/main/java/teetime/framework/AbstractCompositeStage.java index db4fa8f5fa9debdaca4340aafae472cd00a2e4ce..3b421195e813be4d07da5512bf0c0f9a0d06f455 100644 --- a/src/main/java/teetime/framework/AbstractCompositeStage.java +++ b/src/main/java/teetime/framework/AbstractCompositeStage.java @@ -66,10 +66,8 @@ public abstract class AbstractCompositeStage { throw new IllegalArgumentException("1003 - targetPort may not be null"); } - if (sourcePort.getOwningStage().getInputPorts().size() == 0) { - if (sourcePort.getOwningStage().getOwningThread() == null) { - sourcePort.getOwningStage().declareActive(); - } + if (sourcePort.getOwningStage().getInputPorts().size() == 0 && sourcePort.getOwningStage().getOwningThread() == null) { + sourcePort.getOwningStage().declareActive(); } new InstantiationPipe<T>(sourcePort, targetPort, capacity); diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0f86d2b295a755d29fbec862d7cc28ea8c8a6ca1..d85f8388879a7608cb3e1713062799fc3a21d1bf 100644 --- a/src/main/java/teetime/framework/AbstractPort.java +++ b/src/main/java/teetime/framework/AbstractPort.java @@ -17,7 +17,7 @@ package teetime.framework; import teetime.framework.pipe.IPipe; -public abstract class AbstractPort<T> { +public class AbstractPort<T> { protected IPipe<?> pipe; /** diff --git a/src/main/java/teetime/framework/ConfigurationContext.java b/src/main/java/teetime/framework/ConfigurationContext.java index 0b358f7db894c436d919dd61df2e23437b986fec..71e168ef0c99294f2f26aac2ca7d95ef1f720f27 100644 --- a/src/main/java/teetime/framework/ConfigurationContext.java +++ b/src/main/java/teetime/framework/ConfigurationContext.java @@ -18,19 +18,13 @@ package teetime.framework; import java.util.Set; /** - * Represents a context that is used by a configuration and composite stages to connect ports, for example. + * Represents a context that is used by a configuration and composite stages to connect ports,for example. * Stages can be added by executing {@link #declareActive(AbstractStage)}. * * @since 2.0 */ 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; ConfigurationContext(final Configuration configuration) { diff --git a/src/main/java/teetime/framework/ExecutionException.java b/src/main/java/teetime/framework/ExecutionException.java index 71dd418c48be808adca5d9055869eefc1b389c3e..2a758e68ae6388b4180a0d9f0ef23d8cbad5e60e 100644 --- a/src/main/java/teetime/framework/ExecutionException.java +++ b/src/main/java/teetime/framework/ExecutionException.java @@ -19,8 +19,10 @@ import java.util.List; import java.util.Map; /** - * Represents a exception, which is thrown by an analysis, if any problems occured within its execution. - * A collection of thrown exceptions within the analysis can be retrieved with {@link #getThrownExceptions()}. + * Represents a exception, which is thrown by an analysis, + * if any problems occured within its execution. + * A collection of thrown exceptions within the analysis + * can be retrieved with {@link #getThrownExceptions()}. * * @since 2.0 */ @@ -37,7 +39,8 @@ public class ExecutionException extends RuntimeException { /** * 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 */ diff --git a/src/main/java/teetime/framework/ExecutionInstantiation.java b/src/main/java/teetime/framework/ExecutionInstantiation.java deleted file mode 100644 index 90a1473cadb0d91a90b0c7fb049f2e906b28c88c..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/ExecutionInstantiation.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * 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; - } - - } - -} diff --git a/src/main/java/teetime/framework/IntraStageCollector.java b/src/main/java/teetime/framework/IntraStageCollector.java index 7ece0d1468b7e6f4e3c5b0f011aab2346560a47f..2b8680b6d701ca34e6a40068498ef94889254f2f 100644 --- a/src/main/java/teetime/framework/IntraStageCollector.java +++ b/src/main/java/teetime/framework/IntraStageCollector.java @@ -29,7 +29,7 @@ public class IntraStageCollector implements ITraverserVisitor { @Override 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 */) { return VisitorBehavior.CONTINUE; } diff --git a/src/main/java/teetime/framework/MonitoringThread.java b/src/main/java/teetime/framework/MonitoringThread.java index c517db8ca643f80c4a0d398edd90d90eae94a602..85246bed6d0784cc3b2f9c23d0a72bbf2fe71f2e 100644 --- a/src/main/java/teetime/framework/MonitoringThread.java +++ b/src/main/java/teetime/framework/MonitoringThread.java @@ -42,9 +42,11 @@ public class MonitoringThread extends Thread { final long pullThroughput = pipe.getPullThroughput(); final double ratio = (double) pushThroughput / pullThroughput; - LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio)); - LOGGER.info("pushes: " + pushThroughput); - LOGGER.info("pulls: " + pullThroughput); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("pipe: " + "size=" + pipe.size() + ", " + "ratio: " + String.format("%.1f", ratio)); + LOGGER.info("pushes: " + pushThroughput); + LOGGER.info("pulls: " + pullThroughput); + } } LOGGER.info("------------------------------------"); diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java index 366604f380ab44582e8de64f752b39605582b234..e8df8e84320bf50fd5b8c2abd409cd6d4d2aa0e8 100644 --- a/src/main/java/teetime/framework/OutputPort.java +++ b/src/main/java/teetime/framework/OutputPort.java @@ -59,7 +59,8 @@ public class OutputPort<T> extends AbstractPort<T> { * @param element * 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 */ diff --git a/src/main/java/teetime/framework/ThreadService.java b/src/main/java/teetime/framework/ThreadService.java index 2df4b165836378ddb227a82b57bc5cfa62447357..021898997c2c52a3b0c87bfd7c2f74d8a03503dc 100644 --- a/src/main/java/teetime/framework/ThreadService.java +++ b/src/main/java/teetime/framework/ThreadService.java @@ -75,8 +75,6 @@ class ThreadService extends AbstractService<ThreadService> { 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(); Traverser traversor = new Traverser(stageCollector, Direction.BOTH); traversor.traverse(startStage);