diff --git a/pom.xml b/pom.xml index 3fe66f56c8c4637e06ecb539b1e3c21ef9fca3e0..312e29c9739b9d174f7b968a7c685dbc5ec6e50e 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>17.0</version> + <version>18.0</version> </dependency> <dependency> <groupId>org.jctools</groupId> diff --git a/src/main/java/teetime/framework/Analysis.java b/src/main/java/teetime/framework/Analysis.java index 6b451cc10a83d64e5655cc0a9bbb327b2e58934c..bd198247ff69cd650822632ae89044030b23532e 100644 --- a/src/main/java/teetime/framework/Analysis.java +++ b/src/main/java/teetime/framework/Analysis.java @@ -35,7 +35,7 @@ import teetime.util.Pair; * To start the analysis {@link #init()} and {@link #start()} need to be executed in this order. * This class will automatically create threads and join them without any further commitment. */ -public class Analysis implements UncaughtExceptionHandler { +public final class Analysis implements UncaughtExceptionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(Analysis.class); diff --git a/src/main/java/teetime/framework/AnalysisConfiguration.java b/src/main/java/teetime/framework/AnalysisConfiguration.java index 62909734d9989691dbd64cf25906f1a55a026618..ef5ae8a4bd7df6c67d878c709bba15dfcf039455 100644 --- a/src/main/java/teetime/framework/AnalysisConfiguration.java +++ b/src/main/java/teetime/framework/AnalysisConfiguration.java @@ -24,7 +24,7 @@ import teetime.framework.pipe.PipeFactoryRegistry; * Represents a configuration of connected stages, which is needed to run a analysis. * Stages can be added by executing {@link #addThreadableStage(Stage)}. */ -public class AnalysisConfiguration { +public abstract class AnalysisConfiguration { protected static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE; private final List<Stage> threadableStageJobs = new LinkedList<Stage>(); diff --git a/src/main/java/teetime/framework/CompositeStage.java b/src/main/java/teetime/framework/CompositeStage.java index 556f6fd77438c2010f8aa6624f01fce89cf0b654..4765fe8732ddd8673de456815fc0d1e410208bf8 100644 --- a/src/main/java/teetime/framework/CompositeStage.java +++ b/src/main/java/teetime/framework/CompositeStage.java @@ -18,6 +18,10 @@ package teetime.framework; import java.util.Collection; import java.util.List; +import teetime.framework.pipe.IPipeFactory; +import teetime.framework.pipe.PipeFactoryRegistry; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.signal.ISignal; import teetime.framework.validation.InvalidPortConnection; @@ -25,12 +29,15 @@ import teetime.framework.validation.InvalidPortConnection; * Represents a minimal stage that composes several other stages. * * @since 1.1 - * @author Christian Wulf + * @author Christian Wulf, Nelson Tavares de Sousa * */ @SuppressWarnings("PMD.AbstractNaming") public abstract class CompositeStage extends Stage { + protected static final IPipeFactory INTRA_PIPE_FACTORY = PipeFactoryRegistry.INSTANCE + .getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + protected abstract Stage getFirstStage(); protected abstract Collection<? extends Stage> getLastStages(); @@ -81,4 +88,14 @@ public abstract class CompositeStage extends Stage { return isStarted; } + @Override + void setOwningThread(final Thread owningThread) { + getFirstStage().setOwningThread(owningThread); + super.setOwningThread(owningThread); + } + + protected static <T> void connectStages(final OutputPort<? extends T> out, final InputPort<T> in) { + INTRA_PIPE_FACTORY.create(out, in); + } + } diff --git a/src/main/java/teetime/framework/RunnableConsumerStage.java b/src/main/java/teetime/framework/RunnableConsumerStage.java index fd0bff4a6bb307e17db64fb9cf06dac79a6f8120..035ddfc679d8584f32bfc7533fc167ec79039b82 100644 --- a/src/main/java/teetime/framework/RunnableConsumerStage.java +++ b/src/main/java/teetime/framework/RunnableConsumerStage.java @@ -81,7 +81,7 @@ final class RunnableConsumerStage extends AbstractRunnableStage { final Stage stage = this.stage; for (InputPort<?> inputPort : inputPorts) { final IPipe pipe = inputPort.getPipe(); - if (pipe instanceof AbstractInterThreadPipe) { + if (pipe instanceof AbstractInterThreadPipe) { // TODO: is this needed? final AbstractInterThreadPipe intraThreadPipe = (AbstractInterThreadPipe) pipe; final ISignal signal = intraThreadPipe.getSignal(); if (null != signal) { diff --git a/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java b/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java index 52f70fc1e4e7f75c16c2505494c03f3db41d7ef4..85bb67e7593e1dcbdcc6d5c2179e33a9e46c4a3e 100644 --- a/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java +++ b/src/main/java/teetime/framework/pipe/CommittablePipeFactory.java @@ -20,7 +20,7 @@ import teetime.framework.OutputPort; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -public class CommittablePipeFactory implements IPipeFactory { +public final class CommittablePipeFactory implements IPipeFactory { @Override public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { diff --git a/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java b/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java index 6ea8d759a7d0e2be0947390949dd384769e386d1..6f2f1ee6b5b833aec521e718567bb8bc5ead5eca 100644 --- a/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java +++ b/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java @@ -15,7 +15,7 @@ */ package teetime.framework.pipe; -public class CouldNotFindPipeImplException extends RuntimeException { +public final class CouldNotFindPipeImplException extends RuntimeException { private static final long serialVersionUID = 5242260988104493402L; diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java index 21a88a9c3d2a24a30e8209130362f392f90bf079..bd65862ff7b4118441aca4ce1b22d7d1cabbd828 100644 --- a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java +++ b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java @@ -20,7 +20,7 @@ import teetime.framework.OutputPort; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -public class OrderedGrowableArrayPipeFactory implements IPipeFactory { +public final class OrderedGrowableArrayPipeFactory implements IPipeFactory { @Override public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { diff --git a/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java b/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java index 830a25d13c7338408fb8d629d305b3ccf38609bb..e8a1a7af9bf188360dc3577c5583704384c7f5c6 100644 --- a/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java +++ b/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java @@ -20,7 +20,7 @@ import teetime.framework.OutputPort; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -public class SingleElementPipeFactory implements IPipeFactory { +public final class SingleElementPipeFactory implements IPipeFactory { @Override public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { diff --git a/src/main/java/teetime/framework/pipe/SpScPipeFactory.java b/src/main/java/teetime/framework/pipe/SpScPipeFactory.java index 035d789da1ec94a640ccdaddd6a0b9efafa878fa..d36f76b3e103a2d65840647ca74708b987a416ea 100644 --- a/src/main/java/teetime/framework/pipe/SpScPipeFactory.java +++ b/src/main/java/teetime/framework/pipe/SpScPipeFactory.java @@ -20,7 +20,7 @@ import teetime.framework.OutputPort; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -public class SpScPipeFactory implements IPipeFactory { +public final class SpScPipeFactory implements IPipeFactory { @Override public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { diff --git a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java index 9eb081c9ea376f9ca42727e77baf3cce51583172..a3d1c80226fdddacab82a7af8f3c0dea306294c6 100644 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java +++ b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java @@ -20,7 +20,7 @@ import teetime.framework.OutputPort; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -public class UnorderedGrowablePipeFactory implements IPipeFactory { +public final class UnorderedGrowablePipeFactory implements IPipeFactory { @Override public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { diff --git a/src/main/java/teetime/framework/signal/StartingSignal.java b/src/main/java/teetime/framework/signal/StartingSignal.java index 5e10fcc0c18155b5c2f850c5aeeead53edaae62a..646443bec562e3a3bcb7851a6f707accee9e3a59 100644 --- a/src/main/java/teetime/framework/signal/StartingSignal.java +++ b/src/main/java/teetime/framework/signal/StartingSignal.java @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; import teetime.framework.AbstractStage; -public class StartingSignal implements ISignal { +public final class StartingSignal implements ISignal { private static final Logger LOGGER = LoggerFactory.getLogger(StartingSignal.class); private final List<Exception> catchedExceptions = new LinkedList<Exception>(); diff --git a/src/main/java/teetime/framework/signal/TerminatingSignal.java b/src/main/java/teetime/framework/signal/TerminatingSignal.java index 52d5be48e4eb323f52fe43887a73fa14db23f0de..d43f21f35741aeba9672a4f0b4e2395106fd5045 100644 --- a/src/main/java/teetime/framework/signal/TerminatingSignal.java +++ b/src/main/java/teetime/framework/signal/TerminatingSignal.java @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; import teetime.framework.AbstractStage; -public class TerminatingSignal implements ISignal { +public final class TerminatingSignal implements ISignal { private static final Logger LOGGER = LoggerFactory.getLogger(TerminatingSignal.class); private final List<Exception> catchedExceptions = new LinkedList<Exception>(); diff --git a/src/main/java/teetime/framework/signal/ValidatingSignal.java b/src/main/java/teetime/framework/signal/ValidatingSignal.java index e351cbacbcd4be214cd29b60b474a1c5dd54a662..51757ca295094a635e37d28df0cf0aee2823d0b7 100644 --- a/src/main/java/teetime/framework/signal/ValidatingSignal.java +++ b/src/main/java/teetime/framework/signal/ValidatingSignal.java @@ -21,7 +21,7 @@ import java.util.List; import teetime.framework.AbstractStage; import teetime.framework.validation.InvalidPortConnection; -public class ValidatingSignal implements ISignal { +public final class ValidatingSignal implements ISignal { private final List<InvalidPortConnection> invalidPortConnections = new LinkedList<InvalidPortConnection>(); diff --git a/src/main/java/teetime/stage/ByteArray2String.java b/src/main/java/teetime/stage/ByteArray2String.java index 8bd6234cd99ee1fddbe84d55d4db4c22eeee396e..aa9ca7264f134c38c003fdfd5924327c240d1285 100644 --- a/src/main/java/teetime/stage/ByteArray2String.java +++ b/src/main/java/teetime/stage/ByteArray2String.java @@ -20,7 +20,7 @@ import java.nio.charset.Charset; import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; -public class ByteArray2String extends AbstractConsumerStage<byte[]> { +public final class ByteArray2String extends AbstractConsumerStage<byte[]> { private final OutputPort<String> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/Cache.java b/src/main/java/teetime/stage/Cache.java index a3562e520d777b9d05d971de9c1c68561f498e34..392fcd7968da493f3af24328c124fa96f3be2818 100644 --- a/src/main/java/teetime/stage/Cache.java +++ b/src/main/java/teetime/stage/Cache.java @@ -23,7 +23,7 @@ import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; import teetime.util.StopWatch; -public class Cache<T> extends AbstractConsumerStage<T> { +public final class Cache<T> extends AbstractConsumerStage<T> { private final OutputPort<T> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/CipherByteArray.java b/src/main/java/teetime/stage/CipherByteArray.java index 1dfaab158173b7706a4843d7a3a7d3de168d1fae..ea8c4fb26c82f0670da9de0017f5b5b24ac4676e 100644 --- a/src/main/java/teetime/stage/CipherByteArray.java +++ b/src/main/java/teetime/stage/CipherByteArray.java @@ -30,7 +30,7 @@ import javax.crypto.spec.SecretKeySpec; import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; -public class CipherByteArray extends AbstractConsumerStage<byte[]> { +public final class CipherByteArray extends AbstractConsumerStage<byte[]> { private final OutputPort<byte[]> outputPort = this.createOutputPort(); private Cipher cipher = null; diff --git a/src/main/java/teetime/stage/Clock.java b/src/main/java/teetime/stage/Clock.java index 502121fbc4a67610d258c52c4db98dddfafd9d95..27d35ab4ad031eec283ce97a72469779ce908430 100644 --- a/src/main/java/teetime/stage/Clock.java +++ b/src/main/java/teetime/stage/Clock.java @@ -18,7 +18,7 @@ package teetime.stage; import teetime.framework.AbstractProducerStage; import teetime.framework.TerminationStrategy; -public class Clock extends AbstractProducerStage<Long> { +public final class Clock extends AbstractProducerStage<Long> { private boolean initialDelayExceeded = false; diff --git a/src/main/java/teetime/stage/Counter.java b/src/main/java/teetime/stage/Counter.java index bcc54f1cf6274a839d26d9b5812d64c90e2cb5b3..0808f85c115b0d410f194c27396417c4428075a3 100644 --- a/src/main/java/teetime/stage/Counter.java +++ b/src/main/java/teetime/stage/Counter.java @@ -18,7 +18,7 @@ package teetime.stage; import teetime.framework.AbstractConsumerStage; import teetime.framework.OutputPort; -public class Counter<T> extends AbstractConsumerStage<T> { +public final class Counter<T> extends AbstractConsumerStage<T> { private final OutputPort<T> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/CountingMapMerger.java b/src/main/java/teetime/stage/CountingMapMerger.java new file mode 100644 index 0000000000000000000000000000000000000000..22a5bb1b71451a844654e16711e1330f90b97357 --- /dev/null +++ b/src/main/java/teetime/stage/CountingMapMerger.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import teetime.framework.AbstractConsumerStage; +import teetime.framework.OutputPort; +import teetime.stage.util.CountingMap; + +/** + * Receives different CountingMap instances and merges them into a single one. + * The result is sent upon termination. + * + * @since 1.1 + * + * @author Nelson Tavares de Sousa + * + * @param <T> + * Key type of the map to be sent + */ +public final class CountingMapMerger<T> extends AbstractConsumerStage<CountingMap<T>> { + + private final CountingMap<T> result = new CountingMap<T>(); + private final OutputPort<Map<T, Integer>> port = createOutputPort(); + + @Override + protected void execute(final CountingMap<T> element) { + Set<Map.Entry<T, Integer>> entries = element.entrySet(); + for (Entry<T, Integer> entry : entries) { + result.add(entry.getKey(), entry.getValue()); + } + } + + @Override + public void onTerminating() throws Exception { + port.send(result); + super.onTerminating(); + } + + public CountingMap<T> getResult() { + return result; + } + +} diff --git a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java b/src/main/java/teetime/stage/ElementDelayMeasuringStage.java index 1769482d7ff344152663c5e5f9927fcf370094f4..5777aebb0daf4ca50a466ddf0fc83c4235c68128 100644 --- a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java +++ b/src/main/java/teetime/stage/ElementDelayMeasuringStage.java @@ -22,7 +22,7 @@ import teetime.framework.AbstractConsumerStage; import teetime.framework.InputPort; import teetime.framework.OutputPort; -public class ElementDelayMeasuringStage<T> extends AbstractConsumerStage<T> { +public final class ElementDelayMeasuringStage<T> extends AbstractConsumerStage<T> { private final InputPort<Long> triggerInputPort = this.createInputPort(); private final OutputPort<T> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java b/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java index 923941317a99fbd0407ebeee6570c723d78915ae..a986ed8ef9e647ebd181afc621c11cef15f14482 100644 --- a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java +++ b/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java @@ -23,7 +23,7 @@ import teetime.framework.AbstractConsumerStage; import teetime.framework.InputPort; import teetime.framework.OutputPort; -public class ElementThroughputMeasuringStage<T> extends AbstractConsumerStage<T> { +public final class ElementThroughputMeasuringStage<T> extends AbstractConsumerStage<T> { private final InputPort<Long> triggerInputPort = this.createInputPort(); private final OutputPort<T> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/InitialElementProducer.java b/src/main/java/teetime/stage/InitialElementProducer.java index 4cc172052248e066509506e01a1d74a977a0195e..733d3be8aeef1404520f9d8a24166ff4d70b973e 100644 --- a/src/main/java/teetime/stage/InitialElementProducer.java +++ b/src/main/java/teetime/stage/InitialElementProducer.java @@ -17,7 +17,7 @@ package teetime.stage; import teetime.framework.AbstractProducerStage; -public class InitialElementProducer<T> extends AbstractProducerStage<T> { +public final class InitialElementProducer<T> extends AbstractProducerStage<T> { private final T[] elements; diff --git a/src/main/java/teetime/stage/MappingCounter.java b/src/main/java/teetime/stage/MappingCounter.java new file mode 100644 index 0000000000000000000000000000000000000000..ee9ab91800c2124003501b3a0a15e4e9e9deadc4 --- /dev/null +++ b/src/main/java/teetime/stage/MappingCounter.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage; + +import teetime.framework.AbstractConsumerStage; +import teetime.framework.OutputPort; +import teetime.stage.util.CountingMap; + +/** + * This counts how many of different elements are sent to this stage. Nothing is forwarded. + * On termination a CountingMap is sent to its outputport. + * + * @since 1.1 + * + * @author Nelson Tavares de Sousa + * + * @param <T> + * Type to be count + */ +public final class MappingCounter<T> extends AbstractConsumerStage<T> { + + private final CountingMap<T> counter = new CountingMap<T>(); + private final OutputPort<CountingMap<T>> port = createOutputPort(); + + public MappingCounter() { + + } + + @Override + protected void execute(final T element) { + counter.increment(element); + + } + + @Override + public void onTerminating() throws Exception { + port.send(counter); + super.onTerminating(); + } + + public OutputPort<CountingMap<T>> getOutputPort() { + return port; + } + +} diff --git a/src/main/java/teetime/stage/basic/merger/Merger.java b/src/main/java/teetime/stage/basic/merger/Merger.java index 10c5f4f23a692edc5e2c1b202e38e899d42f5a3d..739574e8787bb3dbdefd5a3879240330fe788f1b 100644 --- a/src/main/java/teetime/stage/basic/merger/Merger.java +++ b/src/main/java/teetime/stage/basic/merger/Merger.java @@ -30,7 +30,7 @@ import teetime.framework.signal.ISignal; * This stage merges data from the input ports, by taking elements according to the chosen merge strategy and by putting them to the output port. * For its signal handling behavior see {@link #onSignal(ISignal, InputPort)} * - * @author Christian Wulf + * @author Christian Wulf, Nelson Tavares de Sousa * * @since 1.0 * @@ -43,7 +43,7 @@ public final class Merger<T> extends AbstractStage { private IMergerStrategy strategy; - private final Map<Class<?>, Set<InputPort<?>>> signalMap = new HashMap<Class<?>, Set<InputPort<?>>>(); + private final Map<Class<ISignal>, Set<InputPort<?>>> signalMap = new HashMap<Class<ISignal>, Set<InputPort<?>>>(); public Merger() { this(new RoundRobinStrategy()); @@ -74,25 +74,29 @@ public final class Merger<T> extends AbstractStage { * @param inputPort * The port which the signal was sent to */ + @SuppressWarnings("unchecked") @Override public void onSignal(final ISignal signal, final InputPort<?> inputPort) { - this.logger.trace("Got signal: " + signal + " from input port: " + inputPort); + this.logger.warn("Got signal: " + signal + " from input port: " + inputPort); - if (signalMap.containsKey(signal.getClass())) { - Set<InputPort<?>> set = signalMap.get(signal.getClass()); + Class<? extends ISignal> signalClass = signal.getClass(); + + if (signalMap.containsKey(signalClass)) { + Set<InputPort<?>> set = signalMap.get(signalClass); if (!set.add(inputPort)) { this.logger.warn("Received more than one signal - " + signal + " - from input port: " + inputPort); } - if (set.size() == this.getInputPorts().length) { - this.outputPort.sendSignal(signal); - signalMap.remove(signal.getClass()); - } } else { - signal.trigger(this); Set<InputPort<?>> tempSet = new HashSet<InputPort<?>>(); tempSet.add(inputPort); - signalMap.put(signal.getClass(), tempSet); + signalMap.put((Class<ISignal>) signalClass, tempSet); + } + + if (signalMap.get(signalClass).size() == this.getInputPorts().length) { + signal.trigger(this); + this.outputPort.sendSignal(signal); + signalMap.remove(signalClass); } } diff --git a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java index b7a3d048c699c5d2970df566d02385edd996f59d..66bb89cb8366c323abacc3e26e602deafd900a72 100644 --- a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java +++ b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java @@ -23,7 +23,7 @@ import teetime.framework.AbstractConsumerStage; import com.google.common.io.Files; -public class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { +public final class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { private final File file; private FileOutputStream fo; diff --git a/src/main/java/teetime/stage/io/Directory2FilesFilter.java b/src/main/java/teetime/stage/io/Directory2FilesFilter.java index 4833b3ec149a7c448fa21b79e56dd6dc68ccf032..c306b236a5e57abf0f21aa20c23961e8e150bbe5 100644 --- a/src/main/java/teetime/stage/io/Directory2FilesFilter.java +++ b/src/main/java/teetime/stage/io/Directory2FilesFilter.java @@ -28,7 +28,7 @@ import teetime.framework.OutputPort; * * @since 1.10 */ -public class Directory2FilesFilter extends AbstractConsumerStage<File> { +public final class Directory2FilesFilter extends AbstractConsumerStage<File> { private final OutputPort<File> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/io/EveryXthPrinter.java b/src/main/java/teetime/stage/io/EveryXthPrinter.java index eee5f2285f9d3bc01af18c25c49c0eedb1865a62..4fd4b539ba2e24ae32eba88e132e0505e1d81a6b 100644 --- a/src/main/java/teetime/stage/io/EveryXthPrinter.java +++ b/src/main/java/teetime/stage/io/EveryXthPrinter.java @@ -15,43 +15,38 @@ */ package teetime.stage.io; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import teetime.framework.CompositeStage; import teetime.framework.InputPort; import teetime.framework.OutputPort; import teetime.framework.Stage; import teetime.framework.TerminationStrategy; -import teetime.framework.pipe.IPipeFactory; -import teetime.framework.pipe.PipeFactoryRegistry; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.signal.ISignal; import teetime.framework.validation.InvalidPortConnection; import teetime.stage.EveryXthStage; import teetime.stage.basic.distributor.CopyByReferenceStrategy; import teetime.stage.basic.distributor.Distributor; -public final class EveryXthPrinter<T> extends Stage { +public final class EveryXthPrinter<T> extends CompositeStage { private final Distributor<T> distributor; + private final List<Stage> lastStages = new ArrayList<Stage>(); public EveryXthPrinter(final int threshold) { distributor = new Distributor<T>(); EveryXthStage<T> everyXthStage = new EveryXthStage<T>(threshold); Printer<Integer> printer = new Printer<Integer>(); - IPipeFactory pipeFactory = PipeFactoryRegistry.INSTANCE.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); - pipeFactory.create(distributor.getNewOutputPort(), everyXthStage.getInputPort()); - pipeFactory.create(everyXthStage.getOutputPort(), printer.getInputPort()); + connectStages(distributor.getNewOutputPort(), everyXthStage.getInputPort()); + connectStages(everyXthStage.getOutputPort(), printer.getInputPort()); + lastStages.add(printer); distributor.setStrategy(new CopyByReferenceStrategy()); } - @Override - protected void executeWithPorts() { - distributor.executeWithPorts(); - } - @Override public void validateOutputPorts(final List<InvalidPortConnection> invalidPortConnections) { distributor.validateOutputPorts(invalidPortConnections); @@ -95,4 +90,14 @@ public final class EveryXthPrinter<T> extends Stage { return distributor.isStarted(); } + @Override + protected Stage getFirstStage() { + return distributor; + } + + @Override + protected Collection<? extends Stage> getLastStages() { + return lastStages; + } + } diff --git a/src/main/java/teetime/stage/io/File2ByteArray.java b/src/main/java/teetime/stage/io/File2ByteArray.java index db1942d57293a0b959ef699d1b00e58953470073..155a45a31a7581d5fb77553afdf9461471976f6f 100644 --- a/src/main/java/teetime/stage/io/File2ByteArray.java +++ b/src/main/java/teetime/stage/io/File2ByteArray.java @@ -23,7 +23,7 @@ import teetime.framework.OutputPort; import com.google.common.io.Files; -public class File2ByteArray extends AbstractConsumerStage<File> { +public final class File2ByteArray extends AbstractConsumerStage<File> { private final OutputPort<byte[]> outputPort = this.createOutputPort(); @@ -41,13 +41,4 @@ public class File2ByteArray extends AbstractConsumerStage<File> { return this.outputPort; } - @Override - public boolean shouldBeTerminated() { - return false; - } - - @Override - public void terminate() { - - } } diff --git a/src/main/java/teetime/stage/io/File2TextLinesFilter.java b/src/main/java/teetime/stage/io/File2TextLinesFilter.java index 609232d90992486265f55ada9bc39dc63e6e52dd..977fef59d491ea0a2663171537a25d33209ce1cf 100644 --- a/src/main/java/teetime/stage/io/File2TextLinesFilter.java +++ b/src/main/java/teetime/stage/io/File2TextLinesFilter.java @@ -30,7 +30,7 @@ import teetime.stage.util.TextLine; * @author Christian Wulf * */ -public class File2TextLinesFilter extends AbstractConsumerStage<File> { +public final class File2TextLinesFilter extends AbstractConsumerStage<File> { private final OutputPort<TextLine> outputPort = this.createOutputPort(); diff --git a/src/main/java/teetime/stage/io/Printer.java b/src/main/java/teetime/stage/io/Printer.java index 3aacc3b096fc621a11487c76d8e351abfbf0164b..bd36983163775b5ce6e3b027e58d262da59449fe 100644 --- a/src/main/java/teetime/stage/io/Printer.java +++ b/src/main/java/teetime/stage/io/Printer.java @@ -29,7 +29,7 @@ import teetime.framework.AbstractConsumerStage; * * @since 1.10 */ -public class Printer<T> extends AbstractConsumerStage<T> { +public final class Printer<T> extends AbstractConsumerStage<T> { public static final String STREAM_STDOUT = "STDOUT"; public static final String STREAM_STDERR = "STDERR"; diff --git a/src/main/java/teetime/stage/string/ToLowerCase.java b/src/main/java/teetime/stage/string/ToLowerCase.java new file mode 100644 index 0000000000000000000000000000000000000000..ee32c2bda2396cd81ece31fb68ce350387e02c13 --- /dev/null +++ b/src/main/java/teetime/stage/string/ToLowerCase.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage.string; + +import teetime.framework.AbstractConsumerStage; +import teetime.framework.OutputPort; + +/** + * Receives a string and passes it on to the next stage only with lower case letters. + * Punctuation and similar characters will be removed. Only [a-zA-Z ] will be passed on. + * + * @since 1.1 + * + * @author Nelson Tavares de Sousa + * + */ +public final class ToLowerCase extends AbstractConsumerStage<String> { + + private final OutputPort<String> outputPort = this.createOutputPort(); + + @Override + protected void execute(final String element) { + outputPort.send(element.replaceAll("[^a-zA-Z ]", "").toLowerCase()); + + } + + public OutputPort<String> getOutputPort() { + return outputPort; + } + +} diff --git a/src/main/java/teetime/stage/string/WordCounter.java b/src/main/java/teetime/stage/string/WordCounter.java new file mode 100644 index 0000000000000000000000000000000000000000..9f26beee3e9093c3ec35d954abd3e29e896f5c49 --- /dev/null +++ b/src/main/java/teetime/stage/string/WordCounter.java @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage.string; + +import java.util.ArrayList; +import java.util.Collection; + +import teetime.framework.CompositeStage; +import teetime.framework.InputPort; +import teetime.framework.OutputPort; +import teetime.framework.Stage; +import teetime.stage.MappingCounter; +import teetime.stage.util.CountingMap; + +/** + * Intermediate stage, which receives texts and counts the occurring words. + * The result (a {@link CountingMap}) is passed on upon termination. + * + * @since 1.1 + * + * @author Nelson Tavares de Sousa + * + */ +public final class WordCounter extends CompositeStage { + + // This fields are needed for the methods to work. + private final Tokenizer tokenizer = new Tokenizer(" "); + private final MappingCounter<String> mapCounter = new MappingCounter<String>(); + private final ArrayList<Stage> lastStages = new ArrayList<Stage>(); + + // The connection of the different stages is realized within the construction of a instance of this class. + public WordCounter() { + lastStages.add(mapCounter); + + ToLowerCase toLowerCase = new ToLowerCase(); + connectStages(tokenizer.getOutputPort(), toLowerCase.getInputPort()); + connectStages(toLowerCase.getOutputPort(), mapCounter.getInputPort()); + } + + @Override + protected Stage getFirstStage() { + return tokenizer; + } + + @Override + protected Collection<? extends Stage> getLastStages() { + return lastStages; + } + + public InputPort<String> getInputPort() { + return tokenizer.getInputPort(); + } + + public OutputPort<CountingMap<String>> getOutputPort() { + return mapCounter.getOutputPort(); + } + +} diff --git a/src/main/java/teetime/stage/util/CountingMap.java b/src/main/java/teetime/stage/util/CountingMap.java new file mode 100644 index 0000000000000000000000000000000000000000..e468acaca4ba9dd39260947823e3a039626233a8 --- /dev/null +++ b/src/main/java/teetime/stage/util/CountingMap.java @@ -0,0 +1,72 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage.util; + +import java.util.HashMap; + +/** + * An implementation of HashMap which can be used to count the occurrence of different keys. + * This conaitns all methods of HashMap, but is enhanched with the {@link #add(T, Integer)} and {@link #increment(T)} methods. + * + * @since 1.1 + * + * @author Nelson Tavares de Sousa + * + * @param <T> + * Key type to be count + */ +public final class CountingMap<T> extends HashMap<T, Integer> { + + /** + * Generated serialVersionUID + */ + private static final long serialVersionUID = -8036971796701648200L; + + /** + * Increments the value of key by one. + * + * @param key + * The key which sould be incremented + */ + public void increment(final T key) { + if (super.containsKey(key)) { + Integer i = super.get(key); + i++; + super.put(key, i); + } else { + super.put(key, 1); + } + } + + /** + * Adds i to the value of key. + * + * @param key + * Key which is used to add i. + * @param i + * Integer value to be added. + */ + public void add(final T key, final Integer i) { + if (super.containsKey(key)) { + Integer j = super.get(key); + j += i; + super.put(key, j); + } else { + super.put(key, i); + } + } + +} diff --git a/src/main/java/teetime/stage/util/MappingException.java b/src/main/java/teetime/stage/util/MappingException.java index 8761af48bf3bbc8bf06225372a1d174b46d0173d..456b61911d730afea1d6f85f194210956776b238 100644 --- a/src/main/java/teetime/stage/util/MappingException.java +++ b/src/main/java/teetime/stage/util/MappingException.java @@ -20,7 +20,7 @@ package teetime.stage.util; * * @since 1.10 */ -public class MappingException extends Exception { +public final class MappingException extends Exception { private static final long serialVersionUID = 7300752837946139350L; diff --git a/src/main/java/teetime/stage/util/TextLine.java b/src/main/java/teetime/stage/util/TextLine.java index e9ddbd6f756490376025a910ce6add12e08004aa..ecbfdb3295b8d36bb8998c006740d8b0e25cc1a1 100644 --- a/src/main/java/teetime/stage/util/TextLine.java +++ b/src/main/java/teetime/stage/util/TextLine.java @@ -22,7 +22,7 @@ import java.io.File; * * @since 1.10 */ -public class TextLine { +public final class TextLine { private final File textFile; private final String textLine; diff --git a/src/main/java/teetime/util/CyclicListIterator.java b/src/main/java/teetime/util/CyclicListIterator.java index 9611fcb2186771d752c57fc7bb7fa5a3a5e928bd..d4e06d27453bc453c631419f61fd05c113e32a63 100644 --- a/src/main/java/teetime/util/CyclicListIterator.java +++ b/src/main/java/teetime/util/CyclicListIterator.java @@ -20,12 +20,12 @@ import java.util.List; /** * This iterator infinitely iterates over a list and allows the list to be modified without throwing a <code>ConcurrentMOdificationException</code>. - * + * * @author Christian Wulf - * + * * @param <T> */ -public class CyclicListIterator<T> implements Iterator<T> { +public final class CyclicListIterator<T> implements Iterator<T> { private final List<T> list; // private Iterator<T> iterator; @@ -37,10 +37,12 @@ public class CyclicListIterator<T> implements Iterator<T> { // this.iterator = this.list.iterator(); } + @Override public boolean hasNext() { return true; } + @Override public T next() { // if (!this.iterator.hasNext()) { // this.iterator = this.list.iterator(); @@ -56,6 +58,7 @@ public class CyclicListIterator<T> implements Iterator<T> { return element; } + @Override public void remove() { // this.iterator.remove(); this.currentIndex = this.getCurrentIndex(); diff --git a/src/main/java/teetime/util/HashMapWithDefault.java b/src/main/java/teetime/util/HashMapWithDefault.java index f5797cf0f9dde6292a674ed6f78db860fd7d2106..7ebf6eb5c975ca044d283f47197bbb6aa961f19e 100644 --- a/src/main/java/teetime/util/HashMapWithDefault.java +++ b/src/main/java/teetime/util/HashMapWithDefault.java @@ -21,10 +21,10 @@ import teetime.util.concurrent.hashmap.ValueFactory; /** * @author Christian Wulf - * + * * @since 1.10 */ -public class HashMapWithDefault<K, V> extends HashMap<K, V> { +public final class HashMapWithDefault<K, V> extends HashMap<K, V> { private static final long serialVersionUID = -7958038532219740472L; diff --git a/src/main/java/teetime/util/Pair.java b/src/main/java/teetime/util/Pair.java index 1d671fbf6b7a34a4ad84f63f3d535a40800f9d7f..1cffdbf11c23a6c49b3fffad5fcca024543e8137 100644 --- a/src/main/java/teetime/util/Pair.java +++ b/src/main/java/teetime/util/Pair.java @@ -15,7 +15,7 @@ */ package teetime.util; -public class Pair<F, S> { +public final class Pair<F, S> { private final F first; private final S second; diff --git a/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java b/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java index 13eeaa12aba27af3779c1791fb676fb2e2ffccc7..6e1ec99f49d35703aff8aed6289da3c1fb7a55fc 100644 --- a/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java +++ b/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java @@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentMap; * @author Christian Wulf * @since 1.11 */ -public class CachedClassForNameResolver<T> { +public final class CachedClassForNameResolver<T> { private final ConcurrentMap<String, Class<? extends T>> cachedClasses = new ConcurrentHashMap<String, Class<? extends T>>(); // NOCS private final ClassForNameResolver<T> classForNameResolver; diff --git a/src/main/java/teetime/util/classpath/ClassForNameResolver.java b/src/main/java/teetime/util/classpath/ClassForNameResolver.java index 680ea6af094f4975e0cd4f1844754214768ac66e..d084779936f2f75a954606f39a87dd44b0f253d4 100644 --- a/src/main/java/teetime/util/classpath/ClassForNameResolver.java +++ b/src/main/java/teetime/util/classpath/ClassForNameResolver.java @@ -22,7 +22,7 @@ package teetime.util.classpath; * @author Christian Wulf * @since 1.11 */ -public class ClassForNameResolver<T> { +public final class ClassForNameResolver<T> { private final Class<T> classToCast; diff --git a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java b/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java index 5c2039598a958dc519bb3c80ece0d3cf66a23806..6c2a283fd165a1f6e57fa487b6fd6ebe17961aa8 100644 --- a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java +++ b/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java @@ -17,7 +17,7 @@ package teetime.util.concurrent.hashmap; import java.util.concurrent.ConcurrentHashMap; -public class ConcurrentHashMapWithDefault<K, V> extends ConcurrentHashMap<K, V> { +public final class ConcurrentHashMapWithDefault<K, V> extends ConcurrentHashMap<K, V> { private static final long serialVersionUID = 199185976241037967L; diff --git a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java b/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java index e1c407c7c0f43bfbdb0e853ce3f3df7f054f91b6..0d394c943bdc1de9f13c5f4d2d04b1f258e4d832 100644 --- a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java +++ b/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java @@ -17,14 +17,14 @@ package teetime.util.concurrent.hashmap; /** * @author Christian Wulf - * + * * @since 1.10 */ public interface ValueFactory<T> { /** * Create a new instance of the type <code>T</code>. - * + * * @since 1.10 */ public T create(); diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java index 285db51f49a1d655a8147e928a4bb6739e1845e8..78b1ed4783ef6fdce6c28888bfdf40f11e7d1c54 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java @@ -22,14 +22,14 @@ import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; import teetime.util.concurrent.workstealing.exception.OperationAbortedException; /** - * + * * @author Christian Wulf - * + * * @see "Dynamic Circular WorkStealing Deque" - * + * * @since 1.10 */ -public class CircularWorkStealingDeque<T> { +public final class CircularWorkStealingDeque<T> { public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); @@ -46,7 +46,7 @@ public class CircularWorkStealingDeque<T> { } /** - * + * * @param o * a non-<code>null</code> element */ @@ -66,7 +66,7 @@ public class CircularWorkStealingDeque<T> { } /** - * + * * @param elements * a non-<code>null</code> list */ @@ -91,7 +91,7 @@ public class CircularWorkStealingDeque<T> { /** * Returns and removes the latest element from this deque. - * + * * @return * <ul> * <li><code>null</code> if the deque contains no elements, @@ -123,9 +123,9 @@ public class CircularWorkStealingDeque<T> { /** * Returns and removes the latest element from this deque. - * + * * @return <i>the latest element</i>, otherwise it throws a <code>DequeIsEmptyException</code> - * + * * @throws DequeIsEmptyException */ public T popBottomEx() { @@ -169,7 +169,7 @@ public class CircularWorkStealingDeque<T> { /** * Tries to steal (return & remove) the oldest element from this deque. - * + * * @return * <ul> * <li><code>null</code> if the deque contains no elements, @@ -202,9 +202,9 @@ public class CircularWorkStealingDeque<T> { /** * Tries to steal (return & remove) the oldest element from this deque. - * + * * @return <i>the oldest element</i>, otherwise it throws a <code>DequeIsEmptyException</code> or a <code>OperationAbortedException</code> - * + * * @throws DequeIsEmptyException * @throws OperationAbortedException */ @@ -254,7 +254,7 @@ public class CircularWorkStealingDeque<T> { /** * Returns but does not remove the latest element from this deque.<br> * <i>For debugging purposes</i> - * + * * @return <ul> * <li><code>null</code> if the deque contains no elements, * <li><i>the latest element</i> otherwise @@ -286,7 +286,7 @@ public class CircularWorkStealingDeque<T> { /** * For debugging purposes - * + * * @return the number of elements this deque contains */ public long size(final Object sourceStage) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java index 9ed956de3a98c388754f8ce6a7f04d3520312c01..91554954bb79f78c2fa8eda3359d70a31fd4b030 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java @@ -20,14 +20,14 @@ import java.util.concurrent.atomic.AtomicLong; import teetime.util.concurrent.workstealing.CircularArray; /** - * + * * @author Christian Wulf - * + * * @see "Dynamic Circular WorkStealing Deque" - * + * * @since 1.10 */ -public class CircularWorkStealingDequeWithSentinel<T> { +public final class CircularWorkStealingDequeWithSentinel<T> { public static enum State { REGULAR, EMPTY, ABORT @@ -84,7 +84,7 @@ public class CircularWorkStealingDequeWithSentinel<T> { } /** - * + * * @return * <ul> * <li><code>empty()</code> if the deque contains no elements, @@ -132,7 +132,7 @@ public class CircularWorkStealingDequeWithSentinel<T> { /** * Tries to steal (return & remove) the oldest element from this deque. - * + * * @return * <ul> * <li><code>empty()</code> if the deque contains no elements, @@ -165,7 +165,7 @@ public class CircularWorkStealingDequeWithSentinel<T> { /** * For debugging purposes - * + * * @return but does not remove the bottom element from this deque */ public T readBottom() { @@ -188,7 +188,7 @@ public class CircularWorkStealingDequeWithSentinel<T> { /** * For debugging purposes - * + * * @return the number of elements this deque contains */ public long size(final Object sourceStage) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java index 41c06cd1fc1b84e2a446ae7bc03da7e7b63d4ae8..88004d4525caf2a9b76dbfa57505cb5727c43f90 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java @@ -20,14 +20,14 @@ import java.util.concurrent.atomic.AtomicLong; import teetime.util.concurrent.workstealing.CircularArray; /** - * + * * @author Christian Wulf - * + * * @see "Dynamic Circular WorkStealing Deque" - * + * * @since 1.10 */ -public class CircularWorkStealingDequeWithThreadLocalSentinel<T> { +public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> { public static enum State { REGULAR, EMPTY, ABORT @@ -96,7 +96,7 @@ public class CircularWorkStealingDequeWithThreadLocalSentinel<T> { } /** - * + * * @return * <ul> * <li><code>empty()</code> if the deque contains no elements, @@ -144,7 +144,7 @@ public class CircularWorkStealingDequeWithThreadLocalSentinel<T> { /** * Tries to steal (return & remove) the oldest element from this deque. - * + * * @return * <ul> * <li><code>empty()</code> if the deque contains no elements, @@ -189,7 +189,7 @@ public class CircularWorkStealingDequeWithThreadLocalSentinel<T> { /** * For debugging purposes - * + * * @return but does not remove the bottom element from this deque */ public T readBottom() { @@ -212,7 +212,7 @@ public class CircularWorkStealingDequeWithThreadLocalSentinel<T> { /** * For debugging purposes - * + * * @return the number of elements this deque contains */ public long size(final Object sourceStage) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java index 8cea8f0351fc92c0f415a9f011ea2da326f72717..934473cb6ad618de2bb21b0da3a60a204a358c00 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java @@ -29,7 +29,7 @@ import teetime.util.concurrent.workstealing.exception.OperationAbortedException; * * @since 1.10 */ -public class ExceptionalCircularWorkStealingDeque<T> { +public final class ExceptionalCircularWorkStealingDeque<T> { public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java index 654c5f3ca655d2b1ff20eb18c09fc235c0e83916..35aeb0b0a44a39b8bea846c4a7d68e1ebbb89438 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java @@ -20,14 +20,14 @@ import java.util.concurrent.atomic.AtomicLong; import teetime.util.concurrent.workstealing.CircularArray; /** - * + * * @author Christian Wulf - * + * * @see "Dynamic Circular WorkStealing Deque" - * + * * @since 1.10 */ -public class UntypedCircularWorkStealingDeque { +public final class UntypedCircularWorkStealingDeque { public static final Object EMPTY = new Object(); public static final Object ABORT = new Object(); @@ -64,7 +64,7 @@ public class UntypedCircularWorkStealingDeque { } /** - * + * * @return * <ul> * <li><code>EMPTY</code> if the deque contains no elements, @@ -112,7 +112,7 @@ public class UntypedCircularWorkStealingDeque { /** * Tries to steal (return & remove) the oldest element from this deque. - * + * * @return * <ul> * <li><code>EMPTY</code> if the deque contains no elements, @@ -145,7 +145,7 @@ public class UntypedCircularWorkStealingDeque { /** * For debugging purposes - * + * * @return but does not remove the bottom element from this deque */ public Object readBottom() { @@ -168,7 +168,7 @@ public class UntypedCircularWorkStealingDeque { /** * For debugging purposes - * + * * @return the number of elements this deque contains */ public long size(final Object sourceStage) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java index d1441fc5d3a009c8c5e5a1bf7b30b4e3d3e46ff9..54b5fddba22705e51bd149a5027140d65a635229 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java @@ -30,7 +30,7 @@ import teetime.util.concurrent.workstealing.exception.OperationAbortedException; * * @since 1.10 */ -public class UntypedExceptionalCircularWorkStealingDeque { +public final class UntypedExceptionalCircularWorkStealingDeque { public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java index f8ba9e517b090e6a66738a6fa32935bf1631810e..a86e479fa83af8dab3b4d32c518b98dc9347e50d 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java +++ b/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java @@ -15,6 +15,6 @@ */ package teetime.util.concurrent.workstealing.exception; -public class DequeIsEmptyException extends DequePopException { +public final class DequeIsEmptyException extends DequePopException { private static final long serialVersionUID = -6685406255103741724L; -} \ No newline at end of file +} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java index 803c7f90e19689fa9f8be2d2a6a4704a76508d37..6a640dea0a10df5ded3411d4b767ba33d8ca41d8 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java +++ b/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java @@ -15,6 +15,6 @@ */ package teetime.util.concurrent.workstealing.exception; -public class OperationAbortedException extends DequePopException { +public final class OperationAbortedException extends DequePopException { private static final long serialVersionUID = 2983001853326344073L; -} \ No newline at end of file +} diff --git a/src/main/java/teetime/util/list/ArrayPool.java b/src/main/java/teetime/util/list/ArrayPool.java index de749079874db33dc5359f1e150d50d6c6fe5027..8b66e68dba91c3b94515bb15c4b567291ff1ecac 100644 --- a/src/main/java/teetime/util/list/ArrayPool.java +++ b/src/main/java/teetime/util/list/ArrayPool.java @@ -18,7 +18,7 @@ package teetime.util.list; import java.util.HashMap; import java.util.Map; -public class ArrayPool<T> { +public final class ArrayPool<T> { // BETTER use a map with int as key due to performance private final Map<Integer, T[]> cache = new HashMap<Integer, T[]>(); diff --git a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java b/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java index f66af3d8c1d1c3c4147c4d407155e23becacbe6e..32c8a6f562c08de532b20fa50ebd820aad1046cd 100644 --- a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java +++ b/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java @@ -15,7 +15,7 @@ */ package teetime.util.list; -public class CommittableResizableArrayQueue<T> implements CommittableQueue<T> { +public final class CommittableResizableArrayQueue<T> implements CommittableQueue<T> { // private final int MIN_CAPACITY; diff --git a/src/main/java/teetime/util/list/ListContainer.java b/src/main/java/teetime/util/list/ListContainer.java index 8237ddd423b1db45858a7022f95b185502764138..623a8b035d1a5e92322a54e41a7408e597db7e3f 100644 --- a/src/main/java/teetime/util/list/ListContainer.java +++ b/src/main/java/teetime/util/list/ListContainer.java @@ -15,7 +15,7 @@ */ package teetime.util.list; -public class ListContainer<T> { +public final class ListContainer<T> { public T value; public ListContainer<T> previous; diff --git a/src/main/java/teetime/util/list/ListContainerPool.java b/src/main/java/teetime/util/list/ListContainerPool.java index 33e5435d410f1b63e5e7f3c89da29f2dd61e55ba..a71a767fec3c05c90b820db38d0d7aacfb93e315 100644 --- a/src/main/java/teetime/util/list/ListContainerPool.java +++ b/src/main/java/teetime/util/list/ListContainerPool.java @@ -18,7 +18,7 @@ package teetime.util.list; import java.util.ArrayList; import java.util.List; -public class ListContainerPool<T> implements ObjectPool<ListContainer<T>> { +public final class ListContainerPool<T> implements ObjectPool<ListContainer<T>> { private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>(); diff --git a/src/main/java/teetime/util/list/ObjectPooledLinkedList.java b/src/main/java/teetime/util/list/ObjectPooledLinkedList.java index 587d5e18422a7347a4a8167c4138679f9cba30d1..5b77af4a0627cd94207603bfeb97070eef5d0fd1 100644 --- a/src/main/java/teetime/util/list/ObjectPooledLinkedList.java +++ b/src/main/java/teetime/util/list/ObjectPooledLinkedList.java @@ -15,7 +15,7 @@ */ package teetime.util.list; -public class ObjectPooledLinkedList<T> { +public final class ObjectPooledLinkedList<T> { private final ObjectPool<ListContainer<T>> objectPool = new ListContainerPool<T>(10); @@ -31,7 +31,7 @@ public class ObjectPooledLinkedList<T> { } /** - * + * * @return <code>null</code> if the list is empty. */ public T pop() { diff --git a/src/site/markdown/download.markdown b/src/site/markdown/download.markdown index 129b8ff5192f523f1c37b120ffa2673074212f26..29d7fdbdb8542a9a7938e061de5008cc21185d73 100644 --- a/src/site/markdown/download.markdown +++ b/src/site/markdown/download.markdown @@ -76,6 +76,7 @@ Available formats: * PNG, transparent: [641 x 150px](images/teetime-transparent-150.png), [427 x 100px](images/teetime-transparent-100.png), [214 x 50px](images/teetime-transparent-50.png) * PNG, white background: [641 x 150px](images/teetime-white-150.png), [427 x 100px](images/teetime-white-100.png), [214 x 50px](images/teetime-white-50.png) -* SVG: [transparent](images/teetime-path.svg) -* PDF: +* SVG: [transparent](images/teetime-path.svg), [white background](images/teetime-path-white.svg) +* EMF: [transparent](images/teetime-path.emf), [white background](images/teetime-path-white.emf) +* PDF: [white background](images/teetime-path-white.pdf) diff --git a/src/site/markdown/wiki b/src/site/markdown/wiki index 0e4474577e1f49bc96e734c286b2d9e0363895e8..63ccbbc87bd2c0e6599ca91502149dba3cfb99de 160000 --- a/src/site/markdown/wiki +++ b/src/site/markdown/wiki @@ -1 +1 @@ -Subproject commit 0e4474577e1f49bc96e734c286b2d9e0363895e8 +Subproject commit 63ccbbc87bd2c0e6599ca91502149dba3cfb99de diff --git a/src/site/resources/images/teetime-path-white.emf b/src/site/resources/images/teetime-path-white.emf new file mode 100644 index 0000000000000000000000000000000000000000..de7003ca1d6a5d5b2c6bf528671a1fb42a947699 Binary files /dev/null and b/src/site/resources/images/teetime-path-white.emf differ diff --git a/src/site/resources/images/teetime-path-white.pdf b/src/site/resources/images/teetime-path-white.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3306bddb0e3e9c9b0f02e277b69f477f510997d6 Binary files /dev/null and b/src/site/resources/images/teetime-path-white.pdf differ diff --git a/src/site/resources/images/teetime-path-white.svg b/src/site/resources/images/teetime-path-white.svg new file mode 100644 index 0000000000000000000000000000000000000000..a4770f88f465028576e105046d4356f71a766d93 --- /dev/null +++ b/src/site/resources/images/teetime-path-white.svg @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + width="204.83498" + height="47.800724" + id="svg2" + style="background-color: white" + xml:space="preserve" + inkscape:version="0.48.5 r10040" + sodipodi:docname="teetime-path.svg"> + <rect width="100%" height="100%" style="fill:rgb(255,255,255)" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1920" + inkscape:window-height="1138" + id="namedview12" + showgrid="false" + inkscape:zoom="1.720509" + inkscape:cx="102.64606" + inkscape:cy="23.380028" + inkscape:window-x="-8" + inkscape:window-y="-8" + inkscape:window-maximized="1" + inkscape:current-layer="svg2" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /><metadata + id="metadata8"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs + id="defs6" /><g + transform="matrix(1.25,0,0,-1.25,-344.09582,402.89695)" + id="g10"><g + transform="matrix(1,0,0,-1,296.8051,284.4477)" + id="text12"><path + d="m 17.970293,-10.029023 c -1.8e-5,0.507314 -0.126844,0.8682804 -0.380479,1.0829002 -0.25367,0.2146376 -0.543093,0.3219519 -0.868271,0.3219433 l -11.5119142,0 c -5.2e-6,0.9755936 0.097553,1.85362 0.2926758,2.634082 0.1951114,0.7804739 0.5203064,1.4503756 0.9755859,2.009707 0.4552665,0.5593393 1.0471213,0.9885967 1.7755663,1.2877734 0.7284285,0.299182 1.6194628,0.4487717 2.6731052,0.4487695 0.832488,2.2e-6 1.573933,-0.068289 2.224336,-0.204873 0.650377,-0.1365795 1.212964,-0.2894211 1.687764,-0.4585254 0.47477,-0.1690985 0.865004,-0.3219401 1.170703,-0.4585254 0.305667,-0.1365785 0.536556,-0.2048695 0.692666,-0.204873 0.09104,3.5e-6 0.172337,0.022767 0.243896,0.068291 0.07153,0.045531 0.126809,0.1138217 0.16585,0.204873 0.03901,0.091058 0.06827,0.2178839 0.0878,0.3804785 0.01949,0.1626004 0.02925,0.3609694 0.02927,0.5951074 -1.7e-5,0.1691037 -0.0065,0.3154415 -0.01951,0.4390137 -0.01302,0.123576 -0.02929,0.2341423 -0.04878,0.3316992 -0.01953,0.09756 -0.05205,0.1853627 -0.09756,0.2634082 -0.04555,0.078048 -0.10408,0.1528429 -0.175606,0.2243848 -0.07156,0.0715439 -0.282936,0.1886141 -0.634131,0.35121088 -0.351226,0.1625982 -0.806499,0.32194374 -1.36582,0.4780371 C 14.32809,-0.0780468 13.680952,0.06178705 12.946024,0.18536132 12.211071,0.30893523 11.427352,0.37072228 10.594863,0.37072265 9.1509867,0.37072228 7.8859783,0.16910139 6.7998338,-0.23414062 5.7136758,-0.63738216 4.7998779,-1.2357409 4.0584374,-2.0292187 3.3169888,-2.8226924 2.7576534,-3.8177891 2.3804296,-5.0145116 2.0032011,-6.2112241 1.814588,-7.6030586 1.8145898,-9.1900193 c -1.8e-6,-1.5088957 0.1951152,-2.8649587 0.5853516,-4.0681937 0.3902315,-1.203208 0.9528188,-2.22432 1.6877636,-3.063339 0.7349366,-0.838987 1.6227188,-1.482873 2.6633495,-1.93166 1.0406172,-0.448751 2.2048152,-0.673136 3.4925975,-0.673155 1.378817,1.9e-5 2.55277,0.221152 3.521865,0.663399 0.969068,0.442283 1.765795,1.03739 2.390186,1.785322 0.624358,0.747965 1.082883,1.625991 1.375576,2.634082 0.292658,1.008118 0.438996,2.084514 0.439014,3.229189 z m -3.238946,-0.956074 c 0.03901,-1.691003 -0.334965,-3.017799 -1.121923,-3.980391 -0.786986,-0.962562 -1.954436,-1.443851 -3.502354,-1.443867 -0.7934858,1.6e-5 -1.489403,0.149606 -2.0877538,0.448769 -0.5983668,0.299196 -1.099167,0.695934 -1.5024023,1.190215 -0.4032483,0.494311 -0.7154355,1.069906 -0.9365625,1.726787 -0.2211381,0.656907 -0.3447122,1.343069 -0.3707226,2.058487 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path2990" + inkscape:connector-curvature="0" /><path + d="m 37.890352,-10.029023 c -1.8e-5,0.507314 -0.126844,0.8682804 -0.380479,1.0829002 -0.253669,0.2146376 -0.543093,0.3219519 -0.868271,0.3219433 l -11.511914,0 c -5e-6,0.9755936 0.09755,1.85362 0.292676,2.634082 0.195111,0.7804739 0.520306,1.4503756 0.975586,2.009707 0.455266,0.5593393 1.047121,0.9885967 1.775566,1.2877734 0.728429,0.299182 1.619463,0.4487717 2.673105,0.4487695 0.832489,2.2e-6 1.573933,-0.068289 2.224336,-0.204873 0.650377,-0.1365795 1.212964,-0.2894211 1.687764,-0.4585254 0.47477,-0.1690985 0.865004,-0.3219401 1.170703,-0.4585254 0.305667,-0.1365785 0.536556,-0.2048695 0.692666,-0.204873 0.09104,3.5e-6 0.172337,0.022767 0.243897,0.068291 0.07153,0.045531 0.126809,0.1138217 0.165849,0.204873 0.03901,0.091058 0.06827,0.2178839 0.0878,0.3804785 0.01949,0.1626004 0.02925,0.3609694 0.02927,0.5951074 -1.7e-5,0.1691037 -0.0065,0.3154415 -0.01951,0.4390137 -0.01302,0.123576 -0.02929,0.2341423 -0.04878,0.3316992 -0.01953,0.09756 -0.05205,0.1853627 -0.09756,0.2634082 -0.04555,0.078048 -0.10408,0.1528429 -0.175606,0.2243848 -0.07156,0.0715439 -0.282936,0.1886141 -0.63413,0.35121088 -0.351227,0.1625982 -0.8065,0.32194374 -1.365821,0.4780371 -0.55935,0.15609382 -1.206488,0.29592767 -1.941416,0.41950194 -0.734953,0.12357391 -1.518673,0.18536096 -2.351162,0.18536133 -1.443876,-3.7e-7 -2.708885,-0.20162126 -3.795029,-0.60486327 -1.086158,-0.40324154 -1.999956,-1.00160028 -2.741396,-1.79507808 -0.741449,-0.7934737 -1.300784,-1.7885704 -1.678008,-2.9852929 -0.377229,-1.1967125 -0.565842,-2.588547 -0.56584,-4.1755077 -2e-6,-1.5088957 0.195115,-2.8649587 0.585352,-4.0681937 0.390231,-1.203208 0.952818,-2.22432 1.687763,-3.063339 0.734937,-0.838987 1.622719,-1.482873 2.66335,-1.93166 1.040617,-0.448751 2.204815,-0.673136 3.492597,-0.673155 1.378817,1.9e-5 2.552771,0.221152 3.521865,0.663399 0.969068,0.442283 1.765795,1.03739 2.390186,1.785322 0.624358,0.747965 1.082883,1.625991 1.375576,2.634082 0.292658,1.008118 0.438996,2.084514 0.439014,3.229189 z m -3.238945,-0.956074 c 0.03901,-1.691003 -0.334966,-3.017799 -1.121924,-3.980391 -0.786986,-0.962562 -1.954436,-1.443851 -3.502354,-1.443867 -0.793486,1.6e-5 -1.489403,0.149606 -2.087754,0.448769 -0.598366,0.299196 -1.099167,0.695934 -1.502402,1.190215 -0.403248,0.494311 -0.715435,1.069906 -0.936562,1.726787 -0.221139,0.656907 -0.344713,1.343069 -0.370723,2.058487 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path2992" + inkscape:connector-curvature="0" /><path + d="m 59.020138,-23.804296 c -2e-5,0.247172 -0.01303,0.4618 -0.03902,0.643886 -0.02604,0.182133 -0.06831,0.32847 -0.126826,0.439014 -0.05855,0.110589 -0.130097,0.191888 -0.214629,0.243897 -0.08457,0.05205 -0.178876,0.07807 -0.28292,0.07805 l -7.102265,0 0,21.89214832 c -1.2e-5,0.1040629 -0.02603,0.1951175 -0.07805,0.27316406 -0.05204,0.078047 -0.143097,0.13983408 -0.273164,0.18536132 -0.130089,0.04552735 -0.302443,0.08455075 -0.517061,0.11707031 -0.214639,0.03251943 -0.484551,0.04877918 -0.809736,0.0487793 -0.312197,-1.2e-7 -0.578857,-0.0162599 -0.799981,-0.0487793 -0.221141,-0.03251956 -0.396746,-0.07154296 -0.526816,-0.11707031 -0.130086,-0.04552724 -0.221141,-0.10731429 -0.273164,-0.18536132 -0.05204,-0.0780466 -0.07806,-0.16910116 -0.07805,-0.27316406 l 0,-21.89214832 -7.102265,0 c -0.104064,2.3e-5 -0.19837,-0.02599 -0.28292,-0.07805 -0.08455,-0.05201 -0.152843,-0.133308 -0.204873,-0.243897 -0.05203,-0.110544 -0.09431,-0.256881 -0.126827,-0.439014 -0.03252,-0.182086 -0.04878,-0.396714 -0.04878,-0.643886 0,-0.247125 0.01626,-0.465005 0.04878,-0.653643 0.03252,-0.188589 0.0748,-0.34143 0.126827,-0.458525 0.05203,-0.117046 0.120321,-0.201596 0.204873,-0.253653 0.08455,-0.05201 0.178856,-0.07802 0.28292,-0.07805 l 17.560546,0 c 0.104044,2.5e-5 0.19835,0.02604 0.28292,0.07805 0.08453,0.05206 0.156075,0.136607 0.214629,0.253653 0.05852,0.117095 0.100791,0.269936 0.126826,0.458525 0.026,0.188638 0.039,0.406518 0.03902,0.653643 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path2994" + inkscape:connector-curvature="0" /><path + d="m 65.465408,-0.48779296 c -7e-6,0.10406288 -0.02602,0.19186553 -0.07805,0.2634082 -0.05204,0.0715431 -0.136588,0.13333017 -0.253653,0.18536132 -0.117076,0.05203124 -0.279673,0.09105464 -0.487793,0.11707031 -0.20813,0.02601552 -0.47479,0.03902332 -0.79998,0.03902344 -0.312192,-1.2e-7 -0.572348,-0.0130079 -0.780469,-0.03902344 -0.208128,-0.02601567 -0.373978,-0.06503907 -0.497549,-0.11707031 -0.123577,-0.05203115 -0.208128,-0.1138182 -0.253652,-0.18536132 -0.04553,-0.0715427 -0.06829,-0.15934532 -0.06829,-0.2634082 l 0,-17.56054604 c -3e-6,-0.09104 0.02276,-0.175588 0.06829,-0.253653 0.04552,-0.07803 0.130075,-0.143067 0.253652,-0.195117 0.123571,-0.05201 0.289421,-0.09104 0.497549,-0.11707 0.208121,-0.026 0.468277,-0.039 0.780469,-0.03902 0.32519,1.9e-5 0.59185,0.01303 0.79998,0.03902 0.20812,0.02603 0.370717,0.06506 0.487793,0.11707 0.117065,0.05205 0.201615,0.117089 0.253653,0.195117 0.05203,0.07806 0.07804,0.162616 0.07805,0.253653 z M 65.83613,-23.979902 c -6e-6,0.754477 -0.143092,1.268285 -0.429258,1.541426 -0.286177,0.273186 -0.812993,0.409768 -1.580449,0.409746 -0.754457,2.2e-5 -1.271517,-0.133308 -1.551181,-0.39999 -0.279671,-0.266638 -0.419505,-0.77069 -0.419502,-1.512158 -3e-6,-0.754429 0.143083,-1.268237 0.429257,-1.541426 0.286169,-0.273138 0.812985,-0.40972 1.58045,-0.409746 0.754447,2.6e-5 1.271507,0.133356 1.551181,0.39999 0.279662,0.266685 0.419496,0.770738 0.419502,1.512158 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path2996" + inkscape:connector-curvature="0" /><path + d="m 97.404996,-0.48779296 c -2.9e-5,0.10406288 -0.02604,0.19186553 -0.07805,0.2634082 -0.05206,0.0715431 -0.136611,0.13333017 -0.253652,0.18536132 -0.117096,0.05203124 -0.279694,0.09105464 -0.48779,0.11707031 -0.208153,0.02601552 -0.468309,0.03902332 -0.780469,0.03902344 -0.325222,-1.2e-7 -0.591882,-0.0130079 -0.79998,-0.03902344 -0.208152,-0.02601567 -0.374001,-0.06503907 -0.497549,-0.11707031 -0.1236,-0.05203115 -0.211403,-0.1138182 -0.263408,-0.18536132 -0.05206,-0.0715427 -0.07807,-0.15934532 -0.07805,-0.2634082 l 0,-10.67291004 c -2.6e-5,-0.741433 -0.06506,-1.417839 -0.195117,-2.029219 -0.130104,-0.611353 -0.338229,-1.138169 -0.624375,-1.580449 -0.286197,-0.44225 -0.650415,-0.780453 -1.092657,-1.014609 -0.442289,-0.234125 -0.962601,-0.351195 -1.560937,-0.351211 -0.741467,1.6e-5 -1.486163,0.286188 -2.234092,0.858516 -0.747968,0.572358 -1.570712,1.411361 -2.468232,2.517011 l 0,12.27287104 c -1.8e-5,0.10406288 -0.02603,0.19186553 -0.07805,0.2634082 -0.05205,0.0715431 -0.139851,0.13333017 -0.263408,0.18536132 C 85.525594,0.0130078 85.359745,0.0520312 85.151637,0.07804687 84.943495,0.10406239 84.683339,0.11707019 84.371168,0.11707031 84.071973,0.11707019 83.815069,0.10406239 83.600455,0.07804687 83.385811,0.0520312 83.21671,0.0130078 83.093151,-0.03902344 c -0.123589,-0.05203115 -0.20814,-0.1138182 -0.253653,-0.18536132 -0.04554,-0.0715427 -0.06831,-0.15934532 -0.06829,-0.2634082 l 0,-10.67291004 c -1.4e-5,-0.741433 -0.07156,-1.417839 -0.214629,-2.029219 -0.1431,-0.611353 -0.357728,-1.138169 -0.643886,-1.580449 -0.286185,-0.44225 -0.647152,-0.780453 -1.082901,-1.014609 -0.435773,-0.234125 -0.952833,-0.351195 -1.551181,-0.351211 -0.741456,1.6e-5 -1.489404,0.286188 -2.243848,0.858516 -0.754461,0.572358 -1.573952,1.411361 -2.458476,2.517011 l 0,12.27287104 c -7e-6,0.10406288 -0.02602,0.19186553 -0.07805,0.2634082 -0.05204,0.0715431 -0.136588,0.13333017 -0.253653,0.18536132 -0.117076,0.05203124 -0.279673,0.09105464 -0.487793,0.11707031 -0.20813,0.02601552 -0.47479,0.03902332 -0.79998,0.03902344 -0.312192,-1.2e-7 -0.572348,-0.0130079 -0.780469,-0.03902344 -0.208128,-0.02601567 -0.373978,-0.06503907 -0.497549,-0.11707031 -0.123577,-0.05203115 -0.208128,-0.1138182 -0.253652,-0.18536132 -0.04553,-0.0715427 -0.06829,-0.15934532 -0.06829,-0.2634082 l 0,-17.56054604 c -3e-6,-0.104045 0.01951,-0.191847 0.05853,-0.263409 0.03902,-0.07152 0.117067,-0.136563 0.234141,-0.195117 0.117067,-0.05852 0.266656,-0.09754 0.448769,-0.11707 0.182106,-0.01949 0.42275,-0.02925 0.721934,-0.02927 0.286167,1.9e-5 0.523559,0.0098 0.712178,0.02927 0.188608,0.01953 0.334945,0.05855 0.439013,0.11707 0.104057,0.05855 0.178852,0.123593 0.224385,0.195117 0.04552,0.07156 0.06829,0.159364 0.06829,0.263409 l 0,2.321894 c 0.988587,-1.105647 1.947912,-1.915383 2.877979,-2.429209 0.930048,-0.51379 1.869862,-0.770694 2.819443,-0.770713 0.728425,1.9e-5 1.382067,0.08457 1.960928,0.253653 0.578833,0.16912 1.089389,0.406512 1.531669,0.712177 0.44225,0.305702 0.819477,0.66992 1.13168,1.092657 0.312171,0.42277 0.572327,0.894303 0.780469,1.414599 0.585334,-0.637367 1.141417,-1.17719 1.668252,-1.619473 0.526797,-0.442248 1.034101,-0.799962 1.521914,-1.073144 0.487772,-0.273146 0.962557,-0.471515 1.424355,-0.595107 0.461755,-0.123556 0.926784,-0.185343 1.395088,-0.185362 1.131656,1.9e-5 2.081225,0.198388 2.848711,0.595108 0.767434,0.396756 1.388557,0.926824 1.863369,1.590205 0.474757,0.663414 0.81296,1.44063 1.014609,2.33165 0.201593,0.891049 0.302403,1.830862 0.302432,2.819443 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path2998" + inkscape:connector-curvature="0" /><path + d="m 118.26589,-10.029023 c -1e-5,0.507314 -0.12684,0.8682804 -0.38048,1.0829002 -0.25366,0.2146376 -0.54309,0.3219519 -0.86827,0.3219433 l -11.51191,0 c -1e-5,0.9755936 0.0975,1.85362 0.29268,2.634082 0.19511,0.7804739 0.5203,1.4503756 0.97558,2.009707 0.45527,0.5593393 1.04712,0.9885967 1.77557,1.2877734 0.72843,0.299182 1.61946,0.4487717 2.6731,0.4487695 0.83249,2.2e-6 1.57394,-0.068289 2.22434,-0.204873 0.65038,-0.1365795 1.21296,-0.2894211 1.68776,-0.4585254 0.47477,-0.1690985 0.86501,-0.3219401 1.17071,-0.4585254 0.30566,-0.1365785 0.53655,-0.2048695 0.69266,-0.204873 0.091,3.5e-6 0.17234,0.022767 0.2439,0.068291 0.0715,0.045531 0.12681,0.1138217 0.16585,0.204873 0.039,0.091058 0.0683,0.2178839 0.0878,0.3804785 0.0195,0.1626004 0.0292,0.3609694 0.0293,0.5951074 -2e-5,0.1691037 -0.007,0.3154415 -0.0195,0.4390137 -0.013,0.123576 -0.0293,0.2341423 -0.0488,0.3316992 -0.0195,0.09756 -0.052,0.1853627 -0.0976,0.2634082 -0.0455,0.078048 -0.10408,0.1528429 -0.17561,0.2243848 -0.0716,0.0715439 -0.28293,0.1886141 -0.63413,0.35121088 -0.35122,0.1625982 -0.8065,0.32194374 -1.36582,0.4780371 -0.55935,0.15609382 -1.20649,0.29592767 -1.94141,0.41950194 -0.73496,0.12357391 -1.51868,0.18536096 -2.35117,0.18536133 -1.44387,-3.7e-7 -2.70888,-0.20162126 -3.79503,-0.60486327 -1.08615,-0.40324154 -1.99995,-1.00160028 -2.74139,-1.79507808 -0.74145,-0.7934737 -1.30079,-1.7885704 -1.67801,-2.9852929 -0.37723,-1.1967125 -0.56584,-2.588547 -0.56584,-4.1755077 0,-1.5088957 0.19512,-2.8649587 0.58535,-4.0681937 0.39023,-1.203208 0.95282,-2.22432 1.68777,-3.063339 0.73493,-0.838987 1.62271,-1.482873 2.66335,-1.93166 1.04061,-0.448751 2.20481,-0.673136 3.49259,-0.673155 1.37882,1.9e-5 2.55277,0.221152 3.52187,0.663399 0.96907,0.442283 1.76579,1.03739 2.39018,1.785322 0.62436,0.747965 1.08289,1.625991 1.37558,2.634082 0.29266,1.008118 0.439,2.084514 0.43901,3.229189 z m -3.23894,-0.956074 c 0.039,-1.691003 -0.33497,-3.017799 -1.12193,-3.980391 -0.78698,-0.962562 -1.95443,-1.443851 -3.50235,-1.443867 -0.79348,1.6e-5 -1.4894,0.149606 -2.08775,0.448769 -0.59837,0.299196 -1.09917,0.695934 -1.50241,1.190215 -0.40324,0.494311 -0.71543,1.069906 -0.93656,1.726787 -0.22114,0.656907 -0.34471,1.343069 -0.37072,2.058487 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path3000" + inkscape:connector-curvature="0" /></g> +<g + transform="matrix(1,0,0,-1,274.8372,284.4074)" + id="text16"><path + d="m 28.798828,-35.742187 c -2.9e-5,0.371129 -0.01956,0.693394 -0.05859,0.966796 -0.03909,0.273472 -0.102567,0.493199 -0.190429,0.65918 -0.08792,0.16605 -0.195341,0.28812 -0.322266,0.366211 -0.126981,0.07816 -0.268583,0.117221 -0.424805,0.117188 l -10.664062,0 0,32.87109325 c -1.7e-5,0.15625061 -0.03908,0.29296922 -0.117188,0.41015625 -0.07814,0.11718773 -0.21486,0.20996108 -0.410156,0.27832031 -0.195329,0.06835938 -0.454118,0.12695307 -0.776367,0.17578125 -0.322281,0.048828 -0.727554,0.073242 -1.21582,0.0732422 -0.468765,-1.8e-7 -0.869155,-0.0244142 -1.201172,-0.0732422 -0.332045,-0.04882818 -0.595716,-0.10742187 -0.791016,-0.17578125 -0.195325,-0.06835923 -0.332043,-0.16113258 -0.410156,-0.27832031 -0.07814,-0.11718703 -0.1172,-0.25390564 -0.117188,-0.41015625 l 0,-32.87109325 -10.6640621,0 c -0.1562513,3.3e-5 -0.2978527,-0.03903 -0.4248047,-0.117188 -0.12695402,-0.07809 -0.22949298,-0.200161 -0.3076172,-0.366211 -0.0781256,-0.165981 -0.14160212,-0.385708 -0.19042969,-0.65918 -0.0488286,-0.273402 -0.0732426,-0.595667 -0.0732422,-0.966796 -4.4e-7,-0.371058 0.0244136,-0.698206 0.0732422,-0.981446 0.0488276,-0.283166 0.11230407,-0.512658 0.19042969,-0.688476 0.0781242,-0.175744 0.18066318,-0.302697 0.3076172,-0.38086 0.126952,-0.07809 0.2685534,-0.117149 0.4248047,-0.117187 l 26.3671871,0 c 0.156222,3.8e-5 0.297824,0.0391 0.424805,0.117187 0.126925,0.07816 0.234347,0.205116 0.322266,0.38086 0.08786,0.175818 0.151338,0.40531 0.190429,0.688476 0.03903,0.28324 0.05856,0.610388 0.05859,0.981446 z" + style="font-size:60px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path3003" + inkscape:connector-curvature="0" /></g> +<g + transform="matrix(1,0,0,-1,421.0963,282.5633)" + id="text20"><path + d="m 18.048339,-11.23875 c -1.8e-5,0.520323 -0.07481,0.88129 -0.224384,1.082901 -0.149608,0.2016307 -0.321961,0.3024411 -0.517061,0.3024313 l -14.7508589,0 c -0.1951195,9.8e-6 -0.3642209,-0.1008006 -0.5073047,-0.3024313 -0.1430878,-0.201611 -0.2146307,-0.562578 -0.2146289,-1.082901 -1.8e-6,-0.468269 0.065037,-0.812976 0.1951172,-1.034121 0.130076,-0.22112 0.3056813,-0.331686 0.5268164,-0.331699 l 14.7508589,0 c 0.234123,1.3e-5 0.416232,0.110579 0.546328,0.331699 0.13006,0.221145 0.195099,0.565852 0.195117,1.034121 z m 0,7.5900587 c -1.8e-5,0.5203156 -0.07481,0.8780301 -0.224384,1.0731445 -0.149608,0.1951195 -0.321961,0.292678 -0.517061,0.2926758 l -14.7508589,0 C 2.3609156,-2.2828688 2.1918142,-2.3804273 2.0487304,-2.5755468 1.9056426,-2.7706612 1.8340997,-3.1283757 1.8341015,-3.6486913 1.8340997,-4.1299762 1.8991387,-4.4811868 2.0292187,-4.7023241 2.1592947,-4.923452 2.3349,-5.0340183 2.5560351,-5.0340233 l 14.7508589,0 c 0.234123,5e-6 0.416232,0.1105713 0.546328,0.3316992 0.13006,0.2211373 0.195099,0.5723479 0.195117,1.0536328 z m 0,-15.1215817 c -1.8e-5,0.520331 -0.07481,0.878045 -0.224384,1.073144 -0.149608,0.195135 -0.321961,0.292694 -0.517061,0.292676 l -14.7508589,0 c -0.1951195,1.8e-5 -0.3642209,-0.09754 -0.5073047,-0.292676 -0.1430878,-0.195099 -0.2146307,-0.552813 -0.2146289,-1.073144 -1.8e-6,-0.48127 0.065037,-0.83248 0.1951172,-1.053633 0.130076,-0.221113 0.3056813,-0.331679 0.5268164,-0.331699 l 14.7508589,0 c 0.234123,2e-5 0.416232,0.110586 0.546328,0.331699 0.13006,0.221153 0.195099,0.572363 0.195117,1.053633 z" + style="font-size:39.95999908px;font-variant:normal;font-weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:#3e3e3e;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Calibri;-inkscape-font-specification:Calibri" + id="path3006" + inkscape:connector-curvature="0" /></g> +</g></svg> \ No newline at end of file diff --git a/src/site/resources/images/teetime-path.emf b/src/site/resources/images/teetime-path.emf new file mode 100644 index 0000000000000000000000000000000000000000..f8a036619420d61f0ecd3d94f3ab413eea51d8a9 Binary files /dev/null and b/src/site/resources/images/teetime-path.emf differ diff --git a/src/test/java/teetime/examples/cipher/CipherConfiguration.java b/src/test/java/teetime/examples/cipher/CipherConfiguration.java index 11ef38fa8370c2b3a054a1f25f7d56deef717ac9..6192ad227144e28d6a2f5735c52567104043fb5e 100644 --- a/src/test/java/teetime/examples/cipher/CipherConfiguration.java +++ b/src/test/java/teetime/examples/cipher/CipherConfiguration.java @@ -43,14 +43,14 @@ public class CipherConfiguration extends AnalysisConfiguration { final CipherByteArray decrypt = new CipherByteArray(password, CipherMode.DECRYPT); final ByteArrayFileWriter writer = new ByteArrayFileWriter(output); - final IPipeFactory factory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); - - factory.create(init.getOutputPort(), f2b.getInputPort()); - factory.create(f2b.getOutputPort(), enc.getInputPort()); - factory.create(enc.getOutputPort(), comp.getInputPort()); - factory.create(comp.getOutputPort(), decomp.getInputPort()); - factory.create(decomp.getOutputPort(), decrypt.getInputPort()); - factory.create(decrypt.getOutputPort(), writer.getInputPort()); + final IPipeFactory intraFactory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + + intraFactory.create(init.getOutputPort(), f2b.getInputPort()); + intraFactory.create(f2b.getOutputPort(), enc.getInputPort()); + intraFactory.create(enc.getOutputPort(), comp.getInputPort()); + intraFactory.create(comp.getOutputPort(), decomp.getInputPort()); + intraFactory.create(decomp.getOutputPort(), decrypt.getInputPort()); + intraFactory.create(decrypt.getOutputPort(), writer.getInputPort()); // this.getFiniteProducerStages().add(init); this.addThreadableStage(init); diff --git a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java b/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java index f89a44a2b4268fb54ed8758cd0b3c8fb4ae37549..05bc367b8a953b691cd09b6e9c2bfe247816ce83 100644 --- a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java +++ b/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java @@ -18,6 +18,7 @@ package teetime.examples.tokenizer; import java.io.File; import teetime.framework.AnalysisConfiguration; +import teetime.framework.pipe.IPipeFactory; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.stage.ByteArray2String; @@ -32,6 +33,7 @@ import teetime.stage.string.Tokenizer; public class TokenizerConfiguration extends AnalysisConfiguration { + private static final IPipeFactory INTRA_PIPE_FACTORY = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); private final Counter<String> counter; public TokenizerConfiguration(final String inputFile, final String password) { @@ -45,17 +47,17 @@ public class TokenizerConfiguration extends AnalysisConfiguration { final Tokenizer tokenizer = new Tokenizer(" "); this.counter = new Counter<String>(); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( init.getOutputPort(), f2b.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( f2b.getOutputPort(), decomp.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( decomp.getOutputPort(), decrypt.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( decrypt.getOutputPort(), b2s.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( b2s.getOutputPort(), tokenizer.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( + INTRA_PIPE_FACTORY.create( tokenizer.getOutputPort(), this.counter.getInputPort()); // this.getFiniteProducerStages().add(init); diff --git a/src/test/java/teetime/framework/pipe/DummyFactory.java b/src/test/java/teetime/framework/pipe/DummyFactory.java index 3db1330b46dbe92547d11018029dd7638d3d098a..4d2b328cf52caf4c206b3be75c7b117781d43a77 100644 --- a/src/test/java/teetime/framework/pipe/DummyFactory.java +++ b/src/test/java/teetime/framework/pipe/DummyFactory.java @@ -15,10 +15,36 @@ */ package teetime.framework.pipe; -public class DummyFactory extends SpScPipeFactory { +import teetime.framework.InputPort; +import teetime.framework.OutputPort; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - public DummyFactory() { - super(); +public final class DummyFactory implements IPipeFactory { + + @Override + public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { + return this.create(sourcePort, targetPort, 4); + } + + @Override + public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { + return new SpScPipe(sourcePort, targetPort, capacity); + } + + @Override + public ThreadCommunication getThreadCommunication() { + return ThreadCommunication.INTER; + } + + @Override + public PipeOrdering getOrdering() { + return PipeOrdering.QUEUE_BASED; + } + + @Override + public boolean isGrowable() { + return false; } } diff --git a/src/test/java/teetime/stage/WordCountingConfiguration.java b/src/test/java/teetime/stage/WordCountingConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..31537566379ed6afb5bcd27fef03f9dd83388a2f --- /dev/null +++ b/src/test/java/teetime/stage/WordCountingConfiguration.java @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage; + +import java.io.File; + +import teetime.framework.AnalysisConfiguration; +import teetime.framework.pipe.IPipeFactory; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; +import teetime.stage.basic.distributor.Distributor; +import teetime.stage.basic.merger.Merger; +import teetime.stage.io.File2ByteArray; +import teetime.stage.string.WordCounter; +import teetime.stage.util.CountingMap; + +/** + * A simple configuration, which counts the words of a set of files. + * The execution of this configuration is demonstrated in {@link WordCountingTest}. + * + * This configuration is divided into three parts. The first part reads files and distributes them to different {@link WordCounter} instances. + * The second part are a certain number of WordCounter instances. On construction of this class the number of concurrent WordCounter instances is specified with the + * threads parameter. + * The third and last part collects the results from all WordCounter instances and merges them. This final result can be read afterwards. + * + * + * @author Nelson Tavares de Sousa + * + */ +public class WordCountingConfiguration extends AnalysisConfiguration { + + // Last stage is saved as field, to retrieve the result after execution. + private final CountingMapMerger<String> result = new CountingMapMerger<String>(); + + public WordCountingConfiguration(final int threads, final File... input) { + // First part of the config + final InitialElementProducer<File> init = new InitialElementProducer<File>(input); + final File2ByteArray f2b = new File2ByteArray(); + final ByteArray2String b2s = new ByteArray2String(); + final Distributor<String> dist = new Distributor<String>(); + + // last part + final Merger<CountingMap<String>> merger = new Merger<CountingMap<String>>(); + // CountingMapMerger (already as field) + + // PipeFactory instaces for intra- and inter-thread communication + IPipeFactory interFact = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTER, PipeOrdering.QUEUE_BASED, false); + IPipeFactory intraFact = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + + // Connecting the stages of the first part of the config + intraFact.create(init.getOutputPort(), f2b.getInputPort()); + intraFact.create(f2b.getOutputPort(), b2s.getInputPort()); + intraFact.create(b2s.getOutputPort(), dist.getInputPort()); + + // Middle part... multiple instances of WordCounter are created and connected to the merger and distrubuter stages + WordCounter wc; + for (int i = 0; i < threads; i++) { + wc = new WordCounter(); + interFact.create(dist.getNewOutputPort(), wc.getInputPort()); + interFact.create(wc.getOutputPort(), merger.getNewInputPort()); + // Add WordCounter as a threadable stage, so it runs in its own thread + addThreadableStage(wc); + } + + // Connect the stages of the last part + intraFact.create(merger.getOutputPort(), result.getInputPort()); + + // Add the first and last part to the threadable stages + addThreadableStage(init); + addThreadableStage(merger); + } + + // Further methods are allowed. For e.g. it is possible to read data from certain stages. + public CountingMap<String> getResult() { + return result.getResult(); + } + +} diff --git a/src/test/java/teetime/stage/WordCountingTest.java b/src/test/java/teetime/stage/WordCountingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6fec33e68ea191bc3ee82bdf22046e0aea285104 --- /dev/null +++ b/src/test/java/teetime/stage/WordCountingTest.java @@ -0,0 +1,176 @@ +/** + * Copyright (C) 2015 TeeTime (http://teetime.sourceforge.net) + * + * 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.stage; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + +import teetime.framework.Analysis; +import teetime.stage.util.CountingMap; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Charsets; +import com.google.common.base.Splitter; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.io.Files; + +public class WordCountingTest { + + private static final File testFile = new File("src/test/resources/data/output.txt"); + + @Test + public void test1() throws IOException { + int threads = 1; + WordCountingConfiguration wcc = new WordCountingConfiguration(threads, testFile, testFile); + Analysis analysis = new Analysis(wcc); + analysis.start(); + CountingMap<String> map = wcc.getResult(); + assertEquals(new Integer(wordOccurrences(testFile).count(new String("diam")) * 2), map.get("diam")); + assertEquals(new Integer(wordOccurrences(testFile).count(new String("tation")) * 2), map.get("tation")); + assertEquals(new Integer(wordOccurrences(testFile).count(new String("cum")) * 2), map.get("cum")); + } + + private Multiset<String> wordOccurrences(final File file) throws IOException { + return HashMultiset.create( + Splitter.on(CharMatcher.WHITESPACE) + .trimResults() + .omitEmptyStrings() + .split(Files.asCharSource(testFile, Charsets.UTF_8).read())); + } + +} + +// 56 et +// 31 dolor +// 27 sed +// 27 diam +// 26 sit +// 26 lorem +// 26 ipsum +// 26 amet +// 25 dolore +// 24 ut +// 16 vero +// 16 magna +// 16 erat +// 16 ea +// 16 at +// 14 tempor +// 12 takimata +// 12 stet +// 12 sea +// 12 sanctus +// 12 sadipscing +// 12 rebum +// 12 nonumy +// 12 no +// 12 labore +// 12 kasd +// 12 justo +// 12 invidunt +// 12 gubergren +// 12 eos +// 12 elitr +// 12 eirmod +// 12 duo +// 12 dolores +// 12 consetetur +// 12 clita +// 12 aliquyam +// 12 accusam +// 11 voluptua +// 11 est +// 10 vel +// 10 in +// 9 nulla +// 9 duis +// 8 consequat +// 5 vulputate +// 5 velit +// 5 molestie +// 5 iriure +// 5 illum +// 5 hendrerit +// 5 feugiat +// 5 facilisis +// 5 eum +// 5 eu +// 5 esse +// 5 autem +// 4 zzril +// 4 wisi +// 4 volutpat +// 4 veniam +// 4 ullamcorper +// 4 tincidunt +// 4 te +// 4 tation +// 4 suscipit +// 4 quis +// 4 qui +// 4 praesent +// 4 odio +// 4 nostrud +// 4 nonummy +// 4 nisl +// 4 nibh +// 4 minim +// 4 luptatum +// 4 lobortis +// 4 laoreet +// 4 iusto +// 4 feugait +// 4 facilisi +// 4 exerci +// 4 ex +// 4 euismod +// 4 eros +// 4 enim +// 4 elit +// 4 dignissim +// 4 delenit +// 4 consectetuer +// 4 commodo +// 4 blandit +// 4 augue +// 4 aliquip +// 4 aliquam +// 4 adipiscing +// 4 ad +// 4 accumsan +// 2 soluta +// 2 quod +// 2 possim +// 2 placerat +// 2 option +// 2 nobis +// 2 nihil +// 2 nam +// 2 mazim +// 2 liber +// 2 imperdiet +// 2 id +// 2 facer +// 2 eleifend +// 2 doming +// 2 cum +// 2 congue +// 2 assum diff --git a/src/main/java/util/test/AbstractProfiledPerformanceAssertion.java b/src/test/java/util/test/AbstractProfiledPerformanceAssertion.java similarity index 100% rename from src/main/java/util/test/AbstractProfiledPerformanceAssertion.java rename to src/test/java/util/test/AbstractProfiledPerformanceAssertion.java diff --git a/src/main/java/util/test/MeasurementRepository.java b/src/test/java/util/test/MeasurementRepository.java similarity index 100% rename from src/main/java/util/test/MeasurementRepository.java rename to src/test/java/util/test/MeasurementRepository.java diff --git a/src/main/java/util/test/PerformanceCheckProfileRepository.java b/src/test/java/util/test/PerformanceCheckProfileRepository.java similarity index 100% rename from src/main/java/util/test/PerformanceCheckProfileRepository.java rename to src/test/java/util/test/PerformanceCheckProfileRepository.java diff --git a/src/main/java/util/test/PerformanceResult.java b/src/test/java/util/test/PerformanceResult.java similarity index 100% rename from src/main/java/util/test/PerformanceResult.java rename to src/test/java/util/test/PerformanceResult.java diff --git a/src/main/java/util/test/eval/BucketTimingsReader.java b/src/test/java/util/test/eval/BucketTimingsReader.java similarity index 100% rename from src/main/java/util/test/eval/BucketTimingsReader.java rename to src/test/java/util/test/eval/BucketTimingsReader.java diff --git a/src/main/java/util/test/eval/StatisticsUtil.java b/src/test/java/util/test/eval/StatisticsUtil.java similarity index 100% rename from src/main/java/util/test/eval/StatisticsUtil.java rename to src/test/java/util/test/eval/StatisticsUtil.java