Skip to content
Snippets Groups Projects
Commit 24b51e62 authored by Christian Wulf's avatar Christian Wulf
Browse files

Merge branch 'benchmark' into 'master'

Benchmark

Contains:

* the benchmark, as discussed
* a test for the benchmark (without testing data loss)
* a protected static method in CompositeStage, to connect stages
* final declaration of all classes
* signal-bug fix in Merger
* new images in the download page
* EveryXthPrinter extends CompositeStage
* moved util.test

See merge request !28
parents 2d7466b4 075f6d54
Branches
Tags
No related merge requests found
Showing
with 96 additions and 19 deletions
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>17.0</version> <version>18.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jctools</groupId> <groupId>org.jctools</groupId>
......
...@@ -35,7 +35,7 @@ import teetime.util.Pair; ...@@ -35,7 +35,7 @@ import teetime.util.Pair;
* To start the analysis {@link #init()} and {@link #start()} need to be executed in this order. * 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. * 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); private static final Logger LOGGER = LoggerFactory.getLogger(Analysis.class);
......
...@@ -24,7 +24,7 @@ import teetime.framework.pipe.PipeFactoryRegistry; ...@@ -24,7 +24,7 @@ import teetime.framework.pipe.PipeFactoryRegistry;
* Represents a configuration of connected stages, which is needed to run a analysis. * Represents a configuration of connected stages, which is needed to run a analysis.
* Stages can be added by executing {@link #addThreadableStage(Stage)}. * 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; protected static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE;
private final List<Stage> threadableStageJobs = new LinkedList<Stage>(); private final List<Stage> threadableStageJobs = new LinkedList<Stage>();
......
...@@ -18,6 +18,10 @@ package teetime.framework; ...@@ -18,6 +18,10 @@ package teetime.framework;
import java.util.Collection; import java.util.Collection;
import java.util.List; 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.signal.ISignal;
import teetime.framework.validation.InvalidPortConnection; import teetime.framework.validation.InvalidPortConnection;
...@@ -25,12 +29,15 @@ import teetime.framework.validation.InvalidPortConnection; ...@@ -25,12 +29,15 @@ import teetime.framework.validation.InvalidPortConnection;
* Represents a minimal stage that composes several other stages. * Represents a minimal stage that composes several other stages.
* *
* @since 1.1 * @since 1.1
* @author Christian Wulf * @author Christian Wulf, Nelson Tavares de Sousa
* *
*/ */
@SuppressWarnings("PMD.AbstractNaming") @SuppressWarnings("PMD.AbstractNaming")
public abstract class CompositeStage extends Stage { 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 Stage getFirstStage();
protected abstract Collection<? extends Stage> getLastStages(); protected abstract Collection<? extends Stage> getLastStages();
...@@ -81,4 +88,14 @@ public abstract class CompositeStage extends Stage { ...@@ -81,4 +88,14 @@ public abstract class CompositeStage extends Stage {
return isStarted; 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);
}
} }
...@@ -81,7 +81,7 @@ final class RunnableConsumerStage extends AbstractRunnableStage { ...@@ -81,7 +81,7 @@ final class RunnableConsumerStage extends AbstractRunnableStage {
final Stage stage = this.stage; final Stage stage = this.stage;
for (InputPort<?> inputPort : inputPorts) { for (InputPort<?> inputPort : inputPorts) {
final IPipe pipe = inputPort.getPipe(); final IPipe pipe = inputPort.getPipe();
if (pipe instanceof AbstractInterThreadPipe) { if (pipe instanceof AbstractInterThreadPipe) { // TODO: is this needed?
final AbstractInterThreadPipe intraThreadPipe = (AbstractInterThreadPipe) pipe; final AbstractInterThreadPipe intraThreadPipe = (AbstractInterThreadPipe) pipe;
final ISignal signal = intraThreadPipe.getSignal(); final ISignal signal = intraThreadPipe.getSignal();
if (null != signal) { if (null != signal) {
......
...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort; ...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public class CommittablePipeFactory implements IPipeFactory { public final class CommittablePipeFactory implements IPipeFactory {
@Override @Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package teetime.framework.pipe; package teetime.framework.pipe;
public class CouldNotFindPipeImplException extends RuntimeException { public final class CouldNotFindPipeImplException extends RuntimeException {
private static final long serialVersionUID = 5242260988104493402L; private static final long serialVersionUID = 5242260988104493402L;
......
...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort; ...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public class OrderedGrowableArrayPipeFactory implements IPipeFactory { public final class OrderedGrowableArrayPipeFactory implements IPipeFactory {
@Override @Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
......
...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort; ...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public class SingleElementPipeFactory implements IPipeFactory { public final class SingleElementPipeFactory implements IPipeFactory {
@Override @Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
......
...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort; ...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public class SpScPipeFactory implements IPipeFactory { public final class SpScPipeFactory implements IPipeFactory {
@Override @Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
......
...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort; ...@@ -20,7 +20,7 @@ import teetime.framework.OutputPort;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
public class UnorderedGrowablePipeFactory implements IPipeFactory { public final class UnorderedGrowablePipeFactory implements IPipeFactory {
@Override @Override
public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
......
...@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; ...@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import teetime.framework.AbstractStage; 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 static final Logger LOGGER = LoggerFactory.getLogger(StartingSignal.class);
private final List<Exception> catchedExceptions = new LinkedList<Exception>(); private final List<Exception> catchedExceptions = new LinkedList<Exception>();
......
...@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory; ...@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import teetime.framework.AbstractStage; 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 static final Logger LOGGER = LoggerFactory.getLogger(TerminatingSignal.class);
private final List<Exception> catchedExceptions = new LinkedList<Exception>(); private final List<Exception> catchedExceptions = new LinkedList<Exception>();
......
...@@ -21,7 +21,7 @@ import java.util.List; ...@@ -21,7 +21,7 @@ import java.util.List;
import teetime.framework.AbstractStage; import teetime.framework.AbstractStage;
import teetime.framework.validation.InvalidPortConnection; import teetime.framework.validation.InvalidPortConnection;
public class ValidatingSignal implements ISignal { public final class ValidatingSignal implements ISignal {
private final List<InvalidPortConnection> invalidPortConnections = new LinkedList<InvalidPortConnection>(); private final List<InvalidPortConnection> invalidPortConnections = new LinkedList<InvalidPortConnection>();
......
...@@ -20,7 +20,7 @@ import java.nio.charset.Charset; ...@@ -20,7 +20,7 @@ import java.nio.charset.Charset;
import teetime.framework.AbstractConsumerStage; import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
public class ByteArray2String extends AbstractConsumerStage<byte[]> { public final class ByteArray2String extends AbstractConsumerStage<byte[]> {
private final OutputPort<String> outputPort = this.createOutputPort(); private final OutputPort<String> outputPort = this.createOutputPort();
......
...@@ -23,7 +23,7 @@ import teetime.framework.AbstractConsumerStage; ...@@ -23,7 +23,7 @@ import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
import teetime.util.StopWatch; 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(); private final OutputPort<T> outputPort = this.createOutputPort();
......
...@@ -30,7 +30,7 @@ import javax.crypto.spec.SecretKeySpec; ...@@ -30,7 +30,7 @@ import javax.crypto.spec.SecretKeySpec;
import teetime.framework.AbstractConsumerStage; import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort; 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 final OutputPort<byte[]> outputPort = this.createOutputPort();
private Cipher cipher = null; private Cipher cipher = null;
......
...@@ -18,7 +18,7 @@ package teetime.stage; ...@@ -18,7 +18,7 @@ package teetime.stage;
import teetime.framework.AbstractProducerStage; import teetime.framework.AbstractProducerStage;
import teetime.framework.TerminationStrategy; import teetime.framework.TerminationStrategy;
public class Clock extends AbstractProducerStage<Long> { public final class Clock extends AbstractProducerStage<Long> {
private boolean initialDelayExceeded = false; private boolean initialDelayExceeded = false;
......
...@@ -18,7 +18,7 @@ package teetime.stage; ...@@ -18,7 +18,7 @@ package teetime.stage;
import teetime.framework.AbstractConsumerStage; import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort; 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(); private final OutputPort<T> outputPort = this.createOutputPort();
......
/**
* 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment