diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 989609020a008e70c15d3ce12a3a1c835b80201c..29abf999564110a0d6aca109f55f439c72b7031c 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 encoding/<project>=UTF-8 diff --git a/pom.xml b/pom.xml index 7eed5fafa7b33c916205ec6f5eb1cb24260623e3..ede95fa41d237c78fadd75f7d13e0efaad405e39 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,11 @@ <modelVersion>4.0.0</modelVersion> <groupId>net.sourceforge.teetime</groupId> - <artifactId>teetime</artifactId> + <artifactId>kieker-teetime-stages</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>TeeTime</name> - <description>TeeTime is a Pipes-and-Filters framework for Java</description> - <url>http://teetime.sourceforge.org</url> <licenses> <license> @@ -23,40 +21,6 @@ <java.version>1.6</java.version> </properties> - <distributionManagement> - <snapshotRepository> - <id>ossrh</id> - <url>https://oss.sonatype.org/content/repositories/snapshots</url> - </snapshotRepository> - <repository> - <id>ossrh</id> - <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> - </repository> - </distributionManagement> - - <developers> - <developer> - <id>chw</id> - <name>Christian Wulf</name> - <email>chw@informatik.uni-kiel.de</email> - <organization>Christian-Albrechts-Universitaet zu Kiel</organization> - <organizationUrl>http://www.se.informatik.uni-kiel.de/en/team/christian-wulf</organizationUrl> - </developer> - <developer> - <id>ntd</id> - <name>Nelson Tavares de Sousa</name> - <email>ntd@informatik.uni-kiel.de</email> - <organization>Christian-Albrechts-Universitaet zu Kiel</organization> - <organizationUrl>http://www.se.uni-kiel.de/en</organizationUrl> - </developer> - </developers> - - <scm> - <connection>scm:git:https://build.se.informatik.uni-kiel.de/gitlab/chw/teetime.git</connection> - <developerConnection>scm:git:ssh://gitlab@build.se.informatik.uni-kiel.de:chw/teetime.git</developerConnection> - <url>https://build.se.informatik.uni-kiel.de/gitlab/chw/teetime/</url> - </scm> - <repositories> <repository> <!-- kieker:1.10-SNAPSHOT --> @@ -66,6 +30,11 @@ </repositories> <dependencies> + <dependency> + <groupId>net.sourceforge.teetime</groupId> + <artifactId>teetime</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java deleted file mode 100644 index 29568b17620b6b0c87d84ccde40c724cb96be833..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/AbstractPort.java +++ /dev/null @@ -1,31 +0,0 @@ -package teetime.framework; - -import teetime.framework.pipe.IPipe; - -public abstract class AbstractPort<T> { - - protected IPipe pipe; - /** - * The type of this port. - * <p> - * <i>Used to validate the connection between two ports at runtime.</i> - * </p> - */ - protected Class<T> type; - - public IPipe getPipe() { - return this.pipe; - } - - public void setPipe(final IPipe pipe) { - this.pipe = pipe; - } - - public Class<T> getType() { - return this.type; - } - - public void setType(final Class<T> type) { - this.type = type; - } -} diff --git a/src/main/java/teetime/framework/AbstractStage.java b/src/main/java/teetime/framework/AbstractStage.java deleted file mode 100644 index 33be2f0cfb5b0773f794ffe0097a679d1e23b36b..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/AbstractStage.java +++ /dev/null @@ -1,165 +0,0 @@ -package teetime.framework; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import teetime.framework.pipe.DummyPipe; -import teetime.framework.pipe.IPipe; -import teetime.framework.signal.ISignal; -import teetime.framework.validation.InvalidPortConnection; - -public abstract class AbstractStage implements Stage { - - private final String id; - /** - * A unique logger instance per stage instance - */ - protected final Logger logger; - - private Stage parentStage; - - private final List<InputPort<?>> inputPortList = new ArrayList<InputPort<?>>(); - private final List<OutputPort<?>> outputPortList = new ArrayList<OutputPort<?>>(); - - /** A cached instance of <code>inputPortList</code> to avoid creating an iterator each time iterating it */ - protected InputPort<?>[] cachedInputPorts; - /** A cached instance of <code>outputPortList</code> to avoid creating an iterator each time iterating it */ - protected OutputPort<?>[] cachedOutputPorts; - - private final Map<ISignal, Void> visited = new HashMap<ISignal, Void>(); - - public AbstractStage() { - this.id = UUID.randomUUID().toString(); // the id should only be represented by a UUID, not additionally by the class name - this.logger = LoggerFactory.getLogger(this.getClass().getName() + "(" + this.id + ")"); - } - - /** - * Sends the given <code>element</code> using the default output port - * - * @param element - * @return <code>true</code> iff the given element could be sent, <code>false</code> otherwise (then use a re-try strategy) - */ - protected final <O> boolean send(final OutputPort<O> outputPort, final O element) { - if (!outputPort.send(element)) { - return false; - } - - outputPort.reportNewElement(); - - return true; - // return outputPort.send(element); - } - - private void connectUnconnectedOutputPorts() { - for (OutputPort<?> outputPort : this.cachedOutputPorts) { - if (null == outputPort.getPipe()) { // if port is unconnected - this.logger.warn("Unconnected output port: " + outputPort + ". Connecting with a dummy output port."); - outputPort.setPipe(new DummyPipe()); - } - } - } - - protected InputPort<?>[] getInputPorts() { - return this.cachedInputPorts; - } - - protected OutputPort<?>[] getOutputPorts() { - return this.cachedOutputPorts; - } - - @Override - public Stage getParentStage() { - return this.parentStage; - } - - @Override - public void setParentStage(final Stage parentStage, final int index) { - this.parentStage = parentStage; - } - - @Override - public String getId() { - return this.id; - } - - /** - * May not be invoked outside of IPipe implementations - */ - @Override - public void onSignal(final ISignal signal, final InputPort<?> inputPort) { - if (!this.alreadyVisited(signal, inputPort)) { - signal.trigger(this); - - for (OutputPort<?> outputPort : this.outputPortList) { - outputPort.sendSignal(signal); - } - } - } - - protected boolean alreadyVisited(final ISignal signal, final InputPort<?> inputPort) { - if (this.visited.containsKey(signal)) { - this.logger.trace("Got signal: " + signal + " again from input port: " + inputPort); - return true; - } else { - this.logger.trace("Got signal: " + signal + " from input port: " + inputPort); - this.visited.put(signal, null); - return false; - } - } - - public void onValidating(final List<InvalidPortConnection> invalidPortConnections) { - this.validateOutputPorts(invalidPortConnections); - } - - public void onStarting() { - this.cachedInputPorts = this.inputPortList.toArray(new InputPort<?>[0]); - this.cachedOutputPorts = this.outputPortList.toArray(new OutputPort<?>[0]); - - this.connectUnconnectedOutputPorts(); - } - - public void onTerminating() { - // empty default implementation - } - - protected <T> InputPort<T> createInputPort() { - InputPort<T> inputPort = new InputPort<T>(this); - // inputPort.setType(portType); - this.inputPortList.add(inputPort); - return inputPort; - } - - protected <T> OutputPort<T> createOutputPort() { - OutputPort<T> outputPort = new OutputPort<T>(); - // outputPort.setType(portType); - this.outputPortList.add(outputPort); - return outputPort; - } - - @Override - public void validateOutputPorts(final List<InvalidPortConnection> invalidPortConnections) { - for (OutputPort<?> outputPort : this.getOutputPorts()) { - IPipe pipe = outputPort.getPipe(); - if (null != pipe) { // if output port is connected with another one - Class<?> sourcePortType = outputPort.getType(); - Class<?> targetPortType = pipe.getTargetPort().getType(); - if (null == sourcePortType || !sourcePortType.equals(targetPortType)) { - InvalidPortConnection invalidPortConnection = new InvalidPortConnection(outputPort, pipe.getTargetPort()); - invalidPortConnections.add(invalidPortConnection); - } - } - } - } - - @Override - public String toString() { - return this.getClass().getName() + ": " + this.id; - } - -} diff --git a/src/main/java/teetime/framework/Analysis.java b/src/main/java/teetime/framework/Analysis.java deleted file mode 100644 index c9fd8e112c7a8cfb9e2be4f2df0de17ac660054b..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/Analysis.java +++ /dev/null @@ -1,104 +0,0 @@ -package teetime.framework; - -import java.lang.Thread.UncaughtExceptionHandler; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ConcurrentLinkedQueue; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import teetime.util.Pair; - -public class Analysis implements UncaughtExceptionHandler { - - private static final Logger LOGGER = LoggerFactory.getLogger(Analysis.class); - - private final AnalysisConfiguration configuration; - - private final List<Thread> consumerThreads = new LinkedList<Thread>(); - private final List<Thread> finiteProducerThreads = new LinkedList<Thread>(); - private final List<Thread> infiniteProducerThreads = new LinkedList<Thread>(); - - private final Collection<Pair<Thread, Throwable>> exceptions = new ConcurrentLinkedQueue<Pair<Thread, Throwable>>(); - - public Analysis(final AnalysisConfiguration configuration) { - this.configuration = configuration; - } - - public void init() { - for (HeadStage stage : this.configuration.getConsumerStages()) { - Thread thread = new Thread(new RunnableStage(stage)); - this.consumerThreads.add(thread); - } - - for (HeadStage stage : this.configuration.getFiniteProducerStages()) { - Thread thread = new Thread(new RunnableStage(stage)); - this.finiteProducerThreads.add(thread); - } - - for (HeadStage stage : this.configuration.getInfiniteProducerStages()) { - Thread thread = new Thread(new RunnableStage(stage)); - this.infiniteProducerThreads.add(thread); - } - } - - /** - * - * @return a map of thread/throwable pair - */ - public Collection<Pair<Thread, Throwable>> start() { - // start analysis - for (Thread thread : this.consumerThreads) { - thread.setUncaughtExceptionHandler(this); - thread.start(); - } - - for (Thread thread : this.finiteProducerThreads) { - thread.setUncaughtExceptionHandler(this); - thread.start(); - } - - for (Thread thread : this.infiniteProducerThreads) { - thread.setUncaughtExceptionHandler(this); - thread.start(); - } - - // wait for the analysis to complete - try { - for (Thread thread : this.finiteProducerThreads) { - thread.join(); - } - - for (Thread thread : this.consumerThreads) { - thread.join(); - } - } catch (InterruptedException e) { - LOGGER.error("Analysis has stopped unexpectedly", e); - - for (Thread thread : this.finiteProducerThreads) { - thread.interrupt(); - } - - for (Thread thread : this.consumerThreads) { - thread.interrupt(); - } - } - - for (Thread thread : this.infiniteProducerThreads) { - thread.interrupt(); - } - - return this.exceptions; - } - - public AnalysisConfiguration getConfiguration() { - return this.configuration; - } - - @Override - public void uncaughtException(final Thread t, final Throwable e) { - this.exceptions.add(Pair.of(t, e)); - } -} diff --git a/src/main/java/teetime/framework/AnalysisConfiguration.java b/src/main/java/teetime/framework/AnalysisConfiguration.java deleted file mode 100644 index c051594442e7982ccad776bf71597a6aaeb95547..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/AnalysisConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -package teetime.framework; - -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.pipe.PipeFactoryRegistry; - -public class AnalysisConfiguration { - - protected static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE; - - private final List<HeadStage> consumerStages = new LinkedList<HeadStage>(); - private final List<HeadStage> finiteProducerStages = new LinkedList<HeadStage>(); - private final List<HeadStage> infiniteProducerStages = new LinkedList<HeadStage>(); - - public List<HeadStage> getConsumerStages() { - return this.consumerStages; - } - - public List<HeadStage> getFiniteProducerStages() { - return this.finiteProducerStages; - } - - public List<HeadStage> getInfiniteProducerStages() { - return this.infiniteProducerStages; - } - -} diff --git a/src/main/java/teetime/framework/ConsumerStage.java b/src/main/java/teetime/framework/ConsumerStage.java deleted file mode 100644 index 60db33da9c85901e6482ea01ec21c8834b9f9e87..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/ConsumerStage.java +++ /dev/null @@ -1,20 +0,0 @@ -package teetime.framework; - -public abstract class ConsumerStage<I> extends AbstractStage { - - protected final InputPort<I> inputPort = this.createInputPort(); - - public final InputPort<I> getInputPort() { - return this.inputPort; - } - - @Override - public void executeWithPorts() { - I element = this.getInputPort().receive(); - - this.execute(element); - } - - protected abstract void execute(I element); - -} diff --git a/src/main/java/teetime/framework/HeadPipeline.java b/src/main/java/teetime/framework/HeadPipeline.java deleted file mode 100644 index 293700a045013be308290e984687897a35a0d03f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/HeadPipeline.java +++ /dev/null @@ -1,18 +0,0 @@ -package teetime.framework; - -public class HeadPipeline<FirstStage extends HeadStage, LastStage extends Stage> extends OldPipeline<FirstStage, LastStage> implements HeadStage { - - public HeadPipeline() {} - - public HeadPipeline(final String name) {} - - @Override - public boolean shouldBeTerminated() { - return this.firstStage.shouldBeTerminated(); - } - - @Override - public void terminate() { - this.firstStage.terminate(); - } -} diff --git a/src/main/java/teetime/framework/HeadStage.java b/src/main/java/teetime/framework/HeadStage.java deleted file mode 100644 index 5e8de76568b84801027f947e8fadfbd214b39891..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/HeadStage.java +++ /dev/null @@ -1,8 +0,0 @@ -package teetime.framework; - -public interface HeadStage extends Stage { - - boolean shouldBeTerminated(); - - void terminate(); -} diff --git a/src/main/java/teetime/framework/InputPort.java b/src/main/java/teetime/framework/InputPort.java deleted file mode 100644 index 7f8050c22ef1cffb898e08efe5b90029e1f00595..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/InputPort.java +++ /dev/null @@ -1,40 +0,0 @@ -package teetime.framework; - -import teetime.framework.pipe.IPipe; - -public class InputPort<T> extends AbstractPort<T> { - - private final Stage owningStage; - - InputPort(final Stage owningStage) { - super(); - this.owningStage = owningStage; - } - - public T receive() { - @SuppressWarnings("unchecked") - T element = (T) this.pipe.removeLast(); - return element; - } - - public T read() { - @SuppressWarnings("unchecked") - T element = (T) this.pipe.readLast(); - return element; - } - - /** - * Connects this input port with the given <code>pipe</code> bi-directionally - * - * @param pipe - */ - @Override - public void setPipe(final IPipe pipe) { - this.pipe = pipe; - } - - public Stage getOwningStage() { - return this.owningStage; - } - -} diff --git a/src/main/java/teetime/framework/OldPipeline.java b/src/main/java/teetime/framework/OldPipeline.java deleted file mode 100644 index 77b70577e9c3ec38d49747253d5ead7c22722ec8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/OldPipeline.java +++ /dev/null @@ -1,59 +0,0 @@ -package teetime.framework; - -import java.util.List; - -import teetime.framework.signal.ISignal; -import teetime.framework.validation.InvalidPortConnection; - -public class OldPipeline<FirstStage extends Stage, LastStage extends Stage> implements Stage { - - protected FirstStage firstStage; - protected LastStage lastStage; - - public FirstStage getFirstStage() { - return this.firstStage; - } - - public void setFirstStage(final FirstStage firstStage) { - this.firstStage = firstStage; - } - - public LastStage getLastStage() { - return this.lastStage; - } - - public void setLastStage(final LastStage lastStage) { - this.lastStage = lastStage; - } - - @Override - public String getId() { - return this.firstStage.getId(); - } - - @Override - public void executeWithPorts() { - this.firstStage.executeWithPorts(); - } - - @Override - public Stage getParentStage() { - return this.firstStage.getParentStage(); - } - - @Override - public void setParentStage(final Stage parentStage, final int index) { - this.firstStage.setParentStage(parentStage, index); - } - - @Override - public void onSignal(final ISignal signal, final InputPort<?> inputPort) { - this.firstStage.onSignal(signal, inputPort); - } - - @Override - public void validateOutputPorts(final List<InvalidPortConnection> invalidPortConnections) { - this.lastStage.validateOutputPorts(invalidPortConnections); - } - -} diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java deleted file mode 100644 index 45a8de638a765f72d408dc5e84f856feac624ab6..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/OutputPort.java +++ /dev/null @@ -1,28 +0,0 @@ -package teetime.framework; - -import teetime.framework.signal.ISignal; - -public final class OutputPort<T> extends AbstractPort<T> { - - OutputPort() { - super(); - } - - /** - * - * @param element - * @return <code>true</code> iff the given <code>element</code> could be sent, <code>false</code> otherwise (then use a re-try strategy) - */ - public boolean send(final T element) { - return this.pipe.add(element); - } - - public void sendSignal(final ISignal signal) { - this.pipe.sendSignal(signal); - } - - public void reportNewElement() { - this.pipe.reportNewElement(); - } - -} diff --git a/src/main/java/teetime/framework/ProducerStage.java b/src/main/java/teetime/framework/ProducerStage.java deleted file mode 100644 index ac3dbd1f078dfe477e5029bae8f83a1e2eba5ae6..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/ProducerStage.java +++ /dev/null @@ -1,38 +0,0 @@ -package teetime.framework; - -/** - * The <code>ProducerStage</code> produces at least one element at each execution.<br> - * - * @author Christian Wulf - * - * @param <O> - * the type of the default output port - * - */ -public abstract class ProducerStage<O> extends AbstractStage implements HeadStage { - - protected final OutputPort<O> outputPort = this.createOutputPort(); - private boolean shouldTerminate; - - public final OutputPort<O> getOutputPort() { - return this.outputPort; - } - - @Override - public void executeWithPorts() { - this.execute(); - } - - @Override - public void terminate() { - this.shouldTerminate = true; - } - - @Override - public boolean shouldBeTerminated() { - return this.shouldTerminate; - } - - protected abstract void execute(); - -} diff --git a/src/main/java/teetime/framework/RunnableStage.java b/src/main/java/teetime/framework/RunnableStage.java deleted file mode 100644 index a22400157a53056e6599f4a935772cbebbf751a7..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/RunnableStage.java +++ /dev/null @@ -1,63 +0,0 @@ -package teetime.framework; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import teetime.framework.signal.StartingSignal; -import teetime.framework.signal.TerminatingSignal; -import teetime.framework.signal.ValidatingSignal; -import teetime.framework.validation.AnalysisNotValidException; - -public class RunnableStage implements Runnable { - - private final HeadStage stage; - private final Logger logger; - private boolean validationEnabled; - - public RunnableStage(final HeadStage stage) { - this.stage = stage; - this.logger = LoggerFactory.getLogger(stage.getClass()); - } - - @Override - public void run() { - this.logger.debug("Executing runnable stage..."); - - if (this.validationEnabled) { - ValidatingSignal validatingSignal = new ValidatingSignal(); - this.stage.onSignal(validatingSignal, null); - if (validatingSignal.getInvalidPortConnections().size() > 0) { - throw new AnalysisNotValidException(validatingSignal.getInvalidPortConnections()); - } - } - - try { - StartingSignal startingSignal = new StartingSignal(); - this.stage.onSignal(startingSignal, null); - - do { - this.stage.executeWithPorts(); - } while (!this.stage.shouldBeTerminated()); - - TerminatingSignal terminatingSignal = new TerminatingSignal(); - this.stage.onSignal(terminatingSignal, null); - - } catch (Error e) { - this.logger.error("Terminating thread due to the following exception: ", e); - throw e; - } catch (RuntimeException e) { - this.logger.error("Terminating thread due to the following exception: ", e); - throw e; - } - - this.logger.debug("Finished runnable stage. (" + this.stage.getId() + ")"); - } - - public boolean isValidationEnabled() { - return this.validationEnabled; - } - - public void setValidationEnabled(final boolean validationEnabled) { - this.validationEnabled = validationEnabled; - } -} diff --git a/src/main/java/teetime/framework/Stage.java b/src/main/java/teetime/framework/Stage.java deleted file mode 100644 index 3f0798ac9bd35ed3ad195e1ec1f5feefdc973fb1..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/Stage.java +++ /dev/null @@ -1,26 +0,0 @@ -package teetime.framework; - -import java.util.List; - -import teetime.framework.signal.ISignal; -import teetime.framework.validation.InvalidPortConnection; - -public interface Stage { - - String getId(); - - void executeWithPorts(); - - Stage getParentStage(); - - void setParentStage(Stage parentStage, int index); - - void onSignal(ISignal signal, InputPort<?> inputPort); - - /** - * - * @param invalidPortConnections - * <i>(Passed as parameter for performance reasons)</i> - */ - void validateOutputPorts(List<InvalidPortConnection> invalidPortConnections); -} diff --git a/src/main/java/teetime/framework/pipe/AbstractPipe.java b/src/main/java/teetime/framework/pipe/AbstractPipe.java deleted file mode 100644 index d59c660b7867405553f1e5efe9203e44b5228937..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/AbstractPipe.java +++ /dev/null @@ -1,46 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.Stage; - -public abstract class AbstractPipe implements IPipe { - - private InputPort<?> targetPort; - - /** - * Performance cache: Avoids the following method chain - * - * <pre> - * this.getPipe().getTargetPort().getOwningStage() - * </pre> - */ - protected Stage cachedTargetStage; - - protected <T> AbstractPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - this.targetPort = targetPort; - if (null != targetPort) { // BETTER remove this check if migration is completed - this.cachedTargetStage = targetPort.getOwningStage(); - } - if (null != sourcePort) { // BETTER remove this check if migration is completed - sourcePort.setPipe(this); - } - if (null != targetPort) { // BETTER remove this check if migration is completed - targetPort.setPipe(this); - } - } - - @Override - public InputPort<?> getTargetPort() { - return this.targetPort; - } - - @Override - public <T> void connectPorts(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - sourcePort.setPipe(this); - targetPort.setPipe(this); - this.targetPort = targetPort; - this.cachedTargetStage = targetPort.getOwningStage(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/CommittablePipe.java b/src/main/java/teetime/framework/pipe/CommittablePipe.java deleted file mode 100644 index fddb53c613ca5b31e7acca6a572576a41289b6c8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/CommittablePipe.java +++ /dev/null @@ -1,74 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.util.list.CommittableResizableArrayQueue; - -public final class CommittablePipe extends IntraThreadPipe { - - private final CommittableResizableArrayQueue<Object> elements = new CommittableResizableArrayQueue<Object>(null, 4); - - <T> CommittablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - IPipe pipe = new CommittablePipe(null, null); - pipe.connectPorts(sourcePort, targetPort); - } - - /* - * (non-Javadoc) - * - * @see teetime.examples.throughput.methodcall.IPipe#add(T) - */ - @Override - public boolean add(final Object element) { - this.elements.addToTailUncommitted(element); - this.elements.commit(); - return true; - } - - /* - * (non-Javadoc) - * - * @see teetime.examples.throughput.methodcall.IPipe#removeLast() - */ - @Override - public Object removeLast() { - Object element = this.elements.removeFromHeadUncommitted(); - this.elements.commit(); - return element; - } - - /* - * (non-Javadoc) - * - * @see teetime.examples.throughput.methodcall.IPipe#isEmpty() - */ - @Override - public boolean isEmpty() { - return this.elements.isEmpty(); - } - - /* - * (non-Javadoc) - * - * @see teetime.examples.throughput.methodcall.IPipe#readLast() - */ - @Override - public Object readLast() { - return this.elements.getTail(); - } - - public CommittableResizableArrayQueue<?> getElements() { - return this.elements; - } - - @Override - public int size() { - return this.elements.size(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java b/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java deleted file mode 100644 index ed80b4dc131721b176b298681784280da7e6b54f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/CouldNotFindPipeImplException.java +++ /dev/null @@ -1,11 +0,0 @@ -package teetime.framework.pipe; - -public class CouldNotFindPipeImplException extends RuntimeException { - - private static final long serialVersionUID = 5242260988104493402L; - - public CouldNotFindPipeImplException(final String key) { - super("Could not find any pipe implementation that conforms to the key: " + key); - } - -} diff --git a/src/main/java/teetime/framework/pipe/DummyPipe.java b/src/main/java/teetime/framework/pipe/DummyPipe.java deleted file mode 100644 index 716046dc3242f4f5526bddb163b45bb97ba4fcca..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/DummyPipe.java +++ /dev/null @@ -1,57 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.signal.ISignal; - -/** - * A pipe implementation used to connect unconnected output ports. - * - * @author Christian Wulf - * - */ -@SuppressWarnings("rawtypes") -public final class DummyPipe implements IPipe { - - @Override - public boolean add(final Object element) { - return false; - } - - @Override - public Object removeLast() { - return null; - } - - @Override - public boolean isEmpty() { - return true; - } - - @Override - public int size() { - return 0; - } - - @Override - public Object readLast() { - return null; - } - - @Override - public InputPort<Object> getTargetPort() { - return null; - } - - @Override - public void sendSignal(final ISignal signal) {} - - @Override - public void connectPorts(final OutputPort sourcePort, final InputPort targetPort) {} - - @Override - public void reportNewElement() { - // do nothing - } - -} diff --git a/src/main/java/teetime/framework/pipe/IPipe.java b/src/main/java/teetime/framework/pipe/IPipe.java deleted file mode 100644 index 8fee03e759208e92c3d7fef5d2c04414297ec804..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/IPipe.java +++ /dev/null @@ -1,28 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.signal.ISignal; - -public interface IPipe { - - boolean add(Object element); - - boolean isEmpty(); - - int size(); - - Object removeLast(); - - Object readLast(); - - InputPort<?> getTargetPort(); - - void sendSignal(ISignal signal); - - @Deprecated - <T> void connectPorts(OutputPort<? extends T> sourcePort, InputPort<T> targetPort); - - void reportNewElement(); - -} diff --git a/src/main/java/teetime/framework/pipe/IPipeFactory.java b/src/main/java/teetime/framework/pipe/IPipeFactory.java deleted file mode 100644 index a37955e86dacd9e3dc61df0f902628d393306a67..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/IPipeFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -/** - * Represents the interface, which is must be defined in every PipeFactory - */ -public interface IPipeFactory { - - /** - * Connects two stages with a pipe of default capacity. - * - * @param sourcePort - * OutputPort of the stage, which produces data. - * @param targetPort - * Input port of the receiving stage. - * @return The connecting pipe. - */ - <T> IPipe create(OutputPort<? extends T> sourcePort, InputPort<T> targetPort); - - /** - * Connects two stages with a pipe. - * - * @param sourcePort - * OutputPort of the stage, which produces data. - * @param targetPort - * Input port of the receiving stage. - * @param capacity - * Number of elements the pipe can carry. - * @return The connecting pipe. - */ - <T> IPipe create(OutputPort<? extends T> sourcePort, InputPort<T> targetPort, int capacity); - - /** - * @return Type of ThreadCommunication, which is used by the created pipes. - */ - ThreadCommunication getThreadCommunication(); - - /** - * @return Ordering type, which is used by the created pipes. - */ - PipeOrdering getOrdering(); - - /** - * @return Wether or not the created pipes are growable - */ - boolean isGrowable(); - -} diff --git a/src/main/java/teetime/framework/pipe/InterThreadPipe.java b/src/main/java/teetime/framework/pipe/InterThreadPipe.java deleted file mode 100644 index a38e59519e8e3a16c2027fb0b14ff757273b75a3..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/InterThreadPipe.java +++ /dev/null @@ -1,40 +0,0 @@ -package teetime.framework.pipe; - -import java.util.Queue; - -import org.jctools.queues.QueueFactory; -import org.jctools.queues.spec.ConcurrentQueueSpec; -import org.jctools.queues.spec.Ordering; -import org.jctools.queues.spec.Preference; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.signal.ISignal; - -public abstract class InterThreadPipe extends AbstractPipe { - - private final Queue<ISignal> signalQueue = QueueFactory.newQueue(new ConcurrentQueueSpec(1, 1, 0, Ordering.FIFO, Preference.THROUGHPUT)); - - <T> InterThreadPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - } - - @Override - public void sendSignal(final ISignal signal) { - this.signalQueue.offer(signal); - } - - /** - * Retrieves and removes the head of the signal queue - * - * @return Head of signal queue, <code>null</code> if signal queue is empty. - */ - public ISignal getSignal() { - return this.signalQueue.poll(); - } - - @Override - public void reportNewElement() { - // do nothing - } -} diff --git a/src/main/java/teetime/framework/pipe/IntraThreadPipe.java b/src/main/java/teetime/framework/pipe/IntraThreadPipe.java deleted file mode 100644 index 42257bc9085c363c0604c4a60cf093e88f9f2bcf..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/IntraThreadPipe.java +++ /dev/null @@ -1,25 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.signal.ISignal; - -public abstract class IntraThreadPipe extends AbstractPipe { - - <T> IntraThreadPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - } - - @Override - public void sendSignal(final ISignal signal) { - if (this.getTargetPort() != null) { // BETTER remove this check since there are DummyPorts - this.cachedTargetStage.onSignal(signal, this.getTargetPort()); - } - } - - @Override - public final void reportNewElement() { - this.cachedTargetStage.executeWithPorts(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java deleted file mode 100644 index 5ee042d070bb0c95a45470d6fbaab52cdda411d3..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipe.java +++ /dev/null @@ -1,54 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.util.concurrent.workstealing.CircularArray; - -public final class OrderedGrowableArrayPipe extends IntraThreadPipe { - - private final CircularArray<Object> elements; - private int head; - private int tail; - - <T> OrderedGrowableArrayPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new CircularArray<Object>(capacity); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - IPipe pipe = new OrderedGrowableArrayPipe(sourcePort, targetPort, 4); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - this.elements.put(this.tail++, element); - return true; - } - - @Override - public Object removeLast() { - if (this.head < this.tail) { - return this.elements.get(this.head++); - } else { - return null; - } - } - - @Override - public boolean isEmpty() { - return this.size() == 0; - } - - @Override - public Object readLast() { - return this.elements.get(this.head); - } - - @Override - public int size() { - return this.tail - this.head; - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java b/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java deleted file mode 100644 index ce5c89d844ed5b1458cd9317803e125db6991aff..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowableArrayPipeFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public class OrderedGrowableArrayPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new OrderedGrowableArrayPipe(sourcePort, targetPort, capacity); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.QUEUE_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java b/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java deleted file mode 100644 index 0163ba6a72f43d9a3c179643643bd88fd77693ce..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/OrderedGrowablePipe.java +++ /dev/null @@ -1,48 +0,0 @@ -package teetime.framework.pipe; - -import java.util.LinkedList; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class OrderedGrowablePipe extends IntraThreadPipe { - - private final LinkedList<Object> elements; - - <T> OrderedGrowablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new LinkedList<Object>(); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - IPipe pipe = new OrderedGrowablePipe(null, null, 100000); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - return this.elements.offer(element); - } - - @Override - public Object removeLast() { - return this.elements.poll(); - } - - @Override - public boolean isEmpty() { - return this.elements.isEmpty(); - } - - @Override - public Object readLast() { - return this.elements.peek(); - } - - @Override - public int size() { - return this.elements.size(); - } - -} diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java deleted file mode 100644 index 365918f0421275421c294533d8d99832e89b3fc2..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java +++ /dev/null @@ -1,49 +0,0 @@ -package teetime.framework.pipe; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PipeFactoryLoader { - - private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryLoader.class); - - private PipeFactoryLoader() { - // utility class - } - - public static List<IPipeFactory> loadFromFile(final String fileName) throws IOException { - List<IPipeFactory> pipeFactories = new LinkedList<IPipeFactory>(); - - BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName)); - try { - String line; - while (null != (line = bufferedReader.readLine())) { - try { - line = line.trim(); - if (!line.isEmpty()) { - Class<?> clazz = Class.forName(line); - Class<? extends IPipeFactory> pipeFactoryClass = clazz.asSubclass(IPipeFactory.class); - IPipeFactory pipeFactory = pipeFactoryClass.newInstance(); - pipeFactories.add(pipeFactory); - } - } catch (ClassNotFoundException e) { - LOGGER.warn("Could not find class: " + line, e); - } catch (InstantiationException e) { - LOGGER.warn("Could not instantiate pipe factory", e); - } catch (IllegalAccessException e) { - LOGGER.warn("Could not instantiate pipe factory", e); - } - } - } finally { - bufferedReader.close(); - } - - return pipeFactories; - } -} diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java b/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java deleted file mode 100644 index 44c209205e7a49b025ca61bb7a484dcc073c13a6..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java +++ /dev/null @@ -1,100 +0,0 @@ -package teetime.framework.pipe; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents a Registry which provides PipeFactories that are used to create pipes. - * The instance of this singleton class is saved in {@link PipeFactoryRegistry#INSTANCE}. - * <p> - * To get a PipeFactory instance, call {@link #getPipeFactory(ThreadCommunication, PipeOrdering, boolean)}. - * - */ -public class PipeFactoryRegistry { - - private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryRegistry.class); - - /** - * Represent a communication type between two connected stages - */ - public enum ThreadCommunication { - INTER, INTRA - } - - /** - * Represents the ordering behavior of a pipe - */ - public enum PipeOrdering { - /** - * FIFO - */ - QUEUE_BASED, - /** - * LIFO - */ - STACK_BASED, - ARBITRARY - } - - private final Map<String, IPipeFactory> pipeFactories = new HashMap<String, IPipeFactory>(); - - /** - * The singleton instance of PipeFactoryRegistry - */ - public static PipeFactoryRegistry INSTANCE = new PipeFactoryRegistry(); - - private PipeFactoryRegistry() { - try { - List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadFromFile("conf/pipe-factories.conf"); - for (IPipeFactory pipeFactory : pipeFactories) { - this.register(pipeFactory); - } - } catch (IOException e) { - LOGGER.warn("Could not load pipe factories from file", e); - } - } - - /** - * Returns a PipeFactory Instance. - * - * @param tc - * Communication type between two connected stages. These are defined in PipeFactoryRegistry.ThreadCommunication - * @param ordering - * Specifies the ordering behavior of the pipe. See PipeFactoryRegistry.PipeOrdering - * @param growable - * Whether the queue size is fixed or not. - * @return - * A PipeFactory, which provides suitable pipes. - */ - public IPipeFactory getPipeFactory(final ThreadCommunication tc, final PipeOrdering ordering, final boolean growable) { - String key = this.buildKey(tc, ordering, growable); - IPipeFactory pipeFactory = this.pipeFactories.get(key); - if (null == pipeFactory) { - throw new CouldNotFindPipeImplException(key); - } - return pipeFactory; - } - - /** - * Adds a new PipeFactory to the registry.<br /> - * The new PipeFactory will be automatically selected by the Registry, if it is the most suitable Factory - * corresponding to the requirements. - * - * @param pipeFactory - * A PipeFactory which will be added to the registry - */ - public void register(final IPipeFactory pipeFactory) { - String key = this.buildKey(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable()); - this.pipeFactories.put(key, pipeFactory); - LOGGER.info("Registered pipe factory: " + pipeFactory.getClass().getCanonicalName()); - } - - private String buildKey(final ThreadCommunication tc, final PipeOrdering ordering, final boolean growable) { - return tc.toString() + ordering.toString() + growable; - } -} diff --git a/src/main/java/teetime/framework/pipe/RelayTestPipe.java b/src/main/java/teetime/framework/pipe/RelayTestPipe.java deleted file mode 100644 index 9950af66e27f0b6487cdd8fcd504bb7e49ebb5b3..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/RelayTestPipe.java +++ /dev/null @@ -1,46 +0,0 @@ -package teetime.framework.pipe; - -import teetime.util.ConstructorClosure; - -public final class RelayTestPipe<T> extends InterThreadPipe { - - private int numInputObjects; - private final ConstructorClosure<T> inputObjectCreator; - - public RelayTestPipe(final int numInputObjects, final ConstructorClosure<T> inputObjectCreator) { - super(null, null); - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - @Override - public boolean add(final Object element) { - return false; - } - - @Override - public T removeLast() { - if (this.numInputObjects == 0) { - return null; - } else { - this.numInputObjects--; - return this.inputObjectCreator.create(); - } - } - - @Override - public boolean isEmpty() { - return (this.numInputObjects == 0); - } - - @Override - public int size() { - return this.numInputObjects; - } - - @Override - public T readLast() { - return null; - } - -} diff --git a/src/main/java/teetime/framework/pipe/SingleElementPipe.java b/src/main/java/teetime/framework/pipe/SingleElementPipe.java deleted file mode 100644 index bccc7c9c9adc8331756a756de43994490416669d..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/SingleElementPipe.java +++ /dev/null @@ -1,48 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public final class SingleElementPipe extends IntraThreadPipe { - - private Object element; - - <T> SingleElementPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - super(sourcePort, targetPort); - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - IPipe pipe = new SingleElementPipe(null, null); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - this.element = element; - return true; - } - - @Override - public Object removeLast() { - Object temp = this.element; - this.element = null; - return temp; - } - - @Override - public boolean isEmpty() { - return this.element == null; - } - - @Override - public Object readLast() { - return this.element; - } - - @Override - public int size() { - return (this.element == null) ? 0 : 1; - } - -} diff --git a/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java b/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java deleted file mode 100644 index 7a76c7448953b793cc762241e6b879c18be93051..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/SingleElementPipeFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public class SingleElementPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return create(sourcePort, targetPort, 1); - } - - /** - * Hint: The capacity for this pipe implementation is ignored - */ - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new SingleElementPipe(sourcePort, targetPort); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.ARBITRARY; - } - - @Override - public boolean isGrowable() { - return false; - } - -} diff --git a/src/main/java/teetime/framework/pipe/SpScPipe.java b/src/main/java/teetime/framework/pipe/SpScPipe.java deleted file mode 100644 index 329e4cff5fab0a03a279e74c38c764cd9fb344b6..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/SpScPipe.java +++ /dev/null @@ -1,67 +0,0 @@ -package teetime.framework.pipe; - -import java.util.Queue; - -import org.jctools.queues.QueueFactory; -import org.jctools.queues.spec.ConcurrentQueueSpec; -import org.jctools.queues.spec.Ordering; -import org.jctools.queues.spec.Preference; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public final class SpScPipe extends InterThreadPipe { - - private final Queue<Object> queue; - // statistics - private int numWaits; - - <T> SpScPipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.queue = QueueFactory.newQueue(new ConcurrentQueueSpec(1, 1, capacity, Ordering.FIFO, Preference.THROUGHPUT)); - } - - @Deprecated - public static <T> SpScPipe connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - SpScPipe pipe = new SpScPipe(sourcePort, targetPort, capacity); - pipe.connectPorts(sourcePort, targetPort); - return pipe; - } - - @Override - public boolean add(final Object element) { - // BETTER introduce a QueueIsFullStrategy - while (!this.queue.offer(element)) { - this.numWaits++; - Thread.yield(); - } - - return true; - } - - @Override - public Object removeLast() { - return this.queue.poll(); - } - - @Override - public boolean isEmpty() { - return this.queue.isEmpty(); - } - - @Override - public int size() { - return this.queue.size(); - } - - @Override - public Object readLast() { - return this.queue.peek(); - } - - // BETTER find a solution w/o any thread-safe code in this stage - public synchronized int getNumWaits() { - return this.numWaits; - } - -} diff --git a/src/main/java/teetime/framework/pipe/SpScPipeFactory.java b/src/main/java/teetime/framework/pipe/SpScPipeFactory.java deleted file mode 100644 index 88e4d59bbe0389afc39171e427c1cd2fc2d168ae..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/SpScPipeFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public class SpScPipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return 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/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java deleted file mode 100644 index be8c15457d84011d74606abd0e420500307c06e0..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java +++ /dev/null @@ -1,81 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public final class UnorderedGrowablePipe extends IntraThreadPipe { - - private Object[] elements; - // private final ArrayWrapper2<T> elements = new ArrayWrapper2<T>(2); - private int lastFreeIndex; - - <T> UnorderedGrowablePipe(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - super(sourcePort, targetPort); - this.elements = new Object[capacity]; - } - - @Deprecated - public static <T> void connect(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - IPipe pipe = new UnorderedGrowablePipe(null, null, 4); - pipe.connectPorts(sourcePort, targetPort); - } - - @Override - public boolean add(final Object element) { - if (this.lastFreeIndex == this.elements.length) { - // if (this.lastFreeIndex == this.elements.getCapacity()) { - this.elements = this.grow(); - } - this.elements[this.lastFreeIndex++] = element; - // this.elements.put(this.lastFreeIndex++, element); - return true; - } - - @Override - public Object removeLast() { - // if (this.lastFreeIndex == 0) { - // return null; - // } - Object element = this.elements[--this.lastFreeIndex]; - this.elements[this.lastFreeIndex] = null; - // T element = this.elements.get(--this.lastFreeIndex); - return element; - } - - @Override - public boolean isEmpty() { - return this.lastFreeIndex == 0; - } - - @Override - public Object readLast() { - return this.elements[this.lastFreeIndex - 1]; - // return this.elements.get(this.lastFreeIndex - 1); - } - - @Override - public int size() { - return this.lastFreeIndex; - } - - private Object[] grow() { - int newSize = this.elements.length * 2; - // System.out.println("growing to " + newSize); - return this.newArray(newSize); - } - - // we do not support shrink since it causes too much overhead due to the capacity checks - // private T[] shrink() { - // int newSize = this.elements.length / 2; - // return this.newArray(newSize); - // } - - private Object[] newArray(final int newSize) { - Object[] newElements = new Object[newSize]; - - System.arraycopy(this.elements, 0, newElements, 0, this.elements.length); - - return newElements; - } - -} diff --git a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java deleted file mode 100644 index 7809347aa36c4d10269add05055d7051a6b96c64..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipeFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.framework.pipe; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public class UnorderedGrowablePipeFactory implements IPipeFactory { - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) { - return create(sourcePort, targetPort, 4); - } - - @Override - public <T> IPipe create(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) { - return new UnorderedGrowablePipe(sourcePort, targetPort, capacity); - } - - @Override - public ThreadCommunication getThreadCommunication() { - return ThreadCommunication.INTRA; - } - - @Override - public PipeOrdering getOrdering() { - return PipeOrdering.STACK_BASED; - } - - @Override - public boolean isGrowable() { - return true; - } - -} diff --git a/src/main/java/teetime/framework/signal/ISignal.java b/src/main/java/teetime/framework/signal/ISignal.java deleted file mode 100644 index b94fc752315db55b1ebcdc58f7d21f6a7db10130..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/signal/ISignal.java +++ /dev/null @@ -1,8 +0,0 @@ -package teetime.framework.signal; - -import teetime.framework.AbstractStage; - -public interface ISignal { - - void trigger(AbstractStage stage); -} diff --git a/src/main/java/teetime/framework/signal/StartingSignal.java b/src/main/java/teetime/framework/signal/StartingSignal.java deleted file mode 100644 index d1b7aa5474236f782e6b8436f9934ed87149e9f6..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/signal/StartingSignal.java +++ /dev/null @@ -1,12 +0,0 @@ -package teetime.framework.signal; - -import teetime.framework.AbstractStage; - -public class StartingSignal implements ISignal { - - @Override - public void trigger(final AbstractStage stage) { - stage.onStarting(); - } - -} diff --git a/src/main/java/teetime/framework/signal/TerminatingSignal.java b/src/main/java/teetime/framework/signal/TerminatingSignal.java deleted file mode 100644 index 0aba57bae09d4045d6d76163c86a108206a8d660..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/signal/TerminatingSignal.java +++ /dev/null @@ -1,12 +0,0 @@ -package teetime.framework.signal; - -import teetime.framework.AbstractStage; - -public class TerminatingSignal implements ISignal { - - @Override - public void trigger(final AbstractStage stage) { - stage.onTerminating(); - } - -} diff --git a/src/main/java/teetime/framework/signal/ValidatingSignal.java b/src/main/java/teetime/framework/signal/ValidatingSignal.java deleted file mode 100644 index 2b4858ca45b3ee1d34ec11ecf4f8eb725536bb79..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/signal/ValidatingSignal.java +++ /dev/null @@ -1,22 +0,0 @@ -package teetime.framework.signal; - -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.AbstractStage; -import teetime.framework.validation.InvalidPortConnection; - -public class ValidatingSignal implements ISignal { - - private final List<InvalidPortConnection> invalidPortConnections = new LinkedList<InvalidPortConnection>(); - - @Override - public void trigger(final AbstractStage stage) { - stage.onValidating(this.invalidPortConnections); - } - - public List<InvalidPortConnection> getInvalidPortConnections() { - return invalidPortConnections; - } - -} diff --git a/src/main/java/teetime/framework/validation/AnalysisNotValidException.java b/src/main/java/teetime/framework/validation/AnalysisNotValidException.java deleted file mode 100644 index a827d7f14eb5070fc552321d6805aeeb3853441b..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/validation/AnalysisNotValidException.java +++ /dev/null @@ -1,28 +0,0 @@ -package teetime.framework.validation; - -import java.util.List; - -import com.google.common.base.Joiner; - -public class AnalysisNotValidException extends RuntimeException { - - private static final long serialVersionUID = 455596493924684318L; - - private final List<InvalidPortConnection> invalidPortConnections; - - public AnalysisNotValidException(final List<InvalidPortConnection> invalidPortConnections) { - super(); - this.invalidPortConnections = invalidPortConnections; - - } - - @Override - public String getMessage() { - StringBuilder builder = new StringBuilder(this.invalidPortConnections.size() * 40); - builder.append(this.invalidPortConnections.size()); - builder.append(" invalid port connections were detected.\n"); - Joiner.on("\n").appendTo(builder, this.invalidPortConnections); - return builder.toString(); - } - -} diff --git a/src/main/java/teetime/framework/validation/InvalidPortConnection.java b/src/main/java/teetime/framework/validation/InvalidPortConnection.java deleted file mode 100644 index 183f3700a757c8310ab54fee545742e3bd5fa4e7..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/framework/validation/InvalidPortConnection.java +++ /dev/null @@ -1,32 +0,0 @@ -package teetime.framework.validation; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class InvalidPortConnection { - - private final OutputPort<?> sourcePort; - private final InputPort<?> targetPort; - - public InvalidPortConnection(final OutputPort<?> sourcePort, final InputPort<?> targetPort) { - super(); - this.sourcePort = sourcePort; - this.targetPort = targetPort; - } - - public OutputPort<?> getSourcePort() { - return this.sourcePort; - } - - public InputPort<?> getTargetPort() { - return this.targetPort; - } - - @Override - public String toString() { - String sourcePortTypeName = (this.sourcePort.getType() == null) ? null : this.sourcePort.getType().getName(); - String targetPortTypeName = (this.targetPort.getType() == null) ? null : this.targetPort.getType().getName(); - return sourcePortTypeName + " != " + targetPortTypeName; - } - -} diff --git a/src/main/java/teetime/stage/ByteArray2String.java b/src/main/java/teetime/stage/ByteArray2String.java deleted file mode 100644 index d00ccca99686ae2187273f846132bfddf5abd508..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/ByteArray2String.java +++ /dev/null @@ -1,18 +0,0 @@ -package teetime.stage; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -public class ByteArray2String extends ConsumerStage<byte[]> { - - private final OutputPort<String> outputPort = this.createOutputPort(); - - @Override - protected void execute(final byte[] element) { - this.send(this.outputPort, new String(element)); - } - - public OutputPort<? extends String> getOutputPort() { - return this.outputPort; - } -} diff --git a/src/main/java/teetime/stage/Cache.java b/src/main/java/teetime/stage/Cache.java deleted file mode 100644 index 07b7d2896a04bb5338ff31f63aa09613b8ff9cdf..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/Cache.java +++ /dev/null @@ -1,40 +0,0 @@ -package teetime.stage; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; -import teetime.util.StopWatch; - -public class Cache<T> extends ConsumerStage<T> { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - private final List<T> cachedObjects = new LinkedList<T>(); - - @Override - protected void execute(final T element) { - this.cachedObjects.add(element); - } - - @Override - public void onTerminating() { - super.onTerminating(); - this.logger.debug("Emitting " + this.cachedObjects.size() + " cached elements..."); - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - for (T cachedElement : this.cachedObjects) { - this.send(this.outputPort, cachedElement); - } - stopWatch.end(); - this.logger.debug("Emitting took " + TimeUnit.NANOSECONDS.toMillis(stopWatch.getDurationInNs()) + " ms"); - super.onTerminating(); - } - - public OutputPort<T> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/CipherByteArray.java b/src/main/java/teetime/stage/CipherByteArray.java deleted file mode 100644 index e260f9ab5e58ba910dac8701085ee19f2b685a82..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/CipherByteArray.java +++ /dev/null @@ -1,85 +0,0 @@ -package teetime.stage; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; - -import javax.crypto.Cipher; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.PBEKeySpec; -import javax.crypto.spec.SecretKeySpec; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -public class CipherByteArray extends ConsumerStage<byte[]> { - - private final OutputPort<byte[]> outputPort = this.createOutputPort(); - private Cipher cipher = null; - - public enum CipherMode { - ENCRYPT, DECRYPT - } - - public CipherByteArray(final String password, final CipherMode mode) { - final byte[] salt = { 't', 'e', 's', 't' }; - SecretKeySpec skeyspec = null; - - KeySpec keySpec = new PBEKeySpec(password.toCharArray(), - salt, - 1024, 128); - - SecretKey secretKey = null; - - try { - secretKey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"). - generateSecret(keySpec); - } catch (InvalidKeySpecException e1) { - throw new IllegalStateException(e1); - } catch (NoSuchAlgorithmException e1) { - throw new IllegalStateException(e1); - } - - skeyspec = new SecretKeySpec(secretKey.getEncoded(), "AES"); - - try { - this.cipher = Cipher.getInstance(skeyspec.getAlgorithm()); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException(e); - } catch (NoSuchPaddingException e) { - throw new IllegalStateException(e); - } - - try { - if (mode == CipherMode.ENCRYPT) { - this.cipher.init(Cipher.ENCRYPT_MODE, skeyspec); - } else { - this.cipher.init(Cipher.DECRYPT_MODE, skeyspec); - } - } catch (InvalidKeyException e) { - throw new IllegalStateException(e); - } - } - - @Override - protected void execute(final byte[] element) { - - byte[] output = null; - - try { - output = this.cipher.doFinal(element); - } catch (Exception e) { - e.printStackTrace(); - } - - this.send(this.outputPort, output); - } - - public OutputPort<? extends byte[]> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/Clock.java b/src/main/java/teetime/stage/Clock.java deleted file mode 100644 index e9439886d9c0ac1d5df7d225d43ec46cb49d753f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/Clock.java +++ /dev/null @@ -1,53 +0,0 @@ -package teetime.stage; - -import teetime.framework.ProducerStage; - -public class Clock extends ProducerStage<Long> { - - private boolean initialDelayExceeded = false; - - private long initialDelayInMs; - private long intervalDelayInMs; - - @Override - protected void execute() { - if (!this.initialDelayExceeded) { - this.initialDelayExceeded = true; - this.sleep(this.initialDelayInMs); - } else { - this.sleep(this.intervalDelayInMs); - } - - // this.logger.debug("Emitting timestamp"); - this.send(this.outputPort, this.getCurrentTimeInNs()); - } - - private void sleep(final long delayInMs) { - try { - Thread.sleep(delayInMs); - } catch (InterruptedException e) { - this.terminate(); - } - } - - private long getCurrentTimeInNs() { - return System.nanoTime(); - } - - public long getInitialDelayInMs() { - return this.initialDelayInMs; - } - - public void setInitialDelayInMs(final long initialDelayInMs) { - this.initialDelayInMs = initialDelayInMs; - } - - public long getIntervalDelayInMs() { - return this.intervalDelayInMs; - } - - public void setIntervalDelayInMs(final long intervalDelayInMs) { - this.intervalDelayInMs = intervalDelayInMs; - } - -} diff --git a/src/main/java/teetime/stage/CollectorSink.java b/src/main/java/teetime/stage/CollectorSink.java deleted file mode 100644 index f3b3875dce73a457cc1bec91c195944e7cc9689a..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/CollectorSink.java +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.List; - -import teetime.framework.ConsumerStage; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class CollectorSink<T> extends ConsumerStage<T> { - - // private final InputPort<T> inputPort = this.createInputPort(); - // - // public final InputPort<T> getInputPort() { - // return this.inputPort; - // } - - private final List<T> elements; - private final int threshold; - - public CollectorSink(final List<T> list, final int threshold) { - this.elements = list; - this.threshold = threshold; - } - - public CollectorSink(final List<T> list) { - this(list, 100000); - } - - @Override - public void onTerminating() { - super.onTerminating(); - System.out.println("size: " + this.elements.size()); - } - - @Override - protected void execute(final T element) { - this.elements.add(element); - - if ((this.elements.size() % this.threshold) == 0) { - System.out.println("size: " + this.elements.size()); - } - - // if (this.elements.size() > 90000) { - // // System.out.println("size > 90000: " + this.elements.size()); - // } - } - -} diff --git a/src/main/java/teetime/stage/Counter.java b/src/main/java/teetime/stage/Counter.java deleted file mode 100644 index 7d3d8c9510eba5e774e66c8b2ed7009964344791..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/Counter.java +++ /dev/null @@ -1,27 +0,0 @@ -package teetime.stage; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -public class Counter<T> extends ConsumerStage<T> { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - private int numElementsPassed; - - @Override - protected void execute(final T element) { - this.numElementsPassed++; - // this.logger.debug("count: " + this.numElementsPassed); - this.send(this.outputPort, element); - } - - // BETTER find a solution w/o any thread-safe code in this stage - public synchronized int getNumElementsPassed() { - return this.numElementsPassed; - } - - public OutputPort<T> getOutputPort() { - return this.outputPort; - } -} diff --git a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java b/src/main/java/teetime/stage/ElementDelayMeasuringStage.java deleted file mode 100644 index 452f75e3701d2bb29e74e156b152c5df1156d82f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/ElementDelayMeasuringStage.java +++ /dev/null @@ -1,65 +0,0 @@ -package teetime.stage; - -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.ConsumerStage; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class ElementDelayMeasuringStage<T> extends ConsumerStage<T> { - - private final InputPort<Long> triggerInputPort = this.createInputPort(); - private final OutputPort<T> outputPort = this.createOutputPort(); - - private long numPassedElements; - private long lastTimestampInNs; - - private final List<Long> delays = new LinkedList<Long>(); - - @Override - protected void execute(final T element) { - Long timestampInNs = this.triggerInputPort.receive(); - if (timestampInNs != null) { - this.computeElementDelay(System.nanoTime()); - } - - this.numPassedElements++; - this.send(this.outputPort, element); - } - - @Override - public void onStarting() { - this.resetTimestamp(System.nanoTime()); - super.onStarting(); - } - - private void computeElementDelay(final Long timestampInNs) { - long diffInNs = timestampInNs - this.lastTimestampInNs; - if (this.numPassedElements > 0) { - long delayInNsPerElement = diffInNs / this.numPassedElements; - this.delays.add(delayInNsPerElement); - this.logger.info("Delay: " + delayInNsPerElement + " time units/element"); - - this.resetTimestamp(timestampInNs); - } - } - - private void resetTimestamp(final Long timestampInNs) { - this.numPassedElements = 0; - this.lastTimestampInNs = timestampInNs; - } - - public List<Long> getDelays() { - return this.delays; - } - - public InputPort<Long> getTriggerInputPort() { - return this.triggerInputPort; - } - - public OutputPort<T> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java b/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java deleted file mode 100644 index ea36801a4d4ccbb07868f9582f2fdaab7837f7a9..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/ElementThroughputMeasuringStage.java +++ /dev/null @@ -1,81 +0,0 @@ -package teetime.stage; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import teetime.framework.ConsumerStage; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class ElementThroughputMeasuringStage<T> extends ConsumerStage<T> { - - private final InputPort<Long> triggerInputPort = this.createInputPort(); - private final OutputPort<T> outputPort = this.createOutputPort(); - - private long numPassedElements; - private long lastTimestampInNs; - - private final List<Long> throughputs = new LinkedList<Long>(); - - @Override - protected void execute(final T element) { - Long timestampInNs = this.triggerInputPort.receive(); - if (timestampInNs != null) { - this.computeElementThroughput(System.nanoTime()); - } - this.numPassedElements++; - - this.send(this.outputPort, element); - } - - @Override - public void onStarting() { - this.resetTimestamp(System.nanoTime()); - super.onStarting(); - } - - private void computeElementThroughput(final Long timestampInNs) { - long diffInNs = timestampInNs - this.lastTimestampInNs; - // the minimum time granularity of the clock is ms - long diffInMs = TimeUnit.NANOSECONDS.toMillis(diffInNs); - double throughputPerMs = (double) this.numPassedElements / diffInMs; - this.logger.info("Throughput: " + String.format("%.3f", throughputPerMs) + " elements/ms" + " -> numPassedElements=" + this.numPassedElements); - - // long throughputPerTimeUnit = -1; - // - // long diffInSec = TimeUnit.NANOSECONDS.toSeconds(diffInNs); - // if (diffInSec > 0) { - // throughputPerTimeUnit = this.numPassedElements / diffInSec; - // this.logger.info("Throughput: " + throughputPerTimeUnit + " elements/s" + " -> numPassedElements=" + this.numPassedElements); - // } else { - // long diffInMs = TimeUnit.NANOSECONDS.toMillis(diffInNs); - // if (diffInMs > 0) { - // throughputPerTimeUnit = this.numPassedElements / diffInMs; - // this.logger.info("Throughput: " + throughputPerTimeUnit + " elements/ms" + " -> numPassedElements=" + this.numPassedElements); - // - // } - // } - - this.throughputs.add((long) throughputPerMs); - this.resetTimestamp(timestampInNs); - } - - private void resetTimestamp(final Long timestampInNs) { - this.numPassedElements = 0; - this.lastTimestampInNs = timestampInNs; - } - - public List<Long> getThroughputs() { - return this.throughputs; - } - - public InputPort<Long> getTriggerInputPort() { - return this.triggerInputPort; - } - - public OutputPort<T> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/FileExtensionSwitch.java b/src/main/java/teetime/stage/FileExtensionSwitch.java deleted file mode 100644 index da6099938b7876542b9a3a736d43944157b7d264..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/FileExtensionSwitch.java +++ /dev/null @@ -1,36 +0,0 @@ -package teetime.stage; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -import com.google.common.io.Files; - -public class FileExtensionSwitch extends ConsumerStage<File> { - - private final Map<String, OutputPort<File>> fileExtensions = new HashMap<String, OutputPort<File>>(); - - @Override - protected void execute(final File file) { - String fileExtension = Files.getFileExtension(file.getAbsolutePath()); - this.logger.debug("fileExtension: " + fileExtension); - OutputPort<File> outputPort = this.fileExtensions.get(fileExtension); - if (outputPort != null) { - this.send(outputPort, file); - } - } - - public OutputPort<File> addFileExtension(String fileExtension) { - if (fileExtension.startsWith(".")) { - fileExtension = fileExtension.substring(1); - } - OutputPort<File> outputPort = this.createOutputPort(); - this.fileExtensions.put(fileExtension, outputPort); - this.logger.debug("SUCCESS: Registered output port for '" + fileExtension + "'"); - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/InitialElementProducer.java b/src/main/java/teetime/stage/InitialElementProducer.java deleted file mode 100644 index a5084ce6e6ddca36edb8dbf4f70b5fe19b65022f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/InitialElementProducer.java +++ /dev/null @@ -1,21 +0,0 @@ -package teetime.stage; - -import teetime.framework.ProducerStage; - -public class InitialElementProducer<T> extends ProducerStage<T> { - - private final T[] elements; - - public InitialElementProducer(final T... elements) { - this.elements = elements; - } - - @Override - protected void execute() { - for (T e : this.elements) { - this.send(this.outputPort, e); - } - this.terminate(); - } - -} diff --git a/src/main/java/teetime/stage/InstanceCounter.java b/src/main/java/teetime/stage/InstanceCounter.java deleted file mode 100644 index 30df6693b7d42bfddf88b994c4ec69a6daffba30..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/InstanceCounter.java +++ /dev/null @@ -1,34 +0,0 @@ -package teetime.stage; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -public class InstanceCounter<T, C extends T> extends ConsumerStage<T> { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - private final Class<C> type; - private int counter; - - public InstanceCounter(final Class<C> type) { - this.type = type; - } - - @Override - protected void execute(final T element) { - if (this.type.isInstance(element)) { - this.counter++; - } - - this.send(this.outputPort, element); - } - - public int getCounter() { - return this.counter; - } - - public OutputPort<T> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/InstanceOfFilter.java b/src/main/java/teetime/stage/InstanceOfFilter.java deleted file mode 100644 index 042febae604acfc6d32827dde25ccf24fe0794ad..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/InstanceOfFilter.java +++ /dev/null @@ -1,44 +0,0 @@ -package teetime.stage; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -/** - * @author Jan Waller, Nils Christian Ehmke, Christian Wulf - * - */ -public class InstanceOfFilter<I, O> extends ConsumerStage<I> { - - private final OutputPort<O> outputPort = this.createOutputPort(); - - private Class<O> type; - - public InstanceOfFilter(final Class<O> type) { - this.type = type; - } - - @SuppressWarnings("unchecked") - @Override - protected void execute(final I element) { - if (this.type.isInstance(element)) { - this.send(this.outputPort, (O) element); - } else { // swallow up the element - if (this.logger.isDebugEnabled()) { - this.logger.info("element is not an instance of " + this.type.getName() + ", but of " + element.getClass()); - } - } - } - - public Class<O> getType() { - return this.type; - } - - public void setType(final Class<O> type) { - this.type = type; - } - - public OutputPort<O> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/IterableProducer.java b/src/main/java/teetime/stage/IterableProducer.java deleted file mode 100644 index 7d9eadde0d7e7d686de39a6f0378acd776afb8d8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/IterableProducer.java +++ /dev/null @@ -1,21 +0,0 @@ -package teetime.stage; - -import teetime.framework.ProducerStage; - -public class IterableProducer<O extends Iterable<T>, T> extends ProducerStage<T> { - - private O iter = null; - - public IterableProducer(final O iter) { - this.iter = iter; - } - - @Override - protected void execute() { - for (T i : iter) { - this.send(this.outputPort, i); - } - - } - -} diff --git a/src/main/java/teetime/stage/NoopFilter.java b/src/main/java/teetime/stage/NoopFilter.java deleted file mode 100644 index aaef5e797a0f107cd4d627613fcca38f171d01fd..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/NoopFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.ConsumerStage; -import teetime.framework.OutputPort; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class NoopFilter<T> extends ConsumerStage<T> { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - @Override - protected void execute(final T element) { - this.send(this.outputPort, element); - } - - public OutputPort<T> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/ObjectProducer.java b/src/main/java/teetime/stage/ObjectProducer.java deleted file mode 100644 index f3787ac6283f6f1613bda9af55e09923b36d17c5..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/ObjectProducer.java +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.ProducerStage; -import teetime.util.ConstructorClosure; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class ObjectProducer<T> extends ProducerStage<T> { - - private long numInputObjects; - private ConstructorClosure<T> inputObjectCreator; - - /** - * @since 1.10 - */ - public ObjectProducer(final long numInputObjects, final ConstructorClosure<T> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public long getNumInputObjects() { - return this.numInputObjects; - } - - public void setNumInputObjects(final long numInputObjects) { - this.numInputObjects = numInputObjects; - } - - public ConstructorClosure<T> getInputObjectCreator() { - return this.inputObjectCreator; - } - - public void setInputObjectCreator(final ConstructorClosure<T> inputObjectCreator) { - this.inputObjectCreator = inputObjectCreator; - } - - @Override - protected void execute() { - T newObject = this.inputObjectCreator.create(); - this.numInputObjects--; - - this.send(this.outputPort, newObject); - - if (this.numInputObjects == 0) { - this.terminate(); - } - } - -} diff --git a/src/main/java/teetime/stage/PortTypeConfiguration.java b/src/main/java/teetime/stage/PortTypeConfiguration.java deleted file mode 100644 index 00b9cad4fdb5fe6d156941c6ddf9d271a12c5b60..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/PortTypeConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package teetime.stage; - -import teetime.util.TimestampObject; - -public class PortTypeConfiguration { - - public static <T> void setPortTypes(final ObjectProducer<T> stage, final Class<T> clazz) { - stage.getOutputPort().setType(clazz); - } - - public static <T> void setPortTypes(final CollectorSink<T> stage, final Class<T> clazz) { - stage.getInputPort().setType(clazz); - } - - public static <T> void setPortTypes(final StartTimestampFilter stage) { - stage.getInputPort().setType(TimestampObject.class); - stage.getOutputPort().setType(TimestampObject.class); - } -} diff --git a/src/main/java/teetime/stage/Relay.java b/src/main/java/teetime/stage/Relay.java deleted file mode 100644 index 144b34eaf9d0e6dd7f611b54aa3df28f21e14a00..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/Relay.java +++ /dev/null @@ -1,36 +0,0 @@ -package teetime.stage; - -import teetime.framework.InputPort; -import teetime.framework.ProducerStage; -import teetime.framework.pipe.InterThreadPipe; -import teetime.framework.signal.TerminatingSignal; - -public class Relay<T> extends ProducerStage<T> { - - private final InputPort<T> inputPort = this.createInputPort(); - - private InterThreadPipe cachedCastedInputPipe; - - @Override - public void execute() { - T element = this.inputPort.receive(); - if (null == element) { - if (this.cachedCastedInputPipe.getSignal() instanceof TerminatingSignal) { - this.terminate(); - } - Thread.yield(); - return; - } - this.send(this.outputPort, element); - } - - @Override - public void onStarting() { - this.cachedCastedInputPipe = (InterThreadPipe) this.inputPort.getPipe(); - super.onStarting(); - } - - public InputPort<T> getInputPort() { - return this.inputPort; - } -} diff --git a/src/main/java/teetime/stage/StartTimestampFilter.java b/src/main/java/teetime/stage/StartTimestampFilter.java deleted file mode 100644 index b3ecfe3c06265ac29aab8fda47213b73e0be04ce..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/StartTimestampFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.ConsumerStage; -import teetime.framework.OutputPort; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class StartTimestampFilter extends ConsumerStage<TimestampObject> { - - private final OutputPort<TimestampObject> outputPort = this.createOutputPort(); - - @Override - protected void execute(final TimestampObject element) { - element.setStartTimestamp(System.nanoTime()); - this.send(this.outputPort, element); - } - - public OutputPort<TimestampObject> getOutputPort() { - return this.outputPort; - } -} diff --git a/src/main/java/teetime/stage/StopTimestampFilter.java b/src/main/java/teetime/stage/StopTimestampFilter.java deleted file mode 100644 index 9dff2cf0f067f49847fb241ac8e1fb9636f6926a..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/StopTimestampFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.ConsumerStage; -import teetime.framework.OutputPort; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class StopTimestampFilter extends ConsumerStage<TimestampObject> { - - private final OutputPort<TimestampObject> outputPort = this.createOutputPort(); - - @Override - protected void execute(final TimestampObject element) { - element.setStopTimestamp(System.nanoTime()); - this.send(this.outputPort, element); - } - - public OutputPort<TimestampObject> getOutputPort() { - return this.outputPort; - } -} diff --git a/src/main/java/teetime/stage/Tokenizer.java b/src/main/java/teetime/stage/Tokenizer.java deleted file mode 100644 index 24314cbe083d7db681892c4933f743c9b5822514..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/Tokenizer.java +++ /dev/null @@ -1,29 +0,0 @@ -package teetime.stage; - -import java.util.StringTokenizer; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -public class Tokenizer extends ConsumerStage<String> { - - private final OutputPort<String> outputPort = this.createOutputPort(); - private final String regex; - - public Tokenizer(final String regex) { - this.regex = regex; - } - - @Override - protected void execute(final String element) { - StringTokenizer st = new StringTokenizer(element, this.regex); - while (st.hasMoreTokens()) { - this.send(this.outputPort, st.nextToken()); - } - } - - public OutputPort<? extends String> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/ZipByteArray.java b/src/main/java/teetime/stage/ZipByteArray.java deleted file mode 100644 index ca61720caf000db5aa6c9417151614f0a31d0c3f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/ZipByteArray.java +++ /dev/null @@ -1,88 +0,0 @@ -package teetime.stage; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.zip.DataFormatException; -import java.util.zip.Deflater; -import java.util.zip.Inflater; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -/** - * A stage to compress and decompress byte arrays - * - * @author Nelson Tavares de Sousa - * - */ -public class ZipByteArray extends ConsumerStage<byte[]> { - - private final OutputPort<byte[]> outputPort = this.createOutputPort(); - private final ZipMode mode; - - public enum ZipMode { - COMP, DECOMP - } - - public ZipByteArray(final ZipMode mode) { - this.mode = mode; - } - - @Override - protected void execute(final byte[] element) { - byte[] cache = null; - try { - if (mode == ZipMode.COMP) { - cache = compress(element); - } else { - cache = decompress(element); - } - } catch (Exception e) { - e.printStackTrace(); - } - this.send(this.outputPort, cache); - } - - private byte[] compress(final byte[] data) throws IOException { - Deflater deflater = new Deflater(); - deflater.setInput(data); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); - - deflater.finish(); - byte[] buffer = new byte[1024]; - while (!deflater.finished()) { - int count = deflater.deflate(buffer); // returns the generated code... index - outputStream.write(buffer, 0, count); - } - outputStream.close(); - byte[] output = outputStream.toByteArray(); - - deflater.end(); - - return output; - } - - private byte[] decompress(final byte[] data) throws IOException, DataFormatException { - Inflater inflater = new Inflater(); - inflater.setInput(data); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); - byte[] buffer = new byte[1024]; - while (!inflater.finished()) { - int count = inflater.inflate(buffer); - outputStream.write(buffer, 0, count); - } - outputStream.close(); - byte[] output = outputStream.toByteArray(); - - inflater.end(); - - return output; - } - - public OutputPort<? extends byte[]> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/basic/Delay.java b/src/main/java/teetime/stage/basic/Delay.java deleted file mode 100644 index 09903e8c447f54620a437de8b8fe6db964360cb8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/Delay.java +++ /dev/null @@ -1,49 +0,0 @@ -package teetime.stage.basic; - -import teetime.framework.AbstractStage; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; - -public class Delay<T> extends AbstractStage { - - private final InputPort<T> inputPort = this.createInputPort(); - private final InputPort<Long> timestampTriggerInputPort = this.createInputPort(); - private final OutputPort<T> outputPort = this.createOutputPort(); - - @Override - public void executeWithPorts() { - Long timestampTrigger = this.timestampTriggerInputPort.receive(); - if (null == timestampTrigger) { - return; - } - // System.out.println("got timestamp; #elements: " + this.getInputPort().pipe.size()); - - // System.out.println("#elements: " + this.getInputPort().pipe.size()); - // TODO implement receiveAll() and sendMultiple() - while (!this.inputPort.getPipe().isEmpty()) { - T element = this.inputPort.receive(); - this.send(this.outputPort, element); - } - } - - @Override - public void onTerminating() { - super.onTerminating(); - while (!this.inputPort.getPipe().isEmpty()) { - this.executeWithPorts(); - } - } - - public InputPort<T> getInputPort() { - return this.inputPort; - } - - public InputPort<Long> getTimestampTriggerInputPort() { - return this.timestampTriggerInputPort; - } - - public OutputPort<T> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/basic/Sink.java b/src/main/java/teetime/stage/basic/Sink.java deleted file mode 100644 index e5c5d722ff518d0e776f469ffd600a93cc4ed345..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/Sink.java +++ /dev/null @@ -1,14 +0,0 @@ -package teetime.stage.basic; - -import teetime.framework.ConsumerStage; - -public class Sink<T> extends ConsumerStage<T> { - - // PERFORMANCE let the sink remove all available input at once by using a new method receiveAll() that clears the pipe's buffer - - @Override - protected void execute(final T element) { - // do nothing; just consume - } - -} diff --git a/src/main/java/teetime/stage/basic/distributor/CloneStrategy.java b/src/main/java/teetime/stage/basic/distributor/CloneStrategy.java deleted file mode 100644 index 9512aad0c39eee4528916429423b23bad95ab199..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/distributor/CloneStrategy.java +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.distributor; - -import teetime.framework.OutputPort; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public final class CloneStrategy<T> implements IDistributorStrategy<T> { - - @Override - public boolean distribute(final OutputPort<T>[] outputPorts, final T element) { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/main/java/teetime/stage/basic/distributor/CopyByReferenceStrategy.java b/src/main/java/teetime/stage/basic/distributor/CopyByReferenceStrategy.java deleted file mode 100644 index d5f2697228bbfc7851057eae82e24fa71fe92bcb..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/distributor/CopyByReferenceStrategy.java +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.distributor; - -import teetime.framework.OutputPort; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public final class CopyByReferenceStrategy<T> implements IDistributorStrategy<T> { - - @Override - public boolean distribute(final OutputPort<T>[] outputPorts, final T element) { - for (final OutputPort<T> port : outputPorts) { - port.send(element); - } - - return true; - } - -} diff --git a/src/main/java/teetime/stage/basic/distributor/Distributor.java b/src/main/java/teetime/stage/basic/distributor/Distributor.java deleted file mode 100644 index b80c8e5ef21356fde8b837e2611df330187b75c9..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/distributor/Distributor.java +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.distributor; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -/** - * @author Christian Wulf - * - * @since 1.10 - * - * @param T - * the type of the input port and the output ports - */ -public class Distributor<T> extends ConsumerStage<T> { - - private IDistributorStrategy<T> strategy = new RoundRobinStrategy<T>(); - - @SuppressWarnings("unchecked") - @Override - protected void execute(final T element) { - this.strategy.distribute((OutputPort<T>[]) this.getOutputPorts(), element); - } - - @Override - public void onTerminating() { - super.onTerminating(); - // for (OutputPort<T> op : this.outputPortList) { - // op.getPipe().close(); - // System.out.println("End signal sent, size: " + op.getPipe().size()); - // } - } - - public OutputPort<T> getNewOutputPort() { - return this.createOutputPort(); - } - - public IDistributorStrategy<T> getStrategy() { - return this.strategy; - } - - public void setStrategy(final IDistributorStrategy<T> strategy) { - this.strategy = strategy; - } - -} diff --git a/src/main/java/teetime/stage/basic/distributor/IDistributorStrategy.java b/src/main/java/teetime/stage/basic/distributor/IDistributorStrategy.java deleted file mode 100644 index 69e537877b6b04181f527e6f59096d5557dd259b..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/distributor/IDistributorStrategy.java +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.distributor; - -import teetime.framework.OutputPort; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public interface IDistributorStrategy<T> { - - public boolean distribute(final OutputPort<T>[] allOutputPorts, final T element); - -} diff --git a/src/main/java/teetime/stage/basic/distributor/RoundRobinStrategy.java b/src/main/java/teetime/stage/basic/distributor/RoundRobinStrategy.java deleted file mode 100644 index 64bf90f0fc8da79b3b2c0b999c35d6d7ace319be..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/distributor/RoundRobinStrategy.java +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.distributor; - -import teetime.framework.OutputPort; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public final class RoundRobinStrategy<T> implements IDistributorStrategy<T> { - - private int index = 0; - - @Override - public boolean distribute(final OutputPort<T>[] outputPorts, final T element) { - final OutputPort<T> outputPort = this.getNextPortInRoundRobinOrder(outputPorts); - - outputPort.send(element); - - return true; - } - - private OutputPort<T> getNextPortInRoundRobinOrder(final OutputPort<T>[] outputPorts) { - final OutputPort<T> outputPort = outputPorts[this.index]; - - this.index = (this.index + 1) % outputPorts.length; - - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/basic/merger/IMergerStrategy.java b/src/main/java/teetime/stage/basic/merger/IMergerStrategy.java deleted file mode 100644 index 0114cf9b54bd1f614fb9de9bd99c7e136bd3859c..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/merger/IMergerStrategy.java +++ /dev/null @@ -1,27 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.merger; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public interface IMergerStrategy<T> { - - public T getNextInput(Merger<T> merger); - -} diff --git a/src/main/java/teetime/stage/basic/merger/Merger.java b/src/main/java/teetime/stage/basic/merger/Merger.java deleted file mode 100644 index 870b22b90832de34648468ba03f7c67abc7c21b4..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/merger/Merger.java +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.merger; - -import teetime.framework.AbstractStage; -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -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. - * - * @author Christian Wulf - * - * @since 1.10 - * - * @param <T> - * the type of the input ports and the output port - */ -public class Merger<T> extends AbstractStage { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - private int finishedInputPorts; - - private IMergerStrategy<T> strategy = new RoundRobinStrategy<T>(); - - @Override - public void executeWithPorts() { - final T token = this.strategy.getNextInput(this); - if (token == null) { - return; - } - - this.send(this.outputPort, token); - } - - @Override - public void onSignal(final ISignal signal, final InputPort<?> inputPort) { - this.logger.trace("Got signal: " + signal + " from input port: " + inputPort); - - signal.trigger(this); - - if (this.finishedInputPorts == this.getInputPorts().length) { - this.outputPort.sendSignal(signal); - } - } - - @Override - public void onTerminating() { - super.onTerminating(); - this.finishedInputPorts++; - } - - public IMergerStrategy<T> getStrategy() { - return this.strategy; - } - - public void setStrategy(final IMergerStrategy<T> strategy) { - this.strategy = strategy; - } - - @Override - public InputPort<?>[] getInputPorts() { - return super.getInputPorts(); - } - - public InputPort<T> getNewInputPort() { - return this.createInputPort(); - } - - public OutputPort<T> getOutputPort() { - return this.outputPort; - } - -} diff --git a/src/main/java/teetime/stage/basic/merger/RoundRobinStrategy.java b/src/main/java/teetime/stage/basic/merger/RoundRobinStrategy.java deleted file mode 100644 index 3edb04787f01f3d2d26587def8638e13bb7aa265..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/basic/merger/RoundRobinStrategy.java +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.basic.merger; - -import teetime.framework.InputPort; - -/** - * @author Nils Christian Ehmke - * - * @since 1.10 - */ -public final class RoundRobinStrategy<T> implements IMergerStrategy<T> { - - private int index = 0; - - @Override - public T getNextInput(final Merger<T> merger) { - @SuppressWarnings("unchecked") - InputPort<T>[] inputPorts = (InputPort<T>[]) merger.getInputPorts(); - int size = inputPorts.length; - // check each port at most once to avoid a potentially infinite loop - while (size-- > 0) { - InputPort<T> inputPort = this.getNextPortInRoundRobinOrder(inputPorts); - final T token = inputPort.receive(); - if (token != null) { - return token; - } - } - return null; - } - - private InputPort<T> getNextPortInRoundRobinOrder(final InputPort<T>[] inputPorts) { - InputPort<T> inputPort = inputPorts[this.index]; - - this.index = (this.index + 1) % inputPorts.length; - - return inputPort; - } - -} diff --git a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java deleted file mode 100644 index 3df492b430963d2258bb98cfb5173f5e52a625c2..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.stage.io; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -import teetime.framework.ConsumerStage; - -import com.google.common.io.Files; - -public class ByteArrayFileWriter extends ConsumerStage<byte[]> { - - private final File file; - - public ByteArrayFileWriter(final File file) { - this.file = file; - try { - Files.touch(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - protected void execute(final byte[] element) { - FileOutputStream fo; - try { - fo = new FileOutputStream(this.file); - fo.write(element); - fo.close(); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} diff --git a/src/main/java/teetime/stage/io/Directory2FilesFilter.java b/src/main/java/teetime/stage/io/Directory2FilesFilter.java deleted file mode 100644 index cd45fc7bb84680d8494ee194de3cc1c34f503408..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/io/Directory2FilesFilter.java +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.io; - -import java.io.File; -import java.io.FileFilter; -import java.util.Arrays; -import java.util.Comparator; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class Directory2FilesFilter extends ConsumerStage<File> { - - private final OutputPort<File> outputPort = this.createOutputPort(); - - private FileFilter filter; - private Comparator<File> fileComparator; - - /** - * @since 1.10 - */ - public Directory2FilesFilter(final FileFilter fileFilter) { - this.setFilter(fileFilter); - } - - /** - * @since 1.10 - */ - public Directory2FilesFilter(final Comparator<File> fileComparator) { - this.setFileComparator(fileComparator); - } - - /** - * @since 1.10 - */ - public Directory2FilesFilter(final FileFilter fileFilter, final Comparator<File> fileComparator) { - this.setFilter(fileFilter); - this.setFileComparator(fileComparator); - } - - /** - * @since 1.10 - */ - public Directory2FilesFilter() { - super(); - } - - @Override - protected void execute(final File inputDir) { - final File[] inputFiles = inputDir.listFiles(this.filter); - - if (inputFiles == null) { - this.logger.error("Directory '" + inputDir + "' does not exist or an I/O error occured."); - return; - } - - if (this.fileComparator != null) { - Arrays.sort(inputFiles, this.fileComparator); - } - - for (final File file : inputFiles) { - this.send(this.outputPort, file); - } - } - - public FileFilter getFilter() { - return this.filter; - } - - public void setFilter(final FileFilter filter) { - this.filter = filter; - } - - public Comparator<File> getFileComparator() { - return this.fileComparator; - } - - public void setFileComparator(final Comparator<File> fileComparator) { - this.fileComparator = fileComparator; - } - - public OutputPort<File> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/io/File2ByteArray.java b/src/main/java/teetime/stage/io/File2ByteArray.java deleted file mode 100644 index 390598a17bc13d0a5c9dbbb5a1ba684dc338235a..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/io/File2ByteArray.java +++ /dev/null @@ -1,39 +0,0 @@ -package teetime.stage.io; - -import java.io.File; -import java.io.IOException; - -import teetime.framework.ConsumerStage; -import teetime.framework.HeadStage; -import teetime.framework.OutputPort; - -import com.google.common.io.Files; - -public class File2ByteArray extends ConsumerStage<File> implements HeadStage { - - private final OutputPort<byte[]> outputPort = this.createOutputPort(); - - @Override - protected void execute(final File element) { - try { - byte[] cache = Files.toByteArray(element); - this.send(this.outputPort, cache); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public OutputPort<? extends byte[]> getOutputPort() { - 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 deleted file mode 100644 index c4795559e3ca299ca49492702e76e2fc14a561a8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/io/File2TextLinesFilter.java +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.io; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; - -import teetime.framework.ConsumerStage; -import teetime.framework.OutputPort; -import teetime.stage.util.TextLine; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class File2TextLinesFilter extends ConsumerStage<File> { - - private final OutputPort<TextLine> outputPort = this.createOutputPort(); - - private String charset = "UTF-8"; - - @Override - protected void execute(final File textFile) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(new FileInputStream(textFile), this.charset)); - String line; - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.length() != 0) { - this.send(this.outputPort, new TextLine(textFile, line)); - } // else: ignore empty line - } - } catch (final FileNotFoundException e) { - this.logger.error("", e); - } catch (final IOException e) { - this.logger.error("", e); - } finally { - try { - if (reader != null) { - reader.close(); - } - } catch (final IOException e) { - this.logger.warn("", e); - } - } - } - - public String getCharset() { - return this.charset; - } - - public void setCharset(final String charset) { - this.charset = charset; - } - - public OutputPort<TextLine> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/io/Printer.java b/src/main/java/teetime/stage/io/Printer.java deleted file mode 100644 index 40ee69ee69202d70a1d25d744e66b4e39d9b8843..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/io/Printer.java +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.io; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; - -import teetime.framework.ConsumerStage; - -/** - * A filter to print objects to a configured stream - * - * @author Matthias Rohr, Jan Waller, Nils Christian Ehmke - * - * @since 1.10 - */ -public class Printer<T> extends ConsumerStage<T> { - - public static final String STREAM_STDOUT = "STDOUT"; - public static final String STREAM_STDERR = "STDERR"; - public static final String STREAM_STDLOG = "STDlog"; - public static final String STREAM_NULL = "NULL"; - - public static final String ENCODING_UTF8 = "UTF-8"; - - private PrintStream printStream; - private String streamName = STREAM_STDOUT; - private String encoding = ENCODING_UTF8; - private boolean active = true; - private boolean append = true; - - @Override - protected void execute(final T object) { - if (this.active) { - final StringBuilder sb = new StringBuilder(128); - - sb.append(super.getId()); - sb.append('(').append(object.getClass().getSimpleName()).append(") ").append(object.toString()); - - final String msg = sb.toString(); - if (this.printStream != null) { - this.printStream.println(msg); - } else { - super.logger.info(msg); - } - } - } - - public String getStreamName() { - return this.streamName; - } - - public void setStreamName(final String streamName) { - this.streamName = streamName; - } - - public String getEncoding() { - return this.encoding; - } - - public void setEncoding(final String encoding) { - this.encoding = encoding; - } - - public boolean isAppend() { - return this.append; - } - - public void setAppend(final boolean append) { - this.append = append; - } - - @Override - public void onStarting() { - super.onStarting(); - this.initializeStream(); - } - - @Override - public void onTerminating() { - this.closeStream(); - super.onTerminating(); - } - - private void initializeStream() { - if (STREAM_STDOUT.equals(this.streamName)) { - this.printStream = System.out; - this.active = true; - } else if (STREAM_STDERR.equals(this.streamName)) { - this.printStream = System.err; - this.active = true; - } else if (STREAM_STDLOG.equals(this.streamName)) { - this.printStream = null; - this.active = true; - } else if (STREAM_NULL.equals(this.streamName)) { - this.printStream = null; - this.active = false; - } else { - try { - this.printStream = new PrintStream(new FileOutputStream(this.streamName, this.append), false, this.encoding); - this.active = true; - } catch (final FileNotFoundException ex) { - this.active = false; - super.logger.warn("Stream could not be created", ex); - } catch (final UnsupportedEncodingException ex) { - this.active = false; - super.logger.warn("Encoding not supported", ex); - } - } - } - - private void closeStream() { - if ((this.printStream != null) && (this.printStream != System.out) && (this.printStream != System.err)) { - this.printStream.close(); - } - } - -} diff --git a/src/main/java/teetime/stage/stringBuffer/handler/AbstractDataTypeHandler.java b/src/main/java/teetime/stage/stringBuffer/handler/AbstractDataTypeHandler.java deleted file mode 100644 index f58688df027c7ab160fabf1a55ddb1f708e161b0..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/stringBuffer/handler/AbstractDataTypeHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.stringBuffer.handler; - -import org.slf4j.Logger; - -import teetime.stage.stringBuffer.util.KiekerHashMap; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public abstract class AbstractDataTypeHandler<T> { - - protected Logger logger; - protected KiekerHashMap stringRepository; - - /** - * @since 1.10 - */ - public abstract boolean canHandle(Object object); - - /** - * @since 1.10 - */ - public abstract T handle(T object); - - /** - * @since 1.10 - */ - public void setLogger(final Logger logger) { - this.logger = logger; - } - - /** - * @since 1.10 - */ - public void setStringRepository(final KiekerHashMap stringRepository) { - this.stringRepository = stringRepository; - } - -} diff --git a/src/main/java/teetime/stage/stringBuffer/handler/StringHandler.java b/src/main/java/teetime/stage/stringBuffer/handler/StringHandler.java deleted file mode 100644 index 82c356faf7727ec9d4b1521a9aceb8594837afca..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/stringBuffer/handler/StringHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.stringBuffer.handler; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class StringHandler extends AbstractDataTypeHandler<String> { - - @Override - public boolean canHandle(final Object object) { - return object instanceof String; - } - - @Override - public String handle(final String object) { - return this.stringRepository.get(object); - } - -} diff --git a/src/main/java/teetime/stage/stringBuffer/util/KiekerHashMap.java b/src/main/java/teetime/stage/stringBuffer/util/KiekerHashMap.java deleted file mode 100644 index 22542a58e94def8f0df6da4500332b422c550d55..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/stringBuffer/util/KiekerHashMap.java +++ /dev/null @@ -1,291 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.stringBuffer.util; - -import java.lang.ref.SoftReference; -import java.util.concurrent.locks.ReentrantLock; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class KiekerHashMap { - - private static final int INITIAL_CAPACITY = 16; - private static final double LOAD_FACTOR = 0.75d; - private static final int CONCURRENCY_LEVEL = 16; - private static final int MAXIMUM_CAPACITY = 1 << 30; - - /** - * Mask value for indexing into segments. The upper bits of a key's hash code are used to choose the segment. - */ - private final int segmentMask; - - /** - * Shift value for indexing within segments. - */ - private final int segmentShift; - - /** - * The segments, each of which is a specialized hash table. - */ - private final Segment[] segments; - - /** - * @since 1.10 - */ - public KiekerHashMap() { - // Find power-of-two sizes best matching arguments - int sshift = 0; - int ssize = 1; - while (ssize < CONCURRENCY_LEVEL) { - ++sshift; - ssize <<= 1; - } - this.segmentShift = 32 - sshift; - this.segmentMask = ssize - 1; - this.segments = new Segment[ssize]; - int c = INITIAL_CAPACITY / ssize; - if ((c * ssize) < INITIAL_CAPACITY) { - ++c; - } - int cap = 1; - while (cap < c) { - cap <<= 1; - } - for (int i = 0; i < this.segments.length; ++i) { - this.segments[i] = new Segment(cap, LOAD_FACTOR); - } - } - - /** - * Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions. This is critical because ConcurrentHashMap uses - * power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits. - */ - private static final int hash(final String value) { - // Spread bits to regularize both segment and index locations, using variant of single-word Wang/Jenkins hash. - int h = value.hashCode(); - h += (h << 15) ^ 0xffffcd7d; - h ^= h >>> 10; - h += h << 3; - h ^= h >>> 6; - h += (h << 2) + (h << 14); - return h ^ (h >>> 16); - } - - public final String get(final String value) { - final int hash = KiekerHashMap.hash(value); - Segment segment = this.segments[(hash >>> this.segmentShift) & this.segmentMask]; - return segment.get(value, hash); - } - - // ---------------- Inner Classes -------------- - - /** - * StringBuffer entry. - */ - private static final class HashEntry extends SoftReference<String> { - final int hash; // NOPMD NOCS (package visible for inner class) - final HashEntry next; // NOPMD NOCS (package visible for inner class) - - protected HashEntry(final String value, final int hash, final HashEntry next) { - super(value); - this.hash = hash; - this.next = next; - } - } - - /** - * Segments are specialized versions of hash tables. This subclasses from ReentrantLock opportunistically, just to simplify some locking and avoid separate - * construction. - * - * Segments maintain a table of entry lists that are ALWAYS kept in a consistent state, so can be read without locking. Next fields of nodes are immutable - * (final). All list additions are performed at the front of each bin. This makes it easy to check changes, and also fast to traverse. When nodes would - * otherwise be changed, new nodes are created to replace them. This works well for hash tables since the bin lists tend to be short. (The average length is - * less than two for the default load factor threshold.) - * - * Read operations can thus proceed without locking, but rely on selected uses of volatiles to ensure that completed write operations performed by other - * threads are noticed. For most purposes, the "count" field, tracking the number of elements, serves as that volatile variable ensuring visibility. This is - * convenient because this field needs to be read in many read operations anyway: - * - * - All (unsynchronized) read operations must first read the "count" field, and should not look at table entries if it is 0. - * - * - All (synchronized) write operations should write to the "count" field after structurally changing any bin. The operations must not take any action that - * could even momentarily cause a concurrent read operation to see inconsistent data. This is made easier by the nature of the read operations in Map. For - * example, no operation can reveal that the table has grown but the threshold has not yet been updated, so there are no atomicity requirements for this with - * respect to reads. - * - * As a guide, all critical volatile reads and writes to the count field are marked in code comments. - */ - private static final class Segment extends ReentrantLock { - - private static final long serialVersionUID = 1L; - - /** - * The number of elements in this segment's region. - */ - private volatile int count; - - /** - * The per-segment table. - */ - private HashEntry[] table; - - /** - * The table is rehashed when its size exceeds this threshold. (The value of this field is always <tt>(int)(capacity * loadFactor)</tt>.) - */ - private int threshold; - - protected Segment(final int initialCapacity, final double lf) { - this.table = new HashEntry[initialCapacity]; - this.threshold = (int) (initialCapacity * lf); - this.count = 0; - } - - protected final String get(final String value, final int hash) { - HashEntry e = null; - String cachedString; - if (this.count != 0) { // volatile read! search for entry without locking - final HashEntry[] tab = this.table; - final int index = hash & (tab.length - 1); - final HashEntry first = tab[index]; - e = first; - while (e != null) { - if (e.hash == hash) { - cachedString = e.get(); - if (value.equals(cachedString)) { - return cachedString; - } - } - e = e.next; - } - } - this.lock(); - try { - final int c = this.count + 1; - if (c >= this.threshold) { - this.cleanup(); - if (c >= this.threshold) { // if still full - this.rehash(); - } - this.count = c; // write volatile - } - final HashEntry[] tab = this.table; - final int index = hash & (tab.length - 1); - final HashEntry first = tab[index]; // the bin the value may be inside - e = first; - while (e != null) { - if (e.hash == hash) { - cachedString = e.get(); - if (value.equals(cachedString)) { - return cachedString; - } - } - e = e.next; - } - tab[index] = new HashEntry(value, hash, first); - this.count = c; // write-volatile - return value; // return now cached string - } finally { - this.unlock(); - } - } - - private final void cleanup() { - int c = this.count; - final HashEntry[] tab = this.table; - for (int index = 0; index < tab.length; index++) { - // find first remaining entry - HashEntry e = tab[index]; - while ((e != null) && (e.get() == null)) { - e = e.next; - c--; - } - if (e == null) { - tab[index] = null; - } else { - // find more existing entries and enqueue before this one - HashEntry first = new HashEntry(e.get(), e.hash, null); - e = e.next; - while (e != null) { - final String s = e.get(); - if (s != null) { - first = new HashEntry(s, e.hash, first); - } else { - c--; - } - e = e.next; - } - tab[index] = first; - } - } - c--; - this.count = c; // write-volatile - } - - /** - * Reclassify nodes in each list to new Map. Because we are using power-of-two expansion, the elements from each bin must either stay at same index, or - * move with a power of two offset. We eliminate unnecessary node creation by catching cases where old nodes can be reused because their next fields - * won't change. Statistically, at the default threshold, only about one-sixth of them need cloning when a table doubles. The nodes they replace will be - * garbage collectable as soon as they are no longer referenced by any reader thread that may be in the midst of traversing table right now. - */ - private final void rehash() { - final HashEntry[] oldTable = this.table; - final int oldCapacity = oldTable.length; - if (oldCapacity >= MAXIMUM_CAPACITY) { - return; - } - final HashEntry[] newTable = new HashEntry[oldCapacity << 1]; - this.threshold = (int) (newTable.length * LOAD_FACTOR); - final int sizeMask = newTable.length - 1; - for (int i = 0; i < oldCapacity; i++) { - // We need to guarantee that any existing reads of old Map can proceed. So we cannot yet null out each bin. - final HashEntry e = oldTable[i]; - - if (e != null) { - final HashEntry next = e.next; - final int idx = e.hash & sizeMask; - - // Single node on list - if (next == null) { - newTable[idx] = e; - } else { - // Reuse trailing consecutive sequence at same slot - HashEntry lastRun = e; - int lastIdx = idx; - for (HashEntry last = next; last != null; last = last.next) { // find end of bin - final int k = last.hash & sizeMask; - if (k != lastIdx) { // NOCS (nested if) - lastIdx = k; - lastRun = last; - } - } - newTable[lastIdx] = lastRun; - - // Clone all remaining nodes - for (HashEntry p = e; p != lastRun; p = p.next) { // NOPMD (no equals meant here) - final int k = p.hash & sizeMask; - final HashEntry n = newTable[k]; - newTable[k] = new HashEntry(p.get(), p.hash, n); - } - } - } - } - this.table = newTable; - } - } -} diff --git a/src/main/java/teetime/stage/util/MappingException.java b/src/main/java/teetime/stage/util/MappingException.java deleted file mode 100644 index 40a83811c337bcbfbe56b9437bd7bfbbad790999..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/util/MappingException.java +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MappingException extends Exception { - - private static final long serialVersionUID = 7300752837946139350L; - - public MappingException(final String text) { - super(text); - } - -} diff --git a/src/main/java/teetime/stage/util/TextLine.java b/src/main/java/teetime/stage/util/TextLine.java deleted file mode 100644 index deb5ed8ab60c1aadf3bc2d93c112d57260e5dc02..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/util/TextLine.java +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.io.File; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class TextLine { - - private final File textFile; - private final String textLine; - - /** - * @since 1.10 - */ - public TextLine(final File textFile, final String textLine) { - this.textFile = textFile; - this.textLine = textLine; - } - - public File getTextFile() { - return this.textFile; - } - - public String getTextLine() { - return this.textLine; - } -} diff --git a/src/main/java/teetime/util/ArrayWrapper.java b/src/main/java/teetime/util/ArrayWrapper.java deleted file mode 100644 index 96e17fb56c51fe01b1b4a172d29a25ec59beab77..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/ArrayWrapper.java +++ /dev/null @@ -1,27 +0,0 @@ -package teetime.util; - -public final class ArrayWrapper<T> { - - private final T[] elements; - - // private int lastFreeIndex; - - @SuppressWarnings("unchecked") - public ArrayWrapper(final int initialCapacity) { - super(); - this.elements = (T[]) new Object[initialCapacity]; - } - - public final T get(final int index) { - return this.elements[index]; - } - - public final void put(final int index, final T element) { - this.elements[index] = element; - } - - public final int getCapacity() { - return this.elements.length; - } - -} diff --git a/src/main/java/teetime/util/ConstructorClosure.java b/src/main/java/teetime/util/ConstructorClosure.java deleted file mode 100644 index 4fefbf487c0337164c3732632c4f99c5c5f1c15b..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/ConstructorClosure.java +++ /dev/null @@ -1,8 +0,0 @@ -package teetime.util; - -public interface ConstructorClosure<O> { - - // O create(); - - O create(); -} diff --git a/src/main/java/teetime/util/CyclicListIterator.java b/src/main/java/teetime/util/CyclicListIterator.java deleted file mode 100644 index 71e70bbb60a2002ab498c19b4298344c52b2e054..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/CyclicListIterator.java +++ /dev/null @@ -1,54 +0,0 @@ -package teetime.util; - -import java.util.Iterator; -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> { - - private final List<T> list; - // private Iterator<T> iterator; - - private int currentIndex = 0; - - public CyclicListIterator(final List<T> list) { - this.list = list; - // this.iterator = this.list.iterator(); - } - - public boolean hasNext() { - return true; - } - - public T next() { - // if (!this.iterator.hasNext()) { - // this.iterator = this.list.iterator(); - // } - // return this.iterator.next(); - - // the size of the list could have been changed due to - // <li>an index overflow (then restart from index 0), or - // <li>an add() or a remove(), so update the index - this.currentIndex = this.getCurrentIndex(); - final T element = this.list.get(this.currentIndex); - this.currentIndex++; - return element; - } - - public void remove() { - // this.iterator.remove(); - this.currentIndex = this.getCurrentIndex(); - this.list.remove(this.currentIndex); - } - - private int getCurrentIndex() { - return this.currentIndex % this.list.size(); - } - -} diff --git a/src/main/java/teetime/util/HashMapWithDefault.java b/src/main/java/teetime/util/HashMapWithDefault.java deleted file mode 100644 index 4292c243059611ebd72f39adf648f6d49a92648e..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/HashMapWithDefault.java +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util; - -import java.util.HashMap; - -import teetime.util.concurrent.hashmap.ValueFactory; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class HashMapWithDefault<K, V> extends HashMap<K, V> { - - private static final long serialVersionUID = -7958038532219740472L; - - private final ValueFactory<V> valueFactory; - - /** - * @since 1.10 - */ - public HashMapWithDefault(final ValueFactory<V> valueFactory) { - this.valueFactory = valueFactory; - } - - /** - * @return the corresponding value if the key exists. Otherwise, it creates, - * inserts, and returns a new default value. - */ - @SuppressWarnings("unchecked") - @Override - public V get(final Object key) { - V value = super.get(key); - if (value == null) { - value = this.valueFactory.create(); - super.put((K) key, value); - } - return value; - } -} diff --git a/src/main/java/teetime/util/ListUtil.java b/src/main/java/teetime/util/ListUtil.java deleted file mode 100644 index bea4f12ebfcdb50f5b97cef016f455c37d3ed413..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/ListUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -package teetime.util; - -import java.util.Collection; -import java.util.List; - -public class ListUtil { - - private ListUtil() { - // utility class - } - - public static <T> List<T> merge(final List<List<T>> listOfLists) { - List<T> resultList = listOfLists.get(0); - for (int i = 1; i < listOfLists.size(); i++) { - Collection<? extends T> timestampObjectList = listOfLists.get(i); - resultList.addAll(timestampObjectList); - } - return resultList; - } - - public static <T> List<T> removeFirstHalfElements(final List<T> list) { - if (list.size() < 2) { - return list; - } - return list.subList(list.size() / 2 - 1, list.size()); - } -} diff --git a/src/main/java/teetime/util/MathUtil.java b/src/main/java/teetime/util/MathUtil.java deleted file mode 100644 index 71a36bc0340811b246c5ce21abbf59ccd53a1c30..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/MathUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util; - -import java.util.List; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MathUtil { - - private MathUtil() { - // utility class - } - - public static double getVariance(final List<Long> values, final long avgValue) { - double sum = 0; - for (final long val : values) { - final long diff = val - avgValue; - sum += (diff * diff) / (values.size() - 1); - } - return sum; - } - - public static double getConfidenceWidth(final double z, final double variance, final long n) { - return z * Math.sqrt(variance / n); - } - - public static double getConfidenceWidth(final double z, final List<Long> values, final long avgValue) { - final double variance = MathUtil.getVariance(values, avgValue); - final double confidenceWidth = MathUtil.getConfidenceWidth(z, variance, values.size()); - return confidenceWidth; - } -} diff --git a/src/main/java/teetime/util/Pair.java b/src/main/java/teetime/util/Pair.java deleted file mode 100644 index 2f5018057b1e88b19f5a5f81fb41f686a7f0cd19..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/Pair.java +++ /dev/null @@ -1,25 +0,0 @@ -package teetime.util; - -public class Pair<F, S> { - - private final F first; - private final S second; - - public Pair(final F first, final S second) { - this.first = first; - this.second = second; - } - - public static <F, S> Pair<F, S> of(final F first, final S second) { - return new Pair<F, S>(first, second); - } - - public F getFirst() { - return this.first; - } - - public S getSecond() { - return this.second; - } - -} diff --git a/src/main/java/teetime/util/StacklessException.java b/src/main/java/teetime/util/StacklessException.java deleted file mode 100644 index 8d6be60768473bfda5a2ca1352e66bfd26064e2a..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/StacklessException.java +++ /dev/null @@ -1,12 +0,0 @@ -package teetime.util; - -public class StacklessException extends RuntimeException { - - private static final long serialVersionUID = -9040980547278981254L; - - @Override - public synchronized Throwable fillInStackTrace() { // greatly improves performance when constructing - return this; - } - -} diff --git a/src/main/java/teetime/util/StopWatch.java b/src/main/java/teetime/util/StopWatch.java deleted file mode 100644 index 8b13d08335af0182fa22177b237fca9c89302c56..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/StopWatch.java +++ /dev/null @@ -1,19 +0,0 @@ -package teetime.util; - -public final class StopWatch { - - private long startTimeInNs; - private long endTimeInNs; - - public final void start() { - this.startTimeInNs = System.nanoTime(); - } - - public final void end() { - this.endTimeInNs = System.nanoTime(); - } - - public final long getDurationInNs() { - return this.endTimeInNs - this.startTimeInNs; - } -} diff --git a/src/main/java/teetime/util/TimestampObject.java b/src/main/java/teetime/util/TimestampObject.java deleted file mode 100644 index d47cf229329cdcaf16cf86644ac066436a86da83..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/TimestampObject.java +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util; - -/** - * Object for performance evaluation - * - * @author Christian Wulf - * - * @since 1.10 - */ -public final class TimestampObject { - - @SuppressWarnings("PMD.CommentRequired") - private long startTimestamp; - - @SuppressWarnings("PMD.CommentRequired") - private long stopTimestamp; - - @SuppressWarnings("PMD.CommentRequired") - public long getStartTimestamp() { - return this.startTimestamp; - } - - @SuppressWarnings("PMD.CommentRequired") - public void setStartTimestamp(final long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - @SuppressWarnings("PMD.CommentRequired") - public long getStopTimestamp() { - return this.stopTimestamp; - } - - @SuppressWarnings("PMD.CommentRequired") - public void setStopTimestamp(final long stopTimestamp) { - this.stopTimestamp = stopTimestamp; - } -} diff --git a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java b/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java deleted file mode 100644 index 913b0724253d00b9b4f93d61c3fa061f65c1ce85..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/hashmap/ConcurrentHashMapWithDefault.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.util.concurrent.hashmap; - -import java.util.concurrent.ConcurrentHashMap; - -public class ConcurrentHashMapWithDefault<K, V> extends ConcurrentHashMap<K, V> { - - private static final long serialVersionUID = 199185976241037967L; - - private final ValueFactory<V> valueFactory; - - private int maxElements; - - public ConcurrentHashMapWithDefault(final ValueFactory<V> valueFactory) { - this.valueFactory = valueFactory; - } - - public V getOrCreate(final K key) { - V value = this.get(key); - if (value == null) { - synchronized (this) { - value = this.get(key); - if (value == null) { // NOCS (DCL) - value = this.valueFactory.create(); - this.put(key, value); - this.maxElements++; - } - } - } - return value; - } - - public int getMaxElements() { - return this.maxElements; - } -} diff --git a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java b/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java deleted file mode 100644 index 3cca62d6204c19264f4d94f0fea94fd128b29588..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/hashmap/ValueFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.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/CircularArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularArray.java deleted file mode 100644 index e48177abff54c3e955b243a85c6198efd6e62cf2..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularArray.java +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularArray<T> { - - private final long logSize; - private final T[] segment; - private final long mask; - private long currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularArray(final long logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.mask = this.getCapacity() - 1; // mask = 0..01..1 - } - - public long getCapacity() { - return this.segment.length; - } - - public T get(final long i) { - return this.segment[(int) (i & this.mask)]; // risk of overflow - } - - public T getNext() { - long index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) & this.mask; - return this.segment[(int) index]; - } - - public void put(final long i, final T o) { - this.segment[(int) (i & this.mask)] = o; // risk of overflow - } - - public CircularArray<T> grow(final long b, final long t) { - final CircularArray<T> a = new CircularArray<T>(this.logSize + 1); - for (long i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularArray<T> shrink(final long b, final long t) { - final CircularArray<T> a = new CircularArray<T>(this.logSize - 1); - for (long i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java deleted file mode 100644 index cb1a52f86a3c99879b5bc54cd27d34b0fa0dbb01..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularIntArray.java +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularIntArray<T> { - - private final int logSize; - private final T[] segment; - private final int mask; - private int currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularIntArray(final int logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.mask = this.getCapacity() - 1; // mask = 0..01..1 - } - - public int getCapacity() { - return this.segment.length; - } - - public T get(final int i) { - return this.segment[i & this.mask]; // risk of overflow - } - - public T getNext() { - int index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) & this.mask; - return this.segment[index]; - } - - public void put(final int i, final T o) { - this.segment[i & this.mask] = o; // risk of overflow - } - - public CircularIntArray<T> grow(final int b, final int t) { - final CircularIntArray<T> a = new CircularIntArray<T>(this.logSize + 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularIntArray<T> shrink(final int b, final int t) { - final CircularIntArray<T> a = new CircularIntArray<T>(this.logSize - 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java b/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java deleted file mode 100644 index 990cd38f53df23f6f9118849dce9630c71195686..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularModIntArray.java +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing; - -import java.util.Arrays; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - * - * @param <T> - */ -public final class CircularModIntArray<T> { - - private final int logSize; - private final T[] segment; - private final int size; - - private int currentIndex; - - /** - * - * @param logSize - * The initial size of this array in log2, i.e., the number of bits to use - */ - @SuppressWarnings("unchecked") - public CircularModIntArray(final int logSize) { - this.logSize = logSize; - this.segment = (T[]) new Object[1 << this.logSize]; - this.size = this.segment.length; - } - - public int getCapacity() { - return this.segment.length; - } - - public T get(final int i) { - return this.segment[i % this.size]; // risk of overflow - } - - public T getNext() { - int index = this.currentIndex; - this.currentIndex = (this.currentIndex + 1) % this.size; - return this.segment[index]; - } - - public void put(final int i, final T o) { - this.segment[i % this.size] = o; // risk of overflow - } - - public CircularModIntArray<T> grow(final int b, final int t) { - final CircularModIntArray<T> a = new CircularModIntArray<T>(this.logSize + 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - public CircularModIntArray<T> shrink(final int b, final int t) { - final CircularModIntArray<T> a = new CircularModIntArray<T>(this.logSize - 1); - for (int i = t; i < b; i++) { - a.put(i, this.get(i)); - } - return a; - } - - @Override - public String toString() { - return Arrays.toString(this.segment); - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java deleted file mode 100644 index 0aa4453cd2dc1be54f5bdb17839428bd372ebe6a..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/CircularWorkStealingDeque.java +++ /dev/null @@ -1,306 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing; - -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - -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 static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private final boolean casTop(final long oldVal, final long newVal) { - return this.top.compareAndSet(oldVal, newVal); - } - - /** - * - * @param o - * a non-<code>null</code> element - */ - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final int numElementsToPush = 1; - final long currentSize = b - t; - final long newSize = currentSize + numElementsToPush; - if (newSize > a.getCapacity()) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + numElementsToPush; - } - - /** - * - * @param elements - * a non-<code>null</code> list - */ - public void pushBottomMultiple(final List<T> elements) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final int numElementsToPush = elements.size(); - final long currentSize = b - t; - final long newSize = currentSize + numElementsToPush; - if (newSize > a.getCapacity()) { - a = a.grow(b, t); - this.activeArray = a; - } - - for (final T elem : elements) { - a.put(b, elem); - } - - this.bottom = b + numElementsToPush; - } - - /** - * Returns and removes the latest element from this deque. - * - * @return - * <ul> - * <li><code>null</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public T popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.empty(); - } - T o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.empty(); - } - this.bottom = t + 1; - return o; - } - - /** - * 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() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.emptyEx(); - } - T o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.emptyEx(); - } - this.bottom = t + 1; - return o; - } - - private void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>null</code> if the deque contains no elements, - * <li>(and also) <code>null</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public T steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.empty(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.empty(); - } else { - return this.abort(); - } - } - final T o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abort(); - } - return o; - } - - /** - * 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 - */ - public T stealEx() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.emptyEx(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.emptyEx(); - } else { - return this.abortEx(); - } - } - final T o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abortEx(); - } - return o; - } - - private T empty() { - return null; - } - - private T emptyEx() { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - - private T abort() { - return null; - } - - private T abortEx() { - throw OPERATION_ABORTED_EXCEPTION; - } - - private T regular(final T value) { - return value; - } - - /** - * 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 - * </ul> - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - public boolean isEmpty() { - final long t = this.top.get(); - final long b = this.bottom; - return t >= b; - } - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } - - @Override - public String toString() { - return this.activeArray.toString(); - } - -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java deleted file mode 100644 index 854839c52b124a043181a4cf3c6f598577c0d9a3..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java +++ /dev/null @@ -1,202 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing.alternative; - -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 static enum State { - REGULAR, EMPTY, ABORT - } - - public static class ReturnValue<T> { - private final State state; - private final T value; - - public ReturnValue(final State state, final T value) { - this.state = state; - this.value = value; - } - - public T getValue() { - return this.value; - } - - public State getState() { - return this.state; - } - } - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - return this.top.compareAndSet(oldVal, newVal); - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public ReturnValue<T> popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return new ReturnValue<T>(State.EMPTY, null); - } - ReturnValue<T> o = new ReturnValue<T>(State.REGULAR, a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = new ReturnValue<T>(State.EMPTY, null); - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><code>abort()</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public ReturnValue<T> steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return new ReturnValue<T>(State.EMPTY, null); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return new ReturnValue<T>(State.EMPTY, null); - } else { - return new ReturnValue<T>(State.ABORT, null); - } - } - final ReturnValue<T> o = new ReturnValue<T>(State.REGULAR, a.get(t)); - if (!this.casTop(t, t + 1)) { - return new ReturnValue<T>(State.ABORT, null); - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java deleted file mode 100644 index 746765a1cb646995aa143871b709b196c75431fe..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java +++ /dev/null @@ -1,226 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing.alternative; - -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 static enum State { - REGULAR, EMPTY, ABORT - } - - public static class ReturnValue<T> { - private State state; - private T value; - - public State getState() { - return this.state; - } - - public T getValue() { - return this.value; - } - - public ReturnValue<T> setState(final State state) { - this.state = state; - return this; - } - - public ReturnValue<T> setStateAndValue(final State state, final T value) { - this.state = state; - this.value = value; - return this; - } - } - - private final ThreadLocal<ReturnValue<T>> returnValue = new ThreadLocal<ReturnValue<T>>(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - public CircularWorkStealingDequeWithThreadLocalSentinel() { - this.returnValue.set(new ReturnValue<T>()); - } - - private boolean casTop(final long oldVal, final long newVal) { - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - return this.top.compareAndSet(oldVal, newVal); - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public ReturnValue<T> popBottom() { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return this.empty(); - } - ReturnValue<T> o = this.regular(a.get(b)); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = this.empty(); - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>empty()</code> if the deque contains no elements, - * <li><code>abort()</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public ReturnValue<T> steal() { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return this.empty(); - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return this.empty(); - } else { - return this.abort(); - } - } - final ReturnValue<T> o = this.regular(a.get(t)); - if (!this.casTop(t, t + 1)) { - return this.abort(); - } - return o; - } - - private ReturnValue<T> empty() { - return this.returnValue.get().setState(State.EMPTY); - } - - private ReturnValue<T> abort() { - return this.returnValue.get().setState(State.ABORT); - } - - private ReturnValue<T> regular(final T value) { - return this.returnValue.get().setStateAndValue(State.REGULAR, value); - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java deleted file mode 100644 index 5eae1d222713841b1098ac9940f0ab1a0129b4f8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java +++ /dev/null @@ -1,188 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; -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 ExceptionalCircularWorkStealingDeque<T> { - - public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - return this.top.compareAndSet(oldVal, newVal); - } - - public void pushBottom(final T o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - */ - public T popBottom() throws DequeIsEmptyException { - long b = this.bottom; - final CircularArray<T> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - throw DEQUE_IS_EMPTY_EXCEPTION; - } - final T o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - final boolean success = this.casTop(t, t + 1); - this.bottom = t + 1; - if (!success) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<T> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<T> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - * @throws OperationAbortedException - */ - public T steal() throws DequeIsEmptyException, OperationAbortedException { - final long t = this.top.get(); - final CircularArray<T> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } else { - throw OPERATION_ABORTED_EXCEPTION; - } - } - final T o = a.get(t); - if (!this.casTop(t, t + 1)) { - throw OPERATION_ABORTED_EXCEPTION; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public T readBottom() { - final long b = this.bottom; - final CircularArray<T> a = this.activeArray; - final T o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java deleted file mode 100644 index 1ece4ff8d7615027b689b95c142daac22fe5c8a3..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java +++ /dev/null @@ -1,182 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing.alternative; - -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 static final Object EMPTY = new Object(); - public static final Object ABORT = new Object(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - return this.top.compareAndSet(oldVal, newVal); - } - - public void pushBottom(final Object o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - */ - public Object popBottom() { - long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - b = b - 1; - this.bottom = b; // reserve (avoid stealing) the current bottom element - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - return EMPTY; - } - Object o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - if (!this.casTop(t, t + 1)) { - o = EMPTY; - } - this.bottom = t + 1; - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<Object> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<Object> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - */ - public Object steal() { - final long t = this.top.get(); - final CircularArray<Object> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - return EMPTY; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - return EMPTY; - } else { - return ABORT; - } - } - final Object o = a.get(t); - if (!this.casTop(t, t + 1)) { - return ABORT; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public Object readBottom() { - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final Object o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java deleted file mode 100644 index 584fcc5e87f3b94c6ec089e2977d2171a1aeec7d..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java +++ /dev/null @@ -1,190 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.util.concurrent.workstealing.alternative; - -import java.util.concurrent.atomic.AtomicLong; - -import teetime.util.concurrent.workstealing.CircularArray; -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; -import teetime.util.concurrent.workstealing.exception.DequePopException; -import teetime.util.concurrent.workstealing.exception.OperationAbortedException; - -/** - * - * @author Christian Wulf - * - * @see "Dynamic Circular WorkStealing Deque" - * - * @since 1.10 - */ -public class UntypedExceptionalCircularWorkStealingDeque { - - public static final DequeIsEmptyException DEQUE_IS_EMPTY_EXCEPTION = new DequeIsEmptyException(); - - public static final OperationAbortedException OPERATION_ABORTED_EXCEPTION = new OperationAbortedException(); - - private static final long LOG_INITIAL_SIZE = 10; - - private volatile long bottom = 0; - // private volatile long top = 0; - private final AtomicLong top = new AtomicLong(); - private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); - - private boolean casTop(final long oldVal, final long newVal) { - // boolean preCond; - // synchronized (this) { - // preCond = (this.top == oldVal); - // if (preCond) { - // this.top = newVal; - // } - // } - // return preCond; - return this.top.compareAndSet(oldVal, newVal); - } - - public void pushBottom(final Object o) { - final long b = this.bottom; - final long t = this.top.get(); - CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size > (a.getCapacity() - 1)) { - a = a.grow(b, t); - this.activeArray = a; - } - a.put(b, o); - this.bottom = b + 1; - } - - /** - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><i>the latest element</i> otherwise - * </ul> - * @throws DequeIsEmptyException - */ - public Object popBottom() throws DequePopException { - long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - b = b - 1; - this.bottom = b; - final long t = this.top.get(); - final long size = b - t; - if (size < 0) { - this.bottom = t; - throw DEQUE_IS_EMPTY_EXCEPTION; - } - final Object o = a.get(b); - if (size > 0) { - this.perhapsShrink(b, t); - return o; - } - final boolean success = this.casTop(t, t + 1); - this.bottom = t + 1; - if (!success) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - return o; - } - - void perhapsShrink(final long b, final long t) { - long temp = t; - final CircularArray<Object> a = this.activeArray; - if ((b - temp) < (a.getCapacity() / 4)) { - final CircularArray<Object> aa = a.shrink(b, temp); - this.activeArray = aa; - final long ss = aa.getCapacity(); - this.bottom = b + ss; - temp = this.top.get(); - if (!this.casTop(temp, temp + ss)) { - this.bottom = b; - // a.free(); - } - } - } - - /** - * Tries to steal (return & remove) the oldest element from this deque. - * - * @return - * <ul> - * <li><code>EMPTY</code> if the deque contains no elements, - * <li><code>ABORT</code> if the deque is currently being stolen by another thread, - * <li><i>the oldest element</i> otherwise - * </ul> - * @throws DequePopException - */ - public Object steal() throws DequePopException { - final long t = this.top.get(); - final CircularArray<Object> oldArr = this.activeArray; - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final long size = b - t; - if (size <= 0) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } - if ((size % a.getCapacity()) == 0) { - if ((oldArr == a) && (t == this.top.get())) { - throw DEQUE_IS_EMPTY_EXCEPTION; - } else { - throw OPERATION_ABORTED_EXCEPTION; - } - } - final Object o = a.get(t); - if (!this.casTop(t, t + 1)) { - throw OPERATION_ABORTED_EXCEPTION; - } - return o; - } - - /** - * For debugging purposes - * - * @return but does not remove the bottom element from this deque - */ - public Object readBottom() { - final long b = this.bottom; - final CircularArray<Object> a = this.activeArray; - final Object o = a.get(b); - return o; - } - - // bottom: 4093 - // bottom: 66429 - // bottom: 29993 - // bottom: 29992 - // - // - // bottom: 4093 - // bottom: 66429 - // bottom: 30008 - // bottom: 30007 - - /** - * For debugging purposes - * - * @return the number of elements this deque contains - */ - public long size(final Object sourceStage) { - final long t = this.top.get(); - final long b = this.bottom; - final long size = b - t; - System.out.println("sourceStage=" + sourceStage + ", " + "bottom: " + this.bottom); - return size; - } -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java deleted file mode 100644 index 9aa4ecbcb066bb582a04ef9642e063ea108d523d..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/DequeIsEmptyException.java +++ /dev/null @@ -1,5 +0,0 @@ -package teetime.util.concurrent.workstealing.exception; - -public 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/DequePopException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java deleted file mode 100644 index 405ebe97b12378c69fea05024f6892272fd59bc8..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/DequePopException.java +++ /dev/null @@ -1,8 +0,0 @@ -package teetime.util.concurrent.workstealing.exception; - -import teetime.util.StacklessException; - -public class DequePopException extends StacklessException { - private static final long serialVersionUID = 496512683536868149L; - -} diff --git a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java b/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java deleted file mode 100644 index c2fa61e340f34d71557c1f08aadc1e55a402e46c..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/concurrent/workstealing/exception/OperationAbortedException.java +++ /dev/null @@ -1,5 +0,0 @@ -package teetime.util.concurrent.workstealing.exception; - -public 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 deleted file mode 100644 index b21216ad92fd364d90fc50b7f086106301af5166..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/ArrayPool.java +++ /dev/null @@ -1,24 +0,0 @@ -package teetime.util.list; - -import java.util.HashMap; -import java.util.Map; - -public class ArrayPool<T> { - - // BETTER use a map with int as key due to performance - private final Map<Integer, T[]> cache = new HashMap<Integer, T[]>(); - - @SuppressWarnings("unchecked") - public T[] acquire(final int capacity) { - T[] array = this.cache.get(capacity); - if (array == null) { - array = (T[]) new Object[capacity]; - } - return array; - } - - public void release(final T[] array) { - this.cache.put(array.length, array); - } - -} diff --git a/src/main/java/teetime/util/list/CircularList.java b/src/main/java/teetime/util/list/CircularList.java deleted file mode 100644 index b283ba4a518b0866b32c39512c2350663e2d801f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/CircularList.java +++ /dev/null @@ -1,33 +0,0 @@ -package teetime.util.list; - -public final class CircularList<T> { - - private static final class Node<T> { - T value; - Node<T> next; - } - - private Node<T> headNode; - private Node<T> lastNode; - - private Node<T> currentNode; - - public void add(final T value) { - Node<T> newNode = new Node<T>(); - newNode.value = value; - - if (this.headNode == null) { // newNode is the first node - this.headNode = this.lastNode = newNode; - this.currentNode = newNode; - } - - this.lastNode.next = newNode; - newNode.next = this.headNode; - } - - public T getNext() { - T value = this.currentNode.value; - this.currentNode = this.currentNode.next; - return value; - } -} diff --git a/src/main/java/teetime/util/list/CommittableQueue.java b/src/main/java/teetime/util/list/CommittableQueue.java deleted file mode 100644 index 686ef8f8328d700c79116b43eb48f884314c4173..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/CommittableQueue.java +++ /dev/null @@ -1,29 +0,0 @@ -package teetime.util.list; - -public interface CommittableQueue<T> { - - // basic methods - T get(int index); - - void addToTailUncommitted(T element); - - T removeFromHeadUncommitted(); - - void commit(); - - void rollback(); - - int size(); - - boolean isEmpty(); - - void clear(); - - // convenient methods - // T removeFromHeadUncommitted(int count); - - T getTail(); - - T removeFromHead(); - -} diff --git a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java b/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java deleted file mode 100644 index 6a6b2afe46b590f4cb5f94b32ec5b9988567b7fe..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java +++ /dev/null @@ -1,117 +0,0 @@ -package teetime.util.list; - -public class CommittableResizableArrayQueue<T> implements CommittableQueue<T> { - - private final int MIN_CAPACITY; - - private final ArrayPool<T> arrayPool; - private T[] elements; - - private int lastFreeIndex, lastFreeIndexUncommitted; - - @SuppressWarnings("unchecked") - public CommittableResizableArrayQueue(final Object emptyObject, final int initialCapacity) { - super(); - this.arrayPool = new ArrayPool<T>(); - this.MIN_CAPACITY = initialCapacity + 1; - this.elements = this.arrayPool.acquire(initialCapacity + 1); - - this.elements[0] = (T) emptyObject; // optimization: avoids the use of an index out-of-bounds check - this.clear(); - } - - @Override - public final T get(final int index) { - T element = this.elements[index + 1]; - return element; - } - - @Override - public void addToTailUncommitted(final T element) { - if (this.lastFreeIndexUncommitted == this.capacity()) { - this.grow(); - } - this.put(this.lastFreeIndexUncommitted++, element); - } - - @Override - public T removeFromHeadUncommitted() { - // if (this.capacity() > this.MIN_CAPACITY && this.lastFreeIndexUncommitted < this.capacity() / 2) { // TODO uncomment - // this.shrink(); - // } - T element = this.get(--this.lastFreeIndexUncommitted); - return element; - } - - @Override - public void commit() { - // TODO set elements to null to help the gc - this.lastFreeIndex = this.lastFreeIndexUncommitted; - } - - @Override - public void rollback() { - this.lastFreeIndexUncommitted = this.lastFreeIndex; - } - - @Override - public int size() { - return this.lastFreeIndex; - } - - @Override - public boolean isEmpty() { - return this.size() == 0; - } - - @Override - public void clear() { - this.lastFreeIndex = this.lastFreeIndexUncommitted = 0; - } - - @Override - public T getTail() { - T element = this.get(this.lastFreeIndex - 1); - return element; - } - - private void grow() { - T[] newElements = this.arrayPool.acquire(this.elements.length * 2); - // System.out.println("grow: " + this.lastFreeIndexUncommitted); - this.replaceCurrentArrayBy(newElements); - } - - private void shrink() { - T[] newElements = this.arrayPool.acquire(this.elements.length / 2); - // System.out.println("shrink: " + this.lastFreeIndexUncommitted); - this.replaceCurrentArrayBy(newElements); - } - - private final void replaceCurrentArrayBy(final T[] newElements) { - this.copyArray(this.elements, newElements); - this.arrayPool.release(this.elements); - this.elements = newElements; - } - - private final void copyArray(final T[] elements, final T[] newElements) { - // for (int i = 0; i < this.lastFreeIndexUncommitted; i++) { - // newElements[i] = elements[i]; - // } - System.arraycopy(elements, 0, newElements, 0, this.lastFreeIndexUncommitted + 1); - } - - private final void put(final int index, final T element) { - this.elements[index + 1] = element; - } - - private final int capacity() { - return this.elements.length - 1; - } - - @Override - public T removeFromHead() { - T element = this.removeFromHeadUncommitted(); - this.commit(); - return element; - } -} diff --git a/src/main/java/teetime/util/list/ListContainer.java b/src/main/java/teetime/util/list/ListContainer.java deleted file mode 100644 index f5ed946a9631d564a7ddfb2be3ce3d72e57492ee..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/ListContainer.java +++ /dev/null @@ -1,8 +0,0 @@ -package teetime.util.list; - -public 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 deleted file mode 100644 index d2a27ecc7b3e3adf15ceca144adc4f09a19fdf34..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/ListContainerPool.java +++ /dev/null @@ -1,37 +0,0 @@ -package teetime.util.list; - -import java.util.ArrayList; -import java.util.List; - -public class ListContainerPool<T> implements ObjectPool<ListContainer<T>> { - - private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>(); - - public ListContainerPool(int initialPoolSize) { - while (initialPoolSize-- > 0) { - this.pool.add(this.createNew()); - } - } - - @Override - public ListContainer<T> acquire() { - ListContainer<T> obj; - if (this.pool.size() > 0) { - obj = this.pool.remove(this.pool.size() - 1); - } else { - obj = this.createNew(); - this.pool.add(obj); - } - return obj; - } - - private ListContainer<T> createNew() { - return new ListContainer<T>(); - } - - @Override - public void release(final ListContainer<T> obj) { - this.pool.add(obj); - } - -} diff --git a/src/main/java/teetime/util/list/ObjectPool.java b/src/main/java/teetime/util/list/ObjectPool.java deleted file mode 100644 index e1820468bd6a850da0fd6ae797cd99043a7d106e..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/ObjectPool.java +++ /dev/null @@ -1,9 +0,0 @@ -package teetime.util.list; - -public interface ObjectPool<T> { - - T acquire(); - - void release(T element); - -} diff --git a/src/main/java/teetime/util/list/ObjectPooledLinkedList.java b/src/main/java/teetime/util/list/ObjectPooledLinkedList.java deleted file mode 100644 index b0744508ad98469c88ee5d09428c41622303f83f..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/list/ObjectPooledLinkedList.java +++ /dev/null @@ -1,50 +0,0 @@ -package teetime.util.list; - -public class ObjectPooledLinkedList<T> { - - private final ObjectPool<ListContainer<T>> objectPool = new ListContainerPool<T>(10); - - private static final ListContainer<?> BOTTOM = new ListContainer<Object>(); - - private ListContainer<T> top; - - private int size; - - @SuppressWarnings("unchecked") - public ObjectPooledLinkedList() { - this.top = (ListContainer<T>) BOTTOM; - } - - /** - * - * @return <code>null</code> if the list is empty. - */ - public T pop() { - if (this.top == BOTTOM) { - return null; - } - T value = this.top.value; - this.top = this.top.previous; - this.size--; - return value; - } - - public void push(final T element) { - ListContainer<T> listContainer = this.objectPool.acquire(); - listContainer.previous = this.top; - listContainer.value = element; - this.top = listContainer; - this.size++; - } - - public T read() { - if (this.top == BOTTOM) { - return null; - } - return this.top.value; - } - - public int size() { - return this.size; - } -} diff --git a/src/main/java/util/BucketTimingsReader.java b/src/main/java/util/BucketTimingsReader.java deleted file mode 100644 index 911c997bc391d6337a44fade8c04b75c3134a89f..0000000000000000000000000000000000000000 --- a/src/main/java/util/BucketTimingsReader.java +++ /dev/null @@ -1,59 +0,0 @@ -package util; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import util.test.StatisticsUtil; - -import com.google.common.base.Charsets; -import com.google.common.io.CharSource; -import com.google.common.io.Files; - -public class BucketTimingsReader { - - private final static Logger LOGGER = LoggerFactory.getLogger(BucketTimingsReader.class); - - public static void main(final String[] args) throws IOException { - String fileName = args[0]; - - Long[] currentTimings = new Long[10000]; - int processedLines = 0; - List<Long> buckets = new LinkedList<Long>(); - - LOGGER.trace("Reading " + fileName); - CharSource charSource = Files.asCharSource(new File(fileName), Charsets.UTF_8); - BufferedReader bufferedStream = charSource.openBufferedStream(); - String line; - while (null != (line = bufferedStream.readLine())) { - String[] strings = line.split(";"); - Long timing = new Long(strings[1]); - currentTimings[processedLines] = timing; - processedLines++; - if (currentTimings.length == processedLines) { - // Long aggregatedTimings = StatisticsUtil.calculateQuintiles(Arrays.asList(currentTimings)).get(0.5); - Long aggregatedTimings = StatisticsUtil.calculateAverage(Arrays.asList(currentTimings)); - buckets.add(aggregatedTimings); - processedLines = 0; - } - } - - LOGGER.trace("#buckets: " + buckets.size()); - - List<Long> durationsInNs = buckets.subList(buckets.size() / 2, buckets.size()); - - LOGGER.trace("Calculating quantiles..."); - Map<Double, Long> quintiles = StatisticsUtil.calculateQuintiles(durationsInNs); - LOGGER.info(StatisticsUtil.getQuantilesString(quintiles)); - - long confidenceWidth = StatisticsUtil.calculateConfidenceWidth(durationsInNs); - LOGGER.info("Confidence width: " + confidenceWidth); - } -} diff --git a/src/main/java/util/MooBenchStarter.java b/src/main/java/util/MooBenchStarter.java deleted file mode 100644 index 6a5a42eb04fccad322480032bcc121bc768bbd7f..0000000000000000000000000000000000000000 --- a/src/main/java/util/MooBenchStarter.java +++ /dev/null @@ -1,31 +0,0 @@ -package util; - -import java.io.File; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -public class MooBenchStarter { - - private final File execDir; - - public MooBenchStarter() { - this.execDir = new File("scripts/MooBench-cmd"); - System.out.println("execDir: " + this.execDir.getAbsolutePath()); - } - - public void start(final int runs, final long calls) throws IOException { - List<String> command = new LinkedList<String>(); - command.add("cmd"); - command.add("/c"); - command.add("start"); - command.add("/D"); - command.add(this.execDir.getAbsolutePath()); - command.add("Load Driver"); - command.add("startMooBench.cmd"); - command.add(String.valueOf(runs)); - command.add(String.valueOf(calls)); - - new ProcessBuilder(command).start(); - } -} diff --git a/src/main/java/util/test/MeasurementRepository.java b/src/main/java/util/test/MeasurementRepository.java deleted file mode 100644 index 99843106b521d6bdc9740a356e528353aa956b5b..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/MeasurementRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package util.test; - -import java.util.HashMap; -import java.util.Map; - -public class MeasurementRepository { - - public final Map<String, PerformanceResult> performanceResults = new HashMap<String, PerformanceResult>(); - - public static final String buildTestMethodIdentifier(final Class<?> testClass, final String methodName) { - return testClass.getName() + "(" + methodName + ")"; - } -} diff --git a/src/main/java/util/test/PerformanceCheckProfileRepository.java b/src/main/java/util/test/PerformanceCheckProfileRepository.java deleted file mode 100644 index 74b8ad37ec6b6e709fbf4c8fe972b60a565988f6..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/PerformanceCheckProfileRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -package util.test; - -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PerformanceCheckProfileRepository { - - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceCheckProfileRepository.class); - - public static final PerformanceCheckProfileRepository INSTANCE = new PerformanceCheckProfileRepository(); - - private final Map<Class<?>, ProfiledPerformanceAssertion> performanceCheckProfiles = new HashMap<Class<?>, ProfiledPerformanceAssertion>(); - - private String currentProfile; - - public PerformanceCheckProfileRepository() { - this.currentProfile = System.getProperty("TestProfile", "ChwWork"); - LOGGER.info("Using test profile '" + this.currentProfile + "'"); - } - - public void setCurrentProfile(final String currentProfile) { - this.currentProfile = currentProfile; - } - - public String getCurrentProfile() { - return this.currentProfile; - } - - public void register(final Class<?> testClass, final ProfiledPerformanceAssertion profile) { - if (profile.getCorrespondingPerformanceProfile().equals(this.currentProfile)) { - this.performanceCheckProfiles.put(testClass, profile); - } - } - - public ProfiledPerformanceAssertion get(final Class<?> clazz) { - return this.performanceCheckProfiles.get(clazz); - } -} diff --git a/src/main/java/util/test/PerformanceResult.java b/src/main/java/util/test/PerformanceResult.java deleted file mode 100644 index 22cf87e3069066fc0b224de3062fa69bc4dda835..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/PerformanceResult.java +++ /dev/null @@ -1,36 +0,0 @@ -package util.test; - -import java.util.Map; - -public class PerformanceResult { - - public long overallDurationInNs; - public long sumInNs; - public Map<Double, Long> quantiles; - public long avgDurInNs; - public long confidenceWidthInNs; - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("overallDurationInNs: "); - stringBuilder.append(this.overallDurationInNs); - stringBuilder.append("\n"); - - stringBuilder.append("sumInNs: "); - stringBuilder.append(this.sumInNs); - stringBuilder.append("\n"); - - stringBuilder.append("avgDurInNs: "); - stringBuilder.append(this.avgDurInNs); - stringBuilder.append("\n"); - - stringBuilder.append("confidenceWidthInNs: "); - stringBuilder.append(this.confidenceWidthInNs); - stringBuilder.append("\n"); - - stringBuilder.append(StatisticsUtil.getQuantilesString(this.quantiles)); - - return stringBuilder.toString(); - } -} diff --git a/src/main/java/util/test/PerformanceTest.java b/src/main/java/util/test/PerformanceTest.java deleted file mode 100644 index 66c435b8c4e76b53ebbfd6a89750380decb05724..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/PerformanceTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package util.test; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; - -import teetime.util.StopWatch; -import teetime.util.TimestampObject; - -public abstract class PerformanceTest { - - protected static final PerformanceCheckProfileRepository PERFORMANCE_CHECK_PROFILE_REPOSITORY = PerformanceCheckProfileRepository.INSTANCE; - protected static final int NUM_OBJECTS_TO_CREATE = 1000000; - protected static final int NUM_NOOP_FILTERS = 800; - - public static final MeasurementRepository measurementRepository = new MeasurementRepository(); - - protected Description description; - - protected StopWatch stopWatch; - protected List<TimestampObject> timestampObjects; - - static { - System.setProperty("logback.configurationFile", "src/test/resources/logback-test.groovy"); - } - - @Rule - public final TestRule watcher = new TestWatcher() { - @Override - protected void starting(final Description description) { - PerformanceTest.this.description = description; - // System.out.println("getDisplayName(): " + description.getDisplayName()); - } - }; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - this.timestampObjects = new ArrayList<TimestampObject>(NUM_OBJECTS_TO_CREATE); - } - - @After - public void after() { - String testMethodIdentifier = MeasurementRepository.buildTestMethodIdentifier(description.getTestClass(), description.getMethodName()); - PerformanceResult performanceResult = StatisticsUtil.computeStatistics(this.stopWatch.getDurationInNs(), this.timestampObjects); - measurementRepository.performanceResults.put(testMethodIdentifier, performanceResult); - - addToRepository(performanceResult); - - System.out.println("Duration: " + TimeUnit.NANOSECONDS.toMillis(performanceResult.overallDurationInNs) + " ms"); - System.out.println("avg duration: " + TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs) + " µs"); - System.out.println(StatisticsUtil.getQuantilesString(performanceResult.quantiles)); - System.out.println("confidenceWidth: " + performanceResult.confidenceWidthInNs + " ns"); - System.out.println("[" + TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs - performanceResult.confidenceWidthInNs) + " µs, " - + TimeUnit.NANOSECONDS.toMicros(performanceResult.avgDurInNs + performanceResult.confidenceWidthInNs) + " µs]"); - } - - @Deprecated - private void addToRepository(final PerformanceResult performanceResult) { - measurementRepository.performanceResults.put(this.description.getDisplayName(), performanceResult); - } - -} diff --git a/src/main/java/util/test/ProfiledPerformanceAssertion.java b/src/main/java/util/test/ProfiledPerformanceAssertion.java deleted file mode 100644 index 9e9bb48858c7404f26e5f5c1982301b12ee966a4..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/ProfiledPerformanceAssertion.java +++ /dev/null @@ -1,8 +0,0 @@ -package util.test; - -public abstract class ProfiledPerformanceAssertion { - - public abstract String getCorrespondingPerformanceProfile(); - - public abstract void check(); -} diff --git a/src/main/java/util/test/StatisticsUtil.java b/src/main/java/util/test/StatisticsUtil.java deleted file mode 100644 index a0f091bc5a66c3788887a94143b1733bd90fa920..0000000000000000000000000000000000000000 --- a/src/main/java/util/test/StatisticsUtil.java +++ /dev/null @@ -1,126 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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 util.test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import teetime.util.MathUtil; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class StatisticsUtil { - - /** - * @since 1.10 - */ - private StatisticsUtil() { - // utility class - } - - public static PerformanceResult computeStatistics(final long overallDurationInNs, final List<TimestampObject> timestampObjects) { - PerformanceResult performanceResult = new PerformanceResult(); - - performanceResult.overallDurationInNs = overallDurationInNs; - - final List<Long> sortedDurationsInNs = new ArrayList<Long>(timestampObjects.size() / 2); - long sumInNs = 0; - for (int i = timestampObjects.size() / 2; i < timestampObjects.size(); i++) { - final TimestampObject timestampObject = timestampObjects.get(i); - final long durationInNs = timestampObject.getStopTimestamp() - timestampObject.getStartTimestamp(); - // sortedDurationsInNs.set(i - (timestampObjects.size() / 2), durationInNs); - sortedDurationsInNs.add(durationInNs); - sumInNs += durationInNs; - } - - performanceResult.sumInNs = sumInNs; - - final Map<Double, Long> quintileValues = StatisticsUtil.calculateQuintiles(sortedDurationsInNs); - performanceResult.quantiles = quintileValues; - - final long avgDurInNs = sumInNs / (timestampObjects.size() / 2); - performanceResult.avgDurInNs = avgDurInNs; - - final long confidenceWidthInNs = StatisticsUtil.calculateConfidenceWidth(sortedDurationsInNs, avgDurInNs); - performanceResult.confidenceWidthInNs = confidenceWidthInNs; - - return performanceResult; - } - - public static String getQuantilesString(final Map<Double, Long> quantilesValues) { - StringBuilder builder = new StringBuilder(); - for (final Entry<Double, Long> entry : quantilesValues.entrySet()) { - String quantile = (entry.getKey() * 100) + " % : " + TimeUnit.NANOSECONDS.toNanos(entry.getValue()) + " ns"; - builder.append(quantile); - builder.append("\n"); - } - return builder.toString(); - } - - public static long calculateConfidenceWidth(final List<Long> durations, final long avgDurInNs) { - final double z = 1.96; // for alpha = 0.05 - final double variance = MathUtil.getVariance(durations, avgDurInNs); - final long confidenceWidthInNs = (long) MathUtil.getConfidenceWidth(z, variance, durations.size()); - return confidenceWidthInNs; - } - - public static long calculateConfidenceWidth(final List<Long> durations) { - return StatisticsUtil.calculateConfidenceWidth(durations, StatisticsUtil.calculateAverage(durations)); - } - - public static long calculateAverage(final List<Long> durations) { - long sumNs = 0; - for (final Long value : durations) { - sumNs += value; - } - - return sumNs / durations.size(); - } - - public static Map<Double, Long> calculateQuintiles(final List<Long> durationsInNs) { - Collections.sort(durationsInNs); - - final Map<Double, Long> quintileValues = new LinkedHashMap<Double, Long>(); - final double[] quintiles = { 0.00, 0.25, 0.50, 0.75, 1.00 }; - for (final double quintile : quintiles) { - final int index = (int) ((durationsInNs.size() - 1) * quintile); - quintileValues.put(quintile, durationsInNs.get(index)); - } - return quintileValues; - } - - public static void removeLeadingZeroThroughputs(final List<Long> throughputs) { - Iterator<Long> iterator = throughputs.iterator(); - while (iterator.hasNext()) { - if (iterator.next() == 0) { - iterator.remove(); - } else { - break; - } - } - } - -} diff --git a/src/performancetest/java/teetime/examples/ChwHomeComparisonMethodcallWithPorts.java b/src/performancetest/java/teetime/examples/ChwHomeComparisonMethodcallWithPorts.java deleted file mode 100644 index 52105427b358d1f6e97fc709eb0f5553283f3ac8..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/ChwHomeComparisonMethodcallWithPorts.java +++ /dev/null @@ -1,97 +0,0 @@ -package teetime.examples; - -import static org.junit.Assert.assertEquals; - -import java.util.Map; -import java.util.Map.Entry; - -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwHomeComparisonMethodcallWithPorts extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - Map<String, PerformanceResult> performanceResults = PerformanceTest.measurementRepository.performanceResults; - for (Entry<String, PerformanceResult> entry : performanceResults.entrySet()) { - System.out.println("---> " + entry.getKey() + "\n" + entry.getValue()); - } - - PerformanceResult test1 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - PerformanceResult test9 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment09.MethodCallThoughputTimestampAnalysis9Test)"); - PerformanceResult test15 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment15.MethodCallThoughputTimestampAnalysis15Test)"); - PerformanceResult test16a = performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16b = performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16c = performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test17 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment17.MethodCallThoughputTimestampAnalysis17Test)"); - PerformanceResult test19a = performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19b = performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19c = performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - - double value9 = (double) test9.quantiles.get(0.5) / test1.quantiles.get(0.5); - double value15 = (double) test15.quantiles.get(0.5) / test1.quantiles.get(0.5); - double value17 = (double) test17.quantiles.get(0.5) / test1.quantiles.get(0.5); - - System.out.println("value9: " + value9); - System.out.println("value15: " + value15); - System.out.println("value17: " + value17); - - // until 25.06.2014 (incl.) - // assertEquals(22, (double) test9.quantiles.get(0.5) / test1.quantiles.get(0.5), 2.1); - // assertEquals(44, (double) test15.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - // assertEquals(39, (double) test17.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - - // since 26.06.2014 (incl.) - // assertEquals(36, value9, 2.1); // +14 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +14 - - // // since 04.07.2014 (incl.) - // assertEquals(42, value9, 2.1); // +6 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +0 - - // since 11.08.2014 (incl.) - // assertEquals(42, value9, 2.1); // +6 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +0 - - // since 31.08.2014 (incl.) - assertEquals(44, value9, 2.1); // ?? - assertEquals(68, value15, 4.1); // ?? - assertEquals(75, value17, 4.1); // ?? - - // below results vary too much, possibly due to the OS' scheduler - // assertEquals(RESULT_TESTS_16, (double) test16a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // - // assertEquals(RESULT_TESTS_19, (double) test19a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - - // check speedup - assertEquals(2, (double) test16a.overallDurationInNs / test16b.overallDurationInNs, 0.3); - assertEquals(2.5, (double) test16a.overallDurationInNs / test16c.overallDurationInNs, 0.2); - - assertEquals(2, (double) test19a.overallDurationInNs / test19b.overallDurationInNs, 0.3); - assertEquals(2.5, (double) test19a.overallDurationInNs / test19c.overallDurationInNs, 0.3); - } - -} diff --git a/src/performancetest/java/teetime/examples/ChwWorkComparisonMethodcallWithPorts.java b/src/performancetest/java/teetime/examples/ChwWorkComparisonMethodcallWithPorts.java deleted file mode 100644 index df569b2d7a480d6766dd527f9bfe06960eac8bfb..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/ChwWorkComparisonMethodcallWithPorts.java +++ /dev/null @@ -1,88 +0,0 @@ -package teetime.examples; - -import static org.junit.Assert.assertEquals; - -import java.util.Map; -import java.util.Map.Entry; - -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwWorkComparisonMethodcallWithPorts extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } - - @Override - public void check() { - Map<String, PerformanceResult> performanceResults = PerformanceTest.measurementRepository.performanceResults; - for (Entry<String, PerformanceResult> entry : performanceResults.entrySet()) { - System.out.println("---> " + entry.getKey() + "\n" + entry.getValue()); - } - - PerformanceResult test1 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - PerformanceResult test9 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment09.MethodCallThoughputTimestampAnalysis9Test)"); - PerformanceResult test15 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment15.MethodCallThoughputTimestampAnalysis15Test)"); - PerformanceResult test17 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment17.MethodCallThoughputTimestampAnalysis17Test)"); - PerformanceResult test19a = performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19b = performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19c = performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - - double value9 = (double) test9.quantiles.get(0.5) / test1.quantiles.get(0.5); - double value15 = (double) test15.quantiles.get(0.5) / test1.quantiles.get(0.5); - double value17 = (double) test17.quantiles.get(0.5) / test1.quantiles.get(0.5); - - System.out.println("value9: " + value9); - System.out.println("value15: " + value15); - System.out.println("value17: " + value17); - - // until 25.06.2014 (incl.) - // assertEquals(22, (double) test9.quantiles.get(0.5) / test1.quantiles.get(0.5), 2.1); - // assertEquals(44, (double) test15.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - // assertEquals(39, (double) test17.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - - // since 26.06.2014 (incl.) - // assertEquals(36, value9, 2.1); // +14 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +14 - - // since 04.07.2014 (incl.) - // assertEquals(42, value9, 2.1); // +6 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +0 - - // since 27.08.2014 (incl.) - // assertEquals(77, value9, 2.1); // +35 - // assertEquals(44, value15, 4.1); // +0 - // assertEquals(53, value17, 4.1); // +0 - - // since 14.10.2014 (incl.) - assertEquals(67, value9, 3.1); // -10 - assertEquals(36, value15, 4.1); // -8 - assertEquals(46, value17, 4.1); // -7 - - // below results vary too much, possibly due to the OS' scheduler - // assertEquals(RESULT_TESTS_16, (double) test16a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // - // assertEquals(RESULT_TESTS_19, (double) test19a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - - // check speedup - assertEquals(2, (double) test19a.overallDurationInNs / test19b.overallDurationInNs, 0.3); - assertEquals(2.5, (double) test19a.overallDurationInNs / test19c.overallDurationInNs, 0.3); - } - -} diff --git a/src/performancetest/java/teetime/examples/ComparisonMethodcallWithPorts.java b/src/performancetest/java/teetime/examples/ComparisonMethodcallWithPorts.java deleted file mode 100644 index 26a913942e5f85a09fbe418273b2d175a794876e..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/ComparisonMethodcallWithPorts.java +++ /dev/null @@ -1,49 +0,0 @@ -package teetime.examples; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test; -import teetime.examples.experiment09.MethodCallThoughputTimestampAnalysis9Test; -import teetime.examples.experiment10.MethodCallThoughputTimestampAnalysis10Test; -import teetime.examples.experiment11.MethodCallThoughputTimestampAnalysis11Test; -import teetime.examples.experiment14.MethodCallThoughputTimestampAnalysis14Test; -import teetime.examples.experiment15.MethodCallThoughputTimestampAnalysis15Test; -import teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test; -import teetime.examples.experiment17.MethodCallThoughputTimestampAnalysis17Test; -import teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test; -import util.test.PerformanceCheckProfileRepository; -import util.test.ProfiledPerformanceAssertion; - -@RunWith(Suite.class) -@SuiteClasses({ - MethodCallThoughputTimestampAnalysis1Test.class, - MethodCallThoughputTimestampAnalysis9Test.class, - MethodCallThoughputTimestampAnalysis10Test.class, - MethodCallThoughputTimestampAnalysis11Test.class, - MethodCallThoughputTimestampAnalysis14Test.class, - MethodCallThoughputTimestampAnalysis15Test.class, - MethodCallThoughputTimestampAnalysis16Test.class, - MethodCallThoughputTimestampAnalysis17Test.class, - MethodCallThoughputTimestampAnalysis19Test.class, -}) -public class ComparisonMethodcallWithPorts { - - @BeforeClass - public static void beforeClass() { - System.setProperty("logback.configurationFile", "src/test/resources/logback-test.groovy"); - PerformanceCheckProfileRepository.INSTANCE.register(ComparisonMethodcallWithPorts.class, new ChwWorkComparisonMethodcallWithPorts()); - PerformanceCheckProfileRepository.INSTANCE.register(ComparisonMethodcallWithPorts.class, new ChwHomeComparisonMethodcallWithPorts()); - PerformanceCheckProfileRepository.INSTANCE.register(ComparisonMethodcallWithPorts.class, new NieWorkComparisonMethodcallWithPorts()); - }; - - @AfterClass - public static void compareResults() { - ProfiledPerformanceAssertion pcp = PerformanceCheckProfileRepository.INSTANCE.get(ComparisonMethodcallWithPorts.class); - pcp.check(); - } - -} diff --git a/src/performancetest/java/teetime/examples/NieWorkComparisonMethodcallWithPorts.java b/src/performancetest/java/teetime/examples/NieWorkComparisonMethodcallWithPorts.java deleted file mode 100644 index ea8e30a49b7c2e27c1791582d983e7626678060f..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/NieWorkComparisonMethodcallWithPorts.java +++ /dev/null @@ -1,78 +0,0 @@ -package teetime.examples; - -import static org.junit.Assert.assertEquals; - -import java.util.Map; -import java.util.Map.Entry; - -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class NieWorkComparisonMethodcallWithPorts extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "NieWork"; - } - - @Override - public void check() { - Map<String, PerformanceResult> performanceResults = PerformanceTest.measurementRepository.performanceResults; - for (Entry<String, PerformanceResult> entry : performanceResults.entrySet()) { - System.out.println("---> " + entry.getKey() + "\n" + entry.getValue()); - } - - PerformanceResult test1 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - PerformanceResult test9 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment09.MethodCallThoughputTimestampAnalysis9Test)"); - PerformanceResult test10 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment10.MethodCallThoughputTimestampAnalysis10Test)"); - PerformanceResult test11 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment11.MethodCallThoughputTimestampAnalysis11Test)"); - PerformanceResult test14 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment14.MethodCallThoughputTimestampAnalysis14Test)"); - PerformanceResult test15 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment15.MethodCallThoughputTimestampAnalysis15Test)"); - PerformanceResult test16a = performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16b = performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16c = performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test17 = performanceResults - .get("testWithManyObjects(teetime.examples.experiment17.MethodCallThoughputTimestampAnalysis17Test)"); - PerformanceResult test19a = performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19b = performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - PerformanceResult test19c = performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment19.MethodCallThoughputTimestampAnalysis19Test)"); - - assertEquals(67, (double) test14.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - assertEquals(14, (double) test10.quantiles.get(0.5) / test1.quantiles.get(0.5), 2.1); - assertEquals(39, (double) test11.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - assertEquals(35, (double) test9.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - assertEquals(58, (double) test15.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - - // below results vary too much, possibly due to the OS' scheduler - // assertEquals(RESULT_TESTS_16, (double) test16a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_16, (double) test16c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // - // assertEquals(RESULT_TESTS_19, (double) test19a.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19b.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // assertEquals(RESULT_TESTS_19, (double) test19c.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - - assertEquals(56, (double) test17.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - - // check speedup - assertEquals(2, (double) test16a.overallDurationInNs / test16b.overallDurationInNs, 0.2); - assertEquals(3.7, (double) test16a.overallDurationInNs / test16c.overallDurationInNs, 0.2); - - assertEquals(2, (double) test19a.overallDurationInNs / test19b.overallDurationInNs, 0.2); - assertEquals(3.7, (double) test19a.overallDurationInNs / test19c.overallDurationInNs, 0.2); - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/ChwHomePerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment01/ChwHomePerformanceCheck.java deleted file mode 100644 index 9c9321d3bfccbe7a004a9b5e31ff8ec24702f52f..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/ChwHomePerformanceCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -package teetime.examples.experiment01; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwHomePerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - PerformanceResult test01 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - - assertEquals(292, test01.quantiles.get(0.5), 1); - } -} diff --git a/src/performancetest/java/teetime/examples/experiment01/ChwWorkPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment01/ChwWorkPerformanceCheck.java deleted file mode 100644 index 0f7c9f1912896f178be06e132f36508ab8c7cd51..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/ChwWorkPerformanceCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -package teetime.examples.experiment01; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwWorkPerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } - - @Override - public void check() { - PerformanceResult test01 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - - assertEquals(410, test01.quantiles.get(0.5), 1); - } -} diff --git a/src/performancetest/java/teetime/examples/experiment01/MethodCallThoughputTimestampAnalysis1Test.java b/src/performancetest/java/teetime/examples/experiment01/MethodCallThoughputTimestampAnalysis1Test.java deleted file mode 100644 index 6577d3a39584285b83403a502e4bf83f5229505d..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/MethodCallThoughputTimestampAnalysis1Test.java +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceCheckProfileRepository; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis1Test extends PerformanceTest { - - @BeforeClass - public static void beforeClass() { - PerformanceCheckProfileRepository.INSTANCE.register(MethodCallThoughputTimestampAnalysis1Test.class, new ChwWorkPerformanceCheck()); - PerformanceCheckProfileRepository.INSTANCE.register(MethodCallThoughputTimestampAnalysis1Test.class, new ChwHomePerformanceCheck()); - }; - - @AfterClass - public static void afterClass() { - ProfiledPerformanceAssertion performanceCheckProfile = PerformanceCheckProfileRepository.INSTANCE.get(MethodCallThoughputTimestampAnalysis1Test.class); - performanceCheckProfile.check(); - }; - - // TODO check why the optimal, but inflexible impl is 500 times faster than our new framework - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis1 analysis = new MethodCallThroughputAnalysis1(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/MethodCallThroughputAnalysis1.java b/src/performancetest/java/teetime/examples/experiment01/MethodCallThroughputAnalysis1.java deleted file mode 100644 index 3f494dee35f14d499578ab4e895fbc04541e71c7..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/MethodCallThroughputAnalysis1.java +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01; - -import java.util.List; - -import teetime.examples.experiment01.legacystage.LegacyCollectorSink; -import teetime.examples.experiment01.legacystage.LegacyNoopFilter; -import teetime.examples.experiment01.legacystage.LegacyObjectProducer; -import teetime.examples.experiment01.legacystage.LegacyStartTimestampFilter; -import teetime.examples.experiment01.legacystage.LegacyStopTimestampFilter; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis1 { - - private long numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - private Runnable runnable; - - public void init() { - this.runnable = this.buildPipeline(); - } - - /** - * @param numNoopFilters - * @since 1.10 - */ - private Runnable buildPipeline() { - @SuppressWarnings("unchecked") - final LegacyNoopFilter<TimestampObject>[] noopFilters = new LegacyNoopFilter[this.numNoopFilters]; - // create stages - final LegacyObjectProducer<TimestampObject> objectProducer = new LegacyObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - final LegacyStartTimestampFilter startTimestampFilter = new LegacyStartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new LegacyNoopFilter<TimestampObject>(); - } - final LegacyStopTimestampFilter stopTimestampFilter = new LegacyStopTimestampFilter(); - final LegacyCollectorSink<TimestampObject> collectorSink = new LegacyCollectorSink<TimestampObject>(this.timestampObjects); - - final Runnable runnable = new Runnable() { - @Override - public void run() { - while (true) { - TimestampObject object = objectProducer.execute(); - if (object == null) { - return; - } - - object = startTimestampFilter.execute(object); - for (final LegacyNoopFilter<TimestampObject> noopFilter : noopFilters) { - object = noopFilter.execute(object); - } - object = stopTimestampFilter.execute(object); - collectorSink.execute(object); - } - } - }; - return runnable; - } - - public void start() { - this.runnable.run(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyCollectorSink.java b/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyCollectorSink.java deleted file mode 100644 index 50282c803115c2721e5f4fbd00cfa55e5947f19d..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyCollectorSink.java +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01.legacystage; - -import java.util.List; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class LegacyCollectorSink<T> { - - // private final InputPort<T> inputPort = this.createInputPort(); - // - // public final InputPort<T> getInputPort() { - // return this.inputPort; - // } - - private final List<T> elements; - private final int threshold; - - public LegacyCollectorSink(final List<T> list, final int threshold) { - this.elements = list; - this.threshold = threshold; - } - - public LegacyCollectorSink(final List<T> list) { - this(list, 100000); - } - - public void onIsPipelineHead() { - System.out.println("size: " + this.elements.size()); - } - - public Object execute(final T element) { - this.elements.add(element); - - if ((this.elements.size() % this.threshold) == 0) { - System.out.println("size: " + this.elements.size()); - } - - return new Object(); - // if (this.elements.size() > 90000) { - // // System.out.println("size > 90000: " + this.elements.size()); - // } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyNoopFilter.java b/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyNoopFilter.java deleted file mode 100644 index c5247c212ed954a9ff7d7740f6dae74b2fd5c568..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyNoopFilter.java +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01.legacystage; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class LegacyNoopFilter<T> { - - public T execute(final T element) { - return element; - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyObjectProducer.java b/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyObjectProducer.java deleted file mode 100644 index 16b93fbf34871e3742b35df32083a17a350e5734..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyObjectProducer.java +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01.legacystage; - -import teetime.util.ConstructorClosure; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class LegacyObjectProducer<T> { - - private long numInputObjects; - private ConstructorClosure<T> inputObjectCreator; - - /** - * @since 1.10 - */ - public LegacyObjectProducer(final long numInputObjects, final ConstructorClosure<T> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public long getNumInputObjects() { - return this.numInputObjects; - } - - public void setNumInputObjects(final long numInputObjects) { - this.numInputObjects = numInputObjects; - } - - public ConstructorClosure<T> getInputObjectCreator() { - return this.inputObjectCreator; - } - - public void setInputObjectCreator(final ConstructorClosure<T> inputObjectCreator) { - this.inputObjectCreator = inputObjectCreator; - } - - public T execute() { - if (this.numInputObjects == 0) { - return null; - } - - T newObject = this.inputObjectCreator.create(); - this.numInputObjects--; - - return newObject; - - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStartTimestampFilter.java b/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStartTimestampFilter.java deleted file mode 100644 index f2d119b9edc3cfb1a260b24cd20a15066cda0298..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStartTimestampFilter.java +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01.legacystage; - -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class LegacyStartTimestampFilter { - - public TimestampObject execute(final TimestampObject element) { - element.setStartTimestamp(System.nanoTime()); - return element; - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStopTimestampFilter.java b/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStopTimestampFilter.java deleted file mode 100644 index 1f77d38a4a216a053a2ee1c0c38d549ac5b54a16..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment01/legacystage/LegacyStopTimestampFilter.java +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment01.legacystage; - -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class LegacyStopTimestampFilter { - - public TimestampObject execute(final TimestampObject element) { - element.setStopTimestamp(System.nanoTime()); - return element; - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment09/MethodCallThoughputTimestampAnalysis9Test.java b/src/performancetest/java/teetime/examples/experiment09/MethodCallThoughputTimestampAnalysis9Test.java deleted file mode 100644 index 489f6e4a78494ca24b5792f7d1b2859f295d7e3b..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment09/MethodCallThoughputTimestampAnalysis9Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment09; - -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis9Test extends PerformanceTest { - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis9 analysis = new MethodCallThroughputAnalysis9(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment09/MethodCallThroughputAnalysis9.java b/src/performancetest/java/teetime/examples/experiment09/MethodCallThroughputAnalysis9.java deleted file mode 100644 index cd600de665c628cf1a4f7915d288173ff6c2780c..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment09/MethodCallThroughputAnalysis9.java +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment09; - -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.HeadStage; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.CommittablePipe; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis9 { - - private int numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - private Runnable runnable; - - public void init() { - HeadStage pipeline = this.buildPipeline(); - this.runnable = new RunnableStage(pipeline); - } - - /** - * @param numNoopFilters - * @return - * @since 1.10 - */ - private HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline() { - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); - - final HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(collectorSink); - - CommittablePipe.connect(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - CommittablePipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - CommittablePipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - CommittablePipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - CommittablePipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - this.runnable.run(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment10/AbstractPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment10/AbstractPerformanceCheck.java deleted file mode 100644 index 3a4e75a1e8791d2efad40971febde87366cf8f3e..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment10/AbstractPerformanceCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -package teetime.examples.experiment10; - -import teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test; -import util.test.MeasurementRepository; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public abstract class AbstractPerformanceCheck extends ProfiledPerformanceAssertion { - - protected PerformanceResult test01; - protected PerformanceResult test10; - - @Override - public void check() { - String testMethodIdentifier = MeasurementRepository.buildTestMethodIdentifier(MethodCallThoughputTimestampAnalysis1Test.class, "testWithManyObjects"); - test01 = PerformanceTest.measurementRepository.performanceResults.get(testMethodIdentifier); - testMethodIdentifier = MeasurementRepository.buildTestMethodIdentifier(MethodCallThoughputTimestampAnalysis10Test.class, "testWithManyObjects"); - test10 = PerformanceTest.measurementRepository.performanceResults.get(testMethodIdentifier); - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment10/ChwHomePerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment10/ChwHomePerformanceCheck.java deleted file mode 100644 index 925ab5bbc66743dc9eacf3b14269856fb2a1b8ec..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment10/ChwHomePerformanceCheck.java +++ /dev/null @@ -1,29 +0,0 @@ -package teetime.examples.experiment10; - -import static org.junit.Assert.assertEquals; - -public class ChwHomePerformanceCheck extends AbstractPerformanceCheck { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - super.check(); - - double meanSpeedup = (double) test10.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("meanSpeedup (10): " + meanSpeedup); - - // since 26.06.2014 (incl.) - // assertEquals(26, value10, 2.1); // +14 - // // since 04.07.2014 (incl.) - // assertEquals(26, value10, 2.1); // +0 - // since 11.08.2014 (incl.) - // assertEquals(47, value10, 2.1); // +21 - // since 31.08.2014 (incl.) - assertEquals(51, meanSpeedup, 2.1); - } -} diff --git a/src/performancetest/java/teetime/examples/experiment10/ChwWorkPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment10/ChwWorkPerformanceCheck.java deleted file mode 100644 index 2845935e1e0d2870c1574f79a8682da88f4dc496..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment10/ChwWorkPerformanceCheck.java +++ /dev/null @@ -1,31 +0,0 @@ -package teetime.examples.experiment10; - -import static org.junit.Assert.assertEquals; - -public class ChwWorkPerformanceCheck extends AbstractPerformanceCheck { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } - - @Override - public void check() { - super.check(); - - double medianSpeedup = (double) test10.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("medianSpeedup (10): " + medianSpeedup); - - // until 25.06.2014 (incl.) - // assertEquals(14, (double) test10.quantiles.get(0.5) / test1.quantiles.get(0.5), 2.1); - // since 26.06.2014 (incl.) - // assertEquals(26, meanSpeedup, 2.1); // +14 - // since 04.07.2014 (incl.) - // assertEquals(26, meanSpeedup, 2.1); // +0 - // since 27.08.2014 (incl.) - // assertEquals(56, meanSpeedup, 2.1); // +30 - // since 14.10.2014 (incl.) - assertEquals(25, medianSpeedup, 3.1); // -31 - } -} diff --git a/src/performancetest/java/teetime/examples/experiment10/MethodCallThoughputTimestampAnalysis10Test.java b/src/performancetest/java/teetime/examples/experiment10/MethodCallThoughputTimestampAnalysis10Test.java deleted file mode 100644 index f73409d333e023ebe57d956dcc1a7d82c14809f6..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment10/MethodCallThoughputTimestampAnalysis10Test.java +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment10; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis10Test extends PerformanceTest { - - @BeforeClass - public static void beforeClass() { - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis10Test.class, new ChwWorkPerformanceCheck()); - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis10Test.class, new ChwHomePerformanceCheck()); - }; - - @AfterClass - public static void afterClass() { - ProfiledPerformanceAssertion performanceCheckProfile = PERFORMANCE_CHECK_PROFILE_REPOSITORY.get(MethodCallThoughputTimestampAnalysis10Test.class); - performanceCheckProfile.check(); - }; - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis10 analysis = new MethodCallThroughputAnalysis10(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment10/MethodCallThroughputAnalysis10.java b/src/performancetest/java/teetime/examples/experiment10/MethodCallThroughputAnalysis10.java deleted file mode 100644 index 82a31ff2bcdb706b0b67aec457fee9b82880636b..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment10/MethodCallThroughputAnalysis10.java +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment10; - -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.SingleElementPipe; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis10 { - - private long numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - private Runnable runnable; - - public void init() { - this.runnable = this.buildPipeline(); - } - - /** - * @param numNoopFilters - * @since 1.10 - */ - private Runnable buildPipeline() { - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); - - final HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(collectorSink); - - SingleElementPipe.connect(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - SingleElementPipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - SingleElementPipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - SingleElementPipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - SingleElementPipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return new RunnableStage(pipeline); - } - - public void start() { - this.runnable.run(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment11/ChwHomePerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment11/ChwHomePerformanceCheck.java deleted file mode 100644 index 6b5d256d1ac58d6147532a0b9dbbf4ce522f9b06..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment11/ChwHomePerformanceCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -package teetime.examples.experiment11; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwHomePerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - PerformanceResult test01 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - PerformanceResult test11 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment11.MethodCallThoughputTimestampAnalysis11Test)"); - - double medianSpeedup = (double) test11.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("medianSpeedup (11): " + medianSpeedup); - - // until 25.06.2014 (incl.) - // assertEquals(32, (double) test11.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - // since 26.06.2014 (incl.) - // assertEquals(44, medianSpeedup, 4.1); // +12 - // since 04.07.2014 (incl.) - // assertEquals(41, medianSpeedup, 4.1); // -3 - // since 11.08.2014 (incl.) - // assertEquals(41, medianSpeedup, 4.1); // -3 - // since 31.08.2014 (incl.) - assertEquals(43, medianSpeedup, 4.1); // ?? - } -} diff --git a/src/performancetest/java/teetime/examples/experiment11/ChwWorkPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment11/ChwWorkPerformanceCheck.java deleted file mode 100644 index 65049146d5c0fa586343bbc91c91f0b3c8c4bb59..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment11/ChwWorkPerformanceCheck.java +++ /dev/null @@ -1,37 +0,0 @@ -package teetime.examples.experiment11; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwWorkPerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } - - @Override - public void check() { - PerformanceResult test01 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test)"); - PerformanceResult test11 = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjects(teetime.examples.experiment11.MethodCallThoughputTimestampAnalysis11Test)"); - - double medianSpeedup = (double) test11.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("medianSpeedup (11): " + medianSpeedup); - - // until 25.06.2014 (incl.) - // assertEquals(32, (double) test11.quantiles.get(0.5) / test1.quantiles.get(0.5), 4.1); - // since 26.06.2014 (incl.) - // assertEquals(44, medianSpeedup, 4.1); // +12 - // since 04.07.2014 (incl.) - // assertEquals(41, medianSpeedup, 4.1); // -3 - // since 27.08.2014 (incl.) - // assertEquals(64, medianSpeedup, 4.1); // +15 - // since 14.10.2014 (incl.) - assertEquals(44, medianSpeedup, 4.1); // -20 - } -} diff --git a/src/performancetest/java/teetime/examples/experiment11/MethodCallThoughputTimestampAnalysis11Test.java b/src/performancetest/java/teetime/examples/experiment11/MethodCallThoughputTimestampAnalysis11Test.java deleted file mode 100644 index 80e22ff08ea51e7e721e36cd2d71527dd205b9ac..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment11/MethodCallThoughputTimestampAnalysis11Test.java +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment11; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis11Test extends PerformanceTest { - - @BeforeClass - public static void beforeClass() { - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis11Test.class, new ChwWorkPerformanceCheck()); - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis11Test.class, new ChwHomePerformanceCheck()); - }; - - @AfterClass - public static void afterClass() { - ProfiledPerformanceAssertion performanceCheckProfile = PERFORMANCE_CHECK_PROFILE_REPOSITORY.get(MethodCallThoughputTimestampAnalysis11Test.class); - performanceCheckProfile.check(); - }; - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis11 analysis = new MethodCallThroughputAnalysis11(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment11/MethodCallThroughputAnalysis11.java b/src/performancetest/java/teetime/examples/experiment11/MethodCallThroughputAnalysis11.java deleted file mode 100644 index 07b681ab9d9dd7bee6ce09a3eb9f045d880eb5fd..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment11/MethodCallThroughputAnalysis11.java +++ /dev/null @@ -1,107 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment11; - -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.HeadStage; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.UnorderedGrowablePipe; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis11 { - - private long numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - private Runnable runnable; - - public void init() { - HeadStage pipeline = this.buildPipeline(this.numInputObjects, this.inputObjectCreator); - this.runnable = new RunnableStage(pipeline); - } - - private HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline(final long numInputObjects, - final ConstructorClosure<TimestampObject> inputObjectCreator) { - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(numInputObjects, inputObjectCreator); - // Relay<TimestampObject> relay = new Relay<TimestampObject>(); - // NoopFilter<TimestampObject> relayFake = new NoopFilter<TimestampObject>(); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); - - final HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(collectorSink); - - UnorderedGrowablePipe.connect(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - // UnorderedGrowablePipe.connect(objectProducer.getOutputPort(), relayFake.getInputPort()); - // UnorderedGrowablePipe.connect(relayFake.getOutputPort(), startTimestampFilter.getInputPort()); - - UnorderedGrowablePipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - UnorderedGrowablePipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - UnorderedGrowablePipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - UnorderedGrowablePipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - this.runnable.run(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment14/AbstractPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment14/AbstractPerformanceCheck.java deleted file mode 100644 index 86b158afdb987ea1b597ea348a8cca02406cd2de..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment14/AbstractPerformanceCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -package teetime.examples.experiment14; - -import teetime.examples.experiment01.MethodCallThoughputTimestampAnalysis1Test; -import util.test.MeasurementRepository; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public abstract class AbstractPerformanceCheck extends ProfiledPerformanceAssertion { - - protected PerformanceResult test01; - protected PerformanceResult test14; - - @Override - public void check() { - String testMethodIdentifier = MeasurementRepository.buildTestMethodIdentifier(MethodCallThoughputTimestampAnalysis1Test.class, "testWithManyObjects"); - test01 = PerformanceTest.measurementRepository.performanceResults.get(testMethodIdentifier); - testMethodIdentifier = MeasurementRepository.buildTestMethodIdentifier(MethodCallThoughputTimestampAnalysis14Test.class, "testWithManyObjects"); - test14 = PerformanceTest.measurementRepository.performanceResults.get(testMethodIdentifier); - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment14/ChwHomePerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment14/ChwHomePerformanceCheck.java deleted file mode 100644 index 5b34a6d4c9a87ffb1e6eec3f39e10ae86e8b4273..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment14/ChwHomePerformanceCheck.java +++ /dev/null @@ -1,31 +0,0 @@ -package teetime.examples.experiment14; - -import static org.junit.Assert.assertEquals; - -public class ChwHomePerformanceCheck extends AbstractPerformanceCheck { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - super.check(); - - double medianSpeedup = (double) test14.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("medianSpeedup (14): " + medianSpeedup); - - // until 25.06.2014 (incl.) - // assertEquals(60, (double) test14.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // since 26.06.2014 (incl.) - // assertEquals(76, medianSpeedup, 5.1); // +16 - // since 04.07.2014 (incl.) - // assertEquals(86, medianSpeedup, 5.1); // +16 - // since 11.08.2014 (incl.) - // assertEquals(103, medianSpeedup, 5.1); // +17 - // since 31.08.2014 (incl.) - assertEquals(62, medianSpeedup, 2.1); // -41 - } -} diff --git a/src/performancetest/java/teetime/examples/experiment14/ChwWorkPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment14/ChwWorkPerformanceCheck.java deleted file mode 100644 index eeea568d8114f5434186582faa6b72e516715c83..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment14/ChwWorkPerformanceCheck.java +++ /dev/null @@ -1,31 +0,0 @@ -package teetime.examples.experiment14; - -import static org.junit.Assert.assertEquals; - -public class ChwWorkPerformanceCheck extends AbstractPerformanceCheck { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } - - @Override - public void check() { - super.check(); - - double medianSpeedup = (double) test14.quantiles.get(0.5) / test01.quantiles.get(0.5); - - System.out.println("medianSpeedup (14): " + medianSpeedup); - - // until 25.06.2014 (incl.) - // assertEquals(60, (double) test14.quantiles.get(0.5) / test1.quantiles.get(0.5), 5.1); - // since 26.06.2014 (incl.) - // assertEquals(76, medianSpeedup, 5.1); // +16 - // since 04.07.2014 (incl.) - // assertEquals(86, medianSpeedup, 5.1); // +16 - // since 27.08.2014 (incl.) - // assertEquals(102, medianSpeedup, 5.1); // +16 - // since 14.10.2014 (incl.) - assertEquals(81, medianSpeedup, 5.1); // -21 - } -} diff --git a/src/performancetest/java/teetime/examples/experiment14/MethodCallThoughputTimestampAnalysis14Test.java b/src/performancetest/java/teetime/examples/experiment14/MethodCallThoughputTimestampAnalysis14Test.java deleted file mode 100644 index 3d743f81f0117071c84403f59e8adc5e558765d1..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment14/MethodCallThoughputTimestampAnalysis14Test.java +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment14; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis14Test extends PerformanceTest { - - @BeforeClass - public static void beforeClass() { - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis14Test.class, new ChwWorkPerformanceCheck()); - PERFORMANCE_CHECK_PROFILE_REPOSITORY.register(MethodCallThoughputTimestampAnalysis14Test.class, new ChwHomePerformanceCheck()); - }; - - @AfterClass - public static void afterClass() { - ProfiledPerformanceAssertion performanceCheckProfile = PERFORMANCE_CHECK_PROFILE_REPOSITORY.get(MethodCallThoughputTimestampAnalysis14Test.class); - performanceCheckProfile.check(); - }; - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis14 analysis = new MethodCallThroughputAnalysis14(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment14/MethodCallThroughputAnalysis14.java b/src/performancetest/java/teetime/examples/experiment14/MethodCallThroughputAnalysis14.java deleted file mode 100644 index e229ebc555801dfd1a1b3cf1f5ea1c93863351b0..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment14/MethodCallThroughputAnalysis14.java +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment14; - -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.HeadStage; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.IPipeFactory; -import teetime.framework.pipe.PipeFactoryRegistry; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis14 { - - private long numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - private Runnable runnable; - private final PipeFactoryRegistry pipeFactory = PipeFactoryRegistry.INSTANCE; - - public void init() { - HeadStage pipeline = this.buildPipeline(); - this.runnable = new RunnableStage(pipeline); - } - - /** - * @param numNoopFilters - * @return - * @since 1.10 - */ - private HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline() { - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); - - final HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(collectorSink); - - IPipeFactory factory = this.pipeFactory.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.QUEUE_BASED, true); - - factory.create(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - factory.create(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - factory.create(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - factory.create(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - factory.create(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - this.runnable.run(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment15/MethodCallThoughputTimestampAnalysis15Test.java b/src/performancetest/java/teetime/examples/experiment15/MethodCallThoughputTimestampAnalysis15Test.java deleted file mode 100644 index 356647b0f19e5fbe80d27e98847d32f5a8a8de92..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment15/MethodCallThoughputTimestampAnalysis15Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment15; - -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis15Test extends PerformanceTest { - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis15 analysis = new MethodCallThroughputAnalysis15(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setTimestampObjects(this.timestampObjects); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment15/MethodCallThroughputAnalysis15.java b/src/performancetest/java/teetime/examples/experiment15/MethodCallThroughputAnalysis15.java deleted file mode 100644 index 6850f50cabddee7841602aa3179097f4ebced016..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment15/MethodCallThroughputAnalysis15.java +++ /dev/null @@ -1,142 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment15; - -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.HeadStage; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.OrderedGrowableArrayPipe; -import teetime.framework.pipe.SingleElementPipe; -import teetime.framework.pipe.SpScPipe; -import teetime.stage.Clock; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.stage.basic.Delay; -import teetime.stage.basic.Sink; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis15 { - // FIXME this analysis sometimes runs infinitely - - private static final int SPSC_INITIAL_CAPACITY = 4; - - private int numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - private List<TimestampObject> timestampObjects; - - private Runnable clockRunnable; - private Runnable runnable; - private Clock clock; - - public void init() { - - HeadPipeline<Clock, Sink<Long>> clockPipeline = this.buildClockPipeline(); - this.clockRunnable = new RunnableStage(clockPipeline); - - HeadStage pipeline = this.buildPipeline(this.clock); - this.runnable = new RunnableStage(pipeline); - } - - private HeadPipeline<Clock, Sink<Long>> buildClockPipeline() { - this.clock = new Clock(); - - this.clock.setInitialDelayInMs(100); - this.clock.setIntervalDelayInMs(100); - - final HeadPipeline<Clock, Sink<Long>> pipeline = new HeadPipeline<Clock, Sink<Long>>(); - pipeline.setFirstStage(this.clock); - pipeline.setLastStage(new Sink<Long>()); - - return pipeline; - } - - /** - * @param numNoopFilters - * @return - * @since 1.10 - */ - private HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline(final Clock clock) { - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - Delay<TimestampObject> delay = new Delay<TimestampObject>(); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(this.timestampObjects); - - final HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(collectorSink); - - SpScPipe.connect(clock.getOutputPort(), delay.getTimestampTriggerInputPort(), SPSC_INITIAL_CAPACITY); - - SingleElementPipe.connect(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - SingleElementPipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - SingleElementPipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - SingleElementPipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - OrderedGrowableArrayPipe.connect(stopTimestampFilter.getOutputPort(), delay.getInputPort()); - - SingleElementPipe.connect(delay.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - Thread clockThread = new Thread(this.clockRunnable); - clockThread.start(); - this.runnable.run(); - clockThread.interrupt(); - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<TimestampObject> getTimestampObjects() { - return this.timestampObjects; - } - - public void setTimestampObjects(final List<TimestampObject> timestampObjects) { - this.timestampObjects = timestampObjects; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment16/ChwHomePerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment16/ChwHomePerformanceCheck.java deleted file mode 100644 index 29a27cf7b1b80831cc30b5db330429f51686a399..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment16/ChwHomePerformanceCheck.java +++ /dev/null @@ -1,33 +0,0 @@ -package teetime.examples.experiment16; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwHomePerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwHome"; - } - - @Override - public void check() { - PerformanceResult test16a = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16b = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16c = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - // check speedup - double speedupB = (double) test16a.overallDurationInNs / test16b.overallDurationInNs; - double speedupC = (double) test16a.overallDurationInNs / test16c.overallDurationInNs; - - System.out.println("speedupB: " + speedupB); - System.out.println("speedupC: " + speedupC); - - assertEquals(2, speedupB, 0.3); - assertEquals(3.6, speedupC, 0.3); - } -} diff --git a/src/performancetest/java/teetime/examples/experiment16/ChwWorkPerformanceCheck.java b/src/performancetest/java/teetime/examples/experiment16/ChwWorkPerformanceCheck.java deleted file mode 100644 index 8aeae42d96d7c92a9f652774ed37612e8dc3e9de..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment16/ChwWorkPerformanceCheck.java +++ /dev/null @@ -1,33 +0,0 @@ -package teetime.examples.experiment16; - -import static org.junit.Assert.assertEquals; -import util.test.PerformanceResult; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -public class ChwWorkPerformanceCheck extends ProfiledPerformanceAssertion { - - @Override - public void check() { - PerformanceResult test16a = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16b = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - PerformanceResult test16c = PerformanceTest.measurementRepository.performanceResults - .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - // check speedup - double speedupB = (double) test16a.overallDurationInNs / test16b.overallDurationInNs; - double speedupC = (double) test16a.overallDurationInNs / test16c.overallDurationInNs; - - System.out.println("speedupB: " + speedupB); - System.out.println("speedupC: " + speedupC); - - assertEquals(2, speedupB, 0.3); - assertEquals(2.5, speedupC, 0.3); - } - - @Override - public String getCorrespondingPerformanceProfile() { - return "ChwWork"; - } -} diff --git a/src/performancetest/java/teetime/examples/experiment16/MethodCallThoughputTimestampAnalysis16Test.java b/src/performancetest/java/teetime/examples/experiment16/MethodCallThoughputTimestampAnalysis16Test.java deleted file mode 100644 index 7dd7ea2b0e1b8536d0afd902e5a88f0db4606bd9..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment16/MethodCallThoughputTimestampAnalysis16Test.java +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment16; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import teetime.util.ConstructorClosure; -import teetime.util.ListUtil; -import teetime.util.TimestampObject; -import util.test.PerformanceCheckProfileRepository; -import util.test.PerformanceTest; -import util.test.ProfiledPerformanceAssertion; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MethodCallThoughputTimestampAnalysis16Test extends PerformanceTest { - - // TODO use @Parameter for the number of threads - - @BeforeClass - public static void beforeClass() { - PerformanceCheckProfileRepository.INSTANCE.register(MethodCallThoughputTimestampAnalysis16Test.class, new ChwWorkPerformanceCheck()); - PerformanceCheckProfileRepository.INSTANCE.register(MethodCallThoughputTimestampAnalysis16Test.class, new ChwHomePerformanceCheck()); - } - - @AfterClass - public static void afterClass() { - ProfiledPerformanceAssertion pcp = PerformanceCheckProfileRepository.INSTANCE.get(MethodCallThoughputTimestampAnalysis16Test.class); - pcp.check(); - } - - @Test - public void testWithManyObjectsAnd1Thread() { - this.performAnalysis(1); - } - - @Test - public void testWithManyObjectsAnd2Threads() { - this.performAnalysis(2); - } - - @Test - public void testWithManyObjectsAnd4Threads() { - this.performAnalysis(4); - } - - private void performAnalysis(final int numThreads) { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis16 analysis = new MethodCallThroughputAnalysis16(); - analysis.setNumWorkerThreads(numThreads); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - - this.timestampObjects = ListUtil.merge(analysis.getTimestampObjectsList()); - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment16/MethodCallThroughputAnalysis16.java b/src/performancetest/java/teetime/examples/experiment16/MethodCallThroughputAnalysis16.java deleted file mode 100644 index c84c2bad7ded7a93e6fbfe3449afe0e922966751..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment16/MethodCallThroughputAnalysis16.java +++ /dev/null @@ -1,175 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment16; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.SingleElementPipe; -import teetime.framework.pipe.SpScPipe; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.Relay; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.stage.basic.distributor.Distributor; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis16 { - - private static final int SPSC_INITIAL_CAPACITY = 100100; - private static final int NUM_WORKER_THREADS = Runtime.getRuntime().availableProcessors(); - - private int numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - - private final List<List<TimestampObject>> timestampObjectsList = new LinkedList<List<TimestampObject>>(); - - private Thread producerThread; - - private Thread[] workerThreads; - - private int numWorkerThreads; - - public void init() { - HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> producerPipeline = this.buildProducerPipeline(this.numInputObjects, - this.inputObjectCreator); - this.producerThread = new Thread(new RunnableStage(producerPipeline)); - - this.numWorkerThreads = Math.min(NUM_WORKER_THREADS, this.numWorkerThreads); - - this.workerThreads = new Thread[this.numWorkerThreads]; - for (int i = 0; i < this.workerThreads.length; i++) { - List<TimestampObject> resultList = new ArrayList<TimestampObject>(this.numInputObjects); - this.timestampObjectsList.add(resultList); - - HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> workerPipeline = this.buildPipeline(producerPipeline, resultList); - this.workerThreads[i] = new Thread(new RunnableStage(workerPipeline)); - } - } - - private HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> buildProducerPipeline(final int numInputObjects, - final ConstructorClosure<TimestampObject> inputObjectCreator) { - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(numInputObjects, inputObjectCreator); - Distributor<TimestampObject> distributor = new Distributor<TimestampObject>(); - - final HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(distributor); - - SingleElementPipe.connect(objectProducer.getOutputPort(), distributor.getInputPort()); - - return pipeline; - } - - /** - * @param numNoopFilters - * @since 1.10 - */ - private HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline( - final HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> previousStage, - final List<TimestampObject> timestampObjects) { - Relay<TimestampObject> relay = new Relay<TimestampObject>(); - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(timestampObjects); - - final HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(relay); - pipeline.setLastStage(collectorSink); - - SpScPipe.connect(previousStage.getLastStage().getNewOutputPort(), relay.getInputPort(), SPSC_INITIAL_CAPACITY); - - SingleElementPipe.connect(relay.getOutputPort(), startTimestampFilter.getInputPort()); - - SingleElementPipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - SingleElementPipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - SingleElementPipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - SingleElementPipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - - this.producerThread.start(); - - for (Thread workerThread : this.workerThreads) { - workerThread.start(); - } - - try { - this.producerThread.join(); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - for (Thread workerThread : this.workerThreads) { - workerThread.join(); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<List<TimestampObject>> getTimestampObjectsList() { - return this.timestampObjectsList; - } - - public int getNumWorkerThreads() { - return this.numWorkerThreads; - } - - public void setNumWorkerThreads(final int numWorkerThreads) { - this.numWorkerThreads = numWorkerThreads; - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment17/MethodCallThoughputTimestampAnalysis17Test.java b/src/performancetest/java/teetime/examples/experiment17/MethodCallThoughputTimestampAnalysis17Test.java deleted file mode 100644 index 650d11706482de244efd7db554a15041c0731391..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment17/MethodCallThoughputTimestampAnalysis17Test.java +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment17; - -import org.junit.Test; - -import teetime.util.ConstructorClosure; -import teetime.util.ListUtil; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThoughputTimestampAnalysis17Test extends PerformanceTest { - - @Test - public void testWithManyObjects() { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - // int count = 10; - // while (count-- > 0) { - final MethodCallThroughputAnalysis17 analysis = new MethodCallThroughputAnalysis17(); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - System.out.println("starting"); - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - - this.timestampObjects = ListUtil.merge(analysis.getTimestampObjectsList()); - // } - } -} diff --git a/src/performancetest/java/teetime/examples/experiment17/MethodCallThroughputAnalysis17.java b/src/performancetest/java/teetime/examples/experiment17/MethodCallThroughputAnalysis17.java deleted file mode 100644 index 62345de3f6f43209dc3f5cb5f16eccb87dfdaf65..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment17/MethodCallThroughputAnalysis17.java +++ /dev/null @@ -1,200 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment17; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.RunnableStage; -import teetime.framework.Stage; -import teetime.framework.pipe.DummyPipe; -import teetime.framework.pipe.IPipe; -import teetime.framework.pipe.PipeFactoryRegistry; -import teetime.framework.pipe.RelayTestPipe; -import teetime.framework.pipe.UnorderedGrowablePipe; -import teetime.framework.signal.TerminatingSignal; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.Relay; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.stage.basic.Sink; -import teetime.stage.basic.distributor.Distributor; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis17 { - - private static final int SPSC_INITIAL_CAPACITY = 100100; - private static final int NUM_WORKER_THREADS = Runtime.getRuntime().availableProcessors(); - - private int numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - - private final PipeFactoryRegistry pipeFactory = PipeFactoryRegistry.INSTANCE; - private final List<List<TimestampObject>> timestampObjectsList = new LinkedList<List<TimestampObject>>(); - - private Thread producerThread; - private Thread[] workerThreads; - - public void init() { - HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> producerPipeline = this.buildProducerPipeline(this.numInputObjects, - this.inputObjectCreator); - this.producerThread = new Thread(new RunnableStage(producerPipeline)); - - int numWorkerThreads = Math.min(NUM_WORKER_THREADS, 1); // only for testing purpose - - this.workerThreads = new Thread[numWorkerThreads]; - for (int i = 0; i < this.workerThreads.length; i++) { - List<TimestampObject> resultList = new ArrayList<TimestampObject>(this.numInputObjects); - this.timestampObjectsList.add(resultList); - - HeadPipeline<?, ?> pipeline = this.buildPipeline(null, resultList); - this.workerThreads[i] = new Thread(new RunnableStage(pipeline)); - } - - // this.producerThread = new Thread(new Runnable() { - // @Override - // public void run() { - // TimestampObject ts; - // try { - // ts = MethodCallThroughputAnalysis17.this.inputObjectCreator.call(); - // System.out.println("test" + producerPipeline + ", # filters: " + MethodCallThroughputAnalysis17.this.numNoopFilters + ", ts: " - // + ts); - // MethodCallThroughputAnalysis17.this.numInputObjects++; - // System.out.println("numInputObjects: " + MethodCallThroughputAnalysis17.this.numInputObjects); - // MethodCallThroughputAnalysis17.this.numInputObjects--; - // } catch (Exception e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // System.out.println("run end"); - // } - // }); - - // this.producerThread.start(); - // this.producerThread.run(); - new RunnableStage(producerPipeline).run(); - - // try { - // this.producerThread.join(); - // } catch (InterruptedException e1) { - // // TODO Auto-generated catch block - // e1.printStackTrace(); - // } - - } - - @SuppressWarnings("unchecked") - private HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> buildProducerPipeline(final int numInputObjects, - final ConstructorClosure<TimestampObject> inputObjectCreator) { - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(numInputObjects, inputObjectCreator); - Distributor<TimestampObject> distributor = new Distributor<TimestampObject>(); - - // UnorderedGrowablePipe.connect(objectProducer.getOutputPort(), sink.getInputPort()); - // objectProducer.getOutputPort().pipe = new UnorderedGrowablePipe<TimestampObject>(); - - UnorderedGrowablePipe.connect(objectProducer.getOutputPort(), distributor.getInputPort()); - distributor.getNewOutputPort().setPipe(new DummyPipe()); - - final HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - // pipeline.setFirstStage(sink); - // pipeline.setFirstStage(endStage); - pipeline.setLastStage(distributor); - // pipeline.setLastStage(sink); - // pipeline.setLastStage(new EndStage<TimestampObject>()); - return pipeline; - } - - /** - * @param numNoopFilters - * @since 1.10 - */ - private HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> buildPipeline(final Stage previousStage, - final List<TimestampObject> timestampObjects) { - // create stages - Relay<TimestampObject> relay = new Relay<TimestampObject>(); - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(timestampObjects); - - IPipe startPipe = new RelayTestPipe<TimestampObject>(this.numInputObjects, this.inputObjectCreator); - startPipe.sendSignal(new TerminatingSignal()); - - relay.getInputPort().setPipe(startPipe); - UnorderedGrowablePipe.connect(relay.getOutputPort(), startTimestampFilter.getInputPort()); - UnorderedGrowablePipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - UnorderedGrowablePipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - UnorderedGrowablePipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - UnorderedGrowablePipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - final HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(relay); - pipeline.setLastStage(collectorSink); - return pipeline; - } - - public void start() { - - for (Thread workerThread : this.workerThreads) { - workerThread.start(); - } - - try { - for (Thread workerThread : this.workerThreads) { - workerThread.join(); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<List<TimestampObject>> getTimestampObjectsList() { - return this.timestampObjectsList; - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment19/MethodCallThoughputTimestampAnalysis19Test.java b/src/performancetest/java/teetime/examples/experiment19/MethodCallThoughputTimestampAnalysis19Test.java deleted file mode 100644 index 59d13f1d98a19fde419451f63662eabdc5fa4b0d..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment19/MethodCallThoughputTimestampAnalysis19Test.java +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment19; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import teetime.util.ConstructorClosure; -import teetime.util.ListUtil; -import teetime.util.TimestampObject; -import util.test.PerformanceTest; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MethodCallThoughputTimestampAnalysis19Test extends PerformanceTest { - - // TODO use @Parameter for the number of threads - - @Test - public void testWithManyObjectsAnd1Thread() { - this.performAnalysis(1); - } - - @Test - public void testWithManyObjectsAnd2Threads() { - this.performAnalysis(2); - } - - @Test - public void testWithManyObjectsAnd4Threads() { - this.performAnalysis(4); - } - - // @AfterClass - // public static void afterClass() { - // PerformanceResult test16a = PerformanceTest.measurementRepository.performanceResults - // .get("testWithManyObjectsAnd1Thread(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - // PerformanceResult test16b = PerformanceTest.measurementRepository.performanceResults - // .get("testWithManyObjectsAnd2Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - // PerformanceResult test16c = PerformanceTest.measurementRepository.performanceResults - // .get("testWithManyObjectsAnd4Threads(teetime.examples.experiment16.MethodCallThoughputTimestampAnalysis16Test)"); - // // check speedup - // assertEquals(2, (double) test16a.overallDurationInNs / test16b.overallDurationInNs, 0.2); - // assertEquals(2.5, (double) test16a.overallDurationInNs / test16c.overallDurationInNs, 0.2); - // } - - private void performAnalysis(final int numThreads) { - System.out.println("Testing teetime (mc) with NUM_OBJECTS_TO_CREATE=" + NUM_OBJECTS_TO_CREATE + ", NUM_NOOP_FILTERS=" - + NUM_NOOP_FILTERS + "..."); - - final MethodCallThroughputAnalysis19 analysis = new MethodCallThroughputAnalysis19(); - analysis.setNumWorkerThreads(numThreads); - analysis.setNumNoopFilters(NUM_NOOP_FILTERS); - analysis.setInput(NUM_OBJECTS_TO_CREATE, new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - }); - analysis.init(); - - this.stopWatch.start(); - try { - analysis.start(); - } finally { - this.stopWatch.end(); - } - - this.timestampObjects = ListUtil.merge(analysis.getTimestampObjectsList()); - } - -} diff --git a/src/performancetest/java/teetime/examples/experiment19/MethodCallThroughputAnalysis19.java b/src/performancetest/java/teetime/examples/experiment19/MethodCallThroughputAnalysis19.java deleted file mode 100644 index b91a703bc3f61df66be2ccb72a2f174c34b9b7a9..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/experiment19/MethodCallThroughputAnalysis19.java +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************** - * Copyright 2014 Kieker Project (http://kieker-monitoring.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.examples.experiment19; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import teetime.framework.HeadPipeline; -import teetime.framework.RunnableStage; -import teetime.framework.pipe.OrderedGrowableArrayPipe; -import teetime.framework.pipe.SpScPipe; -import teetime.stage.CollectorSink; -import teetime.stage.NoopFilter; -import teetime.stage.ObjectProducer; -import teetime.stage.Relay; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.stage.basic.distributor.Distributor; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class MethodCallThroughputAnalysis19 { - - private static final int SPSC_INITIAL_CAPACITY = 100100; - private static final int NUM_WORKER_THREADS = Runtime.getRuntime().availableProcessors(); - - private int numInputObjects; - private ConstructorClosure<TimestampObject> inputObjectCreator; - private int numNoopFilters; - - private final List<List<TimestampObject>> timestampObjectsList = new LinkedList<List<TimestampObject>>(); - - private Thread producerThread; - - private Thread[] workerThreads; - - private int numWorkerThreads; - - public void init() { - HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> producerPipeline = this.buildProducerPipeline(this.numInputObjects, - this.inputObjectCreator); - this.producerThread = new Thread(new RunnableStage(producerPipeline)); - - this.numWorkerThreads = Math.min(NUM_WORKER_THREADS, this.numWorkerThreads); - - this.workerThreads = new Thread[this.numWorkerThreads]; - for (int i = 0; i < this.workerThreads.length; i++) { - List<TimestampObject> resultList = new ArrayList<TimestampObject>(this.numInputObjects); - this.timestampObjectsList.add(resultList); - - HeadPipeline<?, ?> pipeline = this.buildPipeline(producerPipeline.getLastStage(), resultList); - this.workerThreads[i] = new Thread(new RunnableStage(pipeline)); - } - - } - - private HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> buildProducerPipeline(final int numInputObjects, - final ConstructorClosure<TimestampObject> inputObjectCreator) { - final ObjectProducer<TimestampObject> objectProducer = new ObjectProducer<TimestampObject>(numInputObjects, inputObjectCreator); - Distributor<TimestampObject> distributor = new Distributor<TimestampObject>(); - - final HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>> pipeline = new HeadPipeline<ObjectProducer<TimestampObject>, Distributor<TimestampObject>>(); - pipeline.setFirstStage(objectProducer); - pipeline.setLastStage(distributor); - - OrderedGrowableArrayPipe.connect(objectProducer.getOutputPort(), distributor.getInputPort()); - - return pipeline; - } - - private HeadPipeline<?, ?> buildPipeline(final Distributor<TimestampObject> previousStage, final List<TimestampObject> timestampObjects) { - Relay<TimestampObject> relay = new Relay<TimestampObject>(); - @SuppressWarnings("unchecked") - final NoopFilter<TimestampObject>[] noopFilters = new NoopFilter[this.numNoopFilters]; - // create stages - final StartTimestampFilter startTimestampFilter = new StartTimestampFilter(); - for (int i = 0; i < noopFilters.length; i++) { - noopFilters[i] = new NoopFilter<TimestampObject>(); - } - final StopTimestampFilter stopTimestampFilter = new StopTimestampFilter(); - final CollectorSink<TimestampObject> collectorSink = new CollectorSink<TimestampObject>(timestampObjects); - - final HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>> pipeline = new HeadPipeline<Relay<TimestampObject>, CollectorSink<TimestampObject>>(); - pipeline.setFirstStage(relay); - pipeline.setLastStage(collectorSink); - - SpScPipe.connect(previousStage.getNewOutputPort(), relay.getInputPort(), SPSC_INITIAL_CAPACITY); - - OrderedGrowableArrayPipe.connect(relay.getOutputPort(), startTimestampFilter.getInputPort()); - - OrderedGrowableArrayPipe.connect(startTimestampFilter.getOutputPort(), noopFilters[0].getInputPort()); - for (int i = 0; i < noopFilters.length - 1; i++) { - OrderedGrowableArrayPipe.connect(noopFilters[i].getOutputPort(), noopFilters[i + 1].getInputPort()); - } - OrderedGrowableArrayPipe.connect(noopFilters[noopFilters.length - 1].getOutputPort(), stopTimestampFilter.getInputPort()); - OrderedGrowableArrayPipe.connect(stopTimestampFilter.getOutputPort(), collectorSink.getInputPort()); - - return pipeline; - } - - public void start() { - - this.producerThread.start(); - - for (Thread workerThread : this.workerThreads) { - workerThread.start(); - } - - try { - this.producerThread.join(); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - for (Thread workerThread : this.workerThreads) { - workerThread.join(); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setInput(final int numInputObjects, final ConstructorClosure<TimestampObject> inputObjectCreator) { - this.numInputObjects = numInputObjects; - this.inputObjectCreator = inputObjectCreator; - } - - public int getNumNoopFilters() { - return this.numNoopFilters; - } - - public void setNumNoopFilters(final int numNoopFilters) { - this.numNoopFilters = numNoopFilters; - } - - public List<List<TimestampObject>> getTimestampObjectsList() { - return this.timestampObjectsList; - } - - public int getNumWorkerThreads() { - return this.numWorkerThreads; - } - - public void setNumWorkerThreads(final int numWorkerThreads) { - this.numWorkerThreads = numWorkerThreads; - } - -} diff --git a/src/performancetest/java/teetime/examples/loopStage/Countdown.java b/src/performancetest/java/teetime/examples/loopStage/Countdown.java deleted file mode 100644 index f70e3eb60a80eadb286bd2c78095040b26ccd2ed..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/loopStage/Countdown.java +++ /dev/null @@ -1,44 +0,0 @@ -package teetime.examples.loopStage; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.ProducerStage; - -public class Countdown extends ProducerStage<Void> { - - private final InputPort<Integer> countdownInputPort = this.createInputPort(); - - private final OutputPort<Integer> newCountdownOutputPort = this.createOutputPort(); - - private final Integer initialCountdown; - - public Countdown(final Integer initialCountdown) { - this.initialCountdown = initialCountdown; - } - - @Override - public void onStarting() { - this.countdownInputPort.getPipe().add(this.initialCountdown); - super.onStarting(); - } - - @Override - protected void execute() { - Integer countdown = this.countdownInputPort.receive(); - if (countdown == 0) { - this.send(this.outputPort, null); - this.terminate(); - } else { - this.send(this.newCountdownOutputPort, --countdown); - } - } - - public InputPort<Integer> getCountdownInputPort() { - return this.countdownInputPort; - } - - public OutputPort<Integer> getNewCountdownOutputPort() { - return this.newCountdownOutputPort; - } - -} diff --git a/src/performancetest/java/teetime/examples/loopStage/FiniteSignalPassingTest.java b/src/performancetest/java/teetime/examples/loopStage/FiniteSignalPassingTest.java deleted file mode 100644 index ffcef1df21063d6bac47c197222e4632d000c316..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/loopStage/FiniteSignalPassingTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package teetime.examples.loopStage; - -import static org.junit.Assert.assertEquals; - -import java.util.Collection; - -import org.junit.Test; - -import teetime.framework.Analysis; -import teetime.util.Pair; - -public class FiniteSignalPassingTest { - - @Test(timeout = 5000) - // may not run infinitely, so we set an arbitrary timeout that is high enough - public void testStartSignalDoesNotEndUpInInfiniteLoop() throws Exception { - LoopStageAnalysisConfiguration configuration = new LoopStageAnalysisConfiguration(); - Analysis analysis = new Analysis(configuration); - analysis.init(); - Collection<Pair<Thread, Throwable>> exceptions = analysis.start(); - - assertEquals(0, exceptions.size()); - } -} diff --git a/src/performancetest/java/teetime/examples/loopStage/LoopStageAnalysisConfiguration.java b/src/performancetest/java/teetime/examples/loopStage/LoopStageAnalysisConfiguration.java deleted file mode 100644 index 400c4cd406fafb5b6dbd2f1f0095b08d1a2d02cf..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/examples/loopStage/LoopStageAnalysisConfiguration.java +++ /dev/null @@ -1,18 +0,0 @@ -package teetime.examples.loopStage; - -import teetime.framework.AnalysisConfiguration; -import teetime.framework.pipe.IPipeFactory; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; - -public class LoopStageAnalysisConfiguration extends AnalysisConfiguration { - - public LoopStageAnalysisConfiguration() { - Countdown countdown = new Countdown(10); - - IPipeFactory factory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.QUEUE_BASED, true); - factory.create(countdown.getNewCountdownOutputPort(), countdown.getCountdownInputPort()); - - this.getFiniteProducerStages().add(countdown); - } -} diff --git a/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java b/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java deleted file mode 100644 index 6b92dbf3c49e4bb7de1b08fc7a0ee7e1570463f9..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/runtime/typeCheck/ConnectionTypeTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package teetime.runtime.typeCheck; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import org.junit.Test; - -import teetime.framework.pipe.IPipeFactory; -import teetime.framework.pipe.PipeFactoryRegistry; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -import teetime.stage.ObjectProducer; -import teetime.stage.PortTypeConfiguration; -import teetime.stage.StartTimestampFilter; -import teetime.stage.StopTimestampFilter; -import teetime.stage.basic.Sink; -import teetime.util.ConstructorClosure; -import teetime.util.TimestampObject; - -public class ConnectionTypeTest { - - private final PipeFactoryRegistry pipeFactory = PipeFactoryRegistry.INSTANCE; - - // tests for load-time validation - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void testDynamicPortConnection() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, ClassNotFoundException { - ConstructorClosure<TimestampObject> constructorClosure = new ConstructorClosure<TimestampObject>() { - @Override - public TimestampObject create() { - return new TimestampObject(); - } - - }; - - Constructor<ObjectProducer> constructor = ObjectProducer.class.getConstructor(long.class, ConstructorClosure.class); - - ObjectProducer objectProducer = constructor.newInstance(1, constructorClosure); - // PortTypeConfiguration.setPortTypes(objectProducer, Class.forName("teetime.variant.explicitScheduling.examples.throughput.TimestampObject")); - - StartTimestampFilter startTimestampFilter = StartTimestampFilter.class.newInstance(); - StopTimestampFilter stopTimestampFilter = StopTimestampFilter.class.newInstance(); - Sink sink = Sink.class.newInstance(); - - IPipeFactory factory = this.pipeFactory.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.QUEUE_BASED, true); - factory.create(objectProducer.getOutputPort(), startTimestampFilter.getInputPort()); - factory.create(startTimestampFilter.getOutputPort(), stopTimestampFilter.getInputPort()); - factory.create(stopTimestampFilter.getOutputPort(), sink.getInputPort()); - - // TypeVariable<Class<ObjectProducer>>[] objectProducerTypeParameters = ObjectProducer.class.getTypeParameters(); - // for (TypeVariable<Class<ObjectProducer>> typeVariable : objectProducerTypeParameters) { - // System.out.println(typeVariable.getBounds()); // ->[Ljava.lang.reflect.Type;@13a65d1f - // System.out.println(typeVariable.getBounds().length); // ->1 - // System.out.println(typeVariable.getBounds()[0]); // ->class java.lang.Object - // System.out.println(typeVariable.getName()); // ->T - // System.out.println(typeVariable.getClass()); // ->class sun.reflect.generics.reflectiveObjects.TypeVariableImpl - // System.out.println(typeVariable.getGenericDeclaration()); // ->class teetime.stage.ObjectProducer - // } - // - // Class<?> currentClass = objectProducer.getClass(); - // while (currentClass.getSuperclass() != null) { // we don't want to process Object.class - // Field[] fields = currentClass.getDeclaredFields(); - // for (Field field : fields) { - // // System.out.println("Field: " + field.getType()); - // if (OutputPort.class.equals(field.getType())) { - // System.out.println("Field.name: " + field.getName()); - // System.out.println("Field.type: " + field.getType()); - // // field.getType() - // } - // } - // - // currentClass = currentClass.getSuperclass(); - // } - - assertNull(objectProducer.getOutputPort().getType()); - PortTypeConfiguration.setPortTypes(objectProducer, Class.forName(TimestampObject.class.getName())); - assertEquals(TimestampObject.class, objectProducer.getOutputPort().getType()); - - assertNull(startTimestampFilter.getOutputPort().getType()); - PortTypeConfiguration.setPortTypes(startTimestampFilter); - assertEquals(TimestampObject.class, startTimestampFilter.getInputPort().getType()); - assertEquals(TimestampObject.class, startTimestampFilter.getOutputPort().getType()); - } -} diff --git a/src/performancetest/java/teetime/util/CircularCollectionsTest.java b/src/performancetest/java/teetime/util/CircularCollectionsTest.java deleted file mode 100644 index f58607b8a728ba13d0238c8682c38854f2f8debf..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/CircularCollectionsTest.java +++ /dev/null @@ -1,161 +0,0 @@ -package teetime.util; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; -import org.junit.runners.MethodSorters; - -import teetime.util.concurrent.workstealing.CircularArray; -import teetime.util.concurrent.workstealing.CircularIntArray; -import teetime.util.concurrent.workstealing.CircularModIntArray; -import teetime.util.list.CircularList; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class CircularCollectionsTest { - - private static final int NUM_OBJECTS_TO_CREATE_IN_POW2 = 2; - private static final int NUM_OBJECTS_TO_CREATE = (int) Math.pow(2, NUM_OBJECTS_TO_CREATE_IN_POW2); - private static final int NUM_ACCESSES = 100000000; - private static final int WARMUP_ITERATIONS = 3; - - private static final Map<String, Long> durations = new LinkedHashMap<String, Long>(); - - private StopWatch stopWatch; - protected Description description; - - @Before - public void setup() { - this.stopWatch = new StopWatch(); - } - - @Rule - public final TestRule watcher = new TestWatcher() { - @Override - protected void starting(final Description description) { - CircularCollectionsTest.this.description = description; - } - }; - - @After - public void tearDown() { - CircularCollectionsTest.durations.put(this.description.getDisplayName(), this.stopWatch.getDurationInNs()); - } - - @Test - public void testCircularIntArray() throws Exception { - CircularIntArray<Object> circularArray = new CircularIntArray<Object>(NUM_OBJECTS_TO_CREATE_IN_POW2); - for (int i = 0; i < NUM_OBJECTS_TO_CREATE; i++) { - circularArray.put(i, new Object()); - } - - int warmupIterations = WARMUP_ITERATIONS; - while (warmupIterations-- > 0) { - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - } - - this.stopWatch.start(); - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - this.stopWatch.end(); - } - - @Test - public void testCircularModIntArray() throws Exception { - CircularModIntArray<Object> circularArray = new CircularModIntArray<Object>(NUM_OBJECTS_TO_CREATE_IN_POW2); - for (int i = 0; i < NUM_OBJECTS_TO_CREATE; i++) { - circularArray.put(i, new Object()); - } - - int warmupIterations = WARMUP_ITERATIONS; - while (warmupIterations-- > 0) { - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - } - - this.stopWatch.start(); - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - this.stopWatch.end(); - } - - @Test - public void testCircularList() throws Exception { - CircularList<Object> circularList = new CircularList<Object>(); - for (int i = 0; i < NUM_OBJECTS_TO_CREATE; i++) { - circularList.add(new Object()); - } - - int warmupIterations = WARMUP_ITERATIONS; - while (warmupIterations-- > 0) { - for (int i = 0; i < NUM_ACCESSES; i++) { - circularList.getNext().toString(); - } - } - - this.stopWatch.start(); - for (int i = 0; i < NUM_ACCESSES; i++) { - circularList.getNext().toString(); - } - this.stopWatch.end(); - } - - @Test - public void testCircularLongArray() throws Exception { - CircularArray<Object> circularArray = new CircularArray<Object>(NUM_OBJECTS_TO_CREATE_IN_POW2); - for (int i = 0; i < NUM_OBJECTS_TO_CREATE; i++) { - circularArray.put(i, new Object()); - } - - int warmupIterations = WARMUP_ITERATIONS; - while (warmupIterations-- > 0) { - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - } - - this.stopWatch.start(); - for (int i = 0; i < NUM_ACCESSES; i++) { - circularArray.getNext().toString(); - } - this.stopWatch.end(); - } - - @AfterClass - public static void afterClass() { - Long circularIntArrayInNs = durations.get("testCircularIntArray(teetime.util.CircularCollectionsTest)"); - Long circularModIntArrayInNs = durations.get("testCircularModIntArray(teetime.util.CircularCollectionsTest)"); - Long circularListInNs = durations.get("testCircularList(teetime.util.CircularCollectionsTest)"); - Long circularLongArrayInNs = durations.get("testCircularLongArray(teetime.util.CircularCollectionsTest)"); - - for (Entry<String, Long> entry : durations.entrySet()) { - System.out.println(entry.getKey() + ": " + TimeUnit.NANOSECONDS.toMillis(entry.getValue()) + " ms"); - } - - assertThat(circularListInNs, is(lessThan(circularModIntArrayInNs))); - - // testCircularIntArray(teetime.util.CircularCollectionsTest): 13202 ms - // testCircularList(teetime.util.CircularCollectionsTest): 13957 ms - // testCircularLongArray(teetime.util.CircularCollectionsTest): 12620 ms - // testCircularModIntArray(teetime.util.CircularCollectionsTest): 14015 ms - } -} diff --git a/src/performancetest/java/teetime/util/StopWatchTest.java b/src/performancetest/java/teetime/util/StopWatchTest.java deleted file mode 100644 index 5c0a6a0d721e27e2c44694115ce2b40576e27ec3..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/StopWatchTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package teetime.util; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.junit.Test; - -import util.test.StatisticsUtil; - -public class StopWatchTest { - - private static final int NUM_ITERATIONS = 1000000; - - @Test - public void testNanotime() throws Exception { - StopWatch iterationStopWatch = new StopWatch(); - - List<Long> durationsInNs = new ArrayList<Long>(NUM_ITERATIONS); - for (int i = 0; i < NUM_ITERATIONS; i++) { - iterationStopWatch.start(); - fib(BigInteger.valueOf(10l)); - iterationStopWatch.end(); - durationsInNs.add(iterationStopWatch.getDurationInNs()); - } - - Map<Double, Long> quintiles = StatisticsUtil.calculateQuintiles(durationsInNs); - StatisticsUtil.getQuantilesString(quintiles); - } - - public static BigInteger fib(final BigInteger n) { - if (n.compareTo(BigInteger.ONE) == -1 || n.compareTo(BigInteger.ONE) == 0) { - return n; - } else { - return fib(n.subtract(BigInteger.ONE)).add(fib(n.subtract(BigInteger.ONE).subtract(BigInteger.ONE))); - } - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/CircularWorkStealingDequeTest.java b/src/performancetest/java/teetime/util/concurrent/CircularWorkStealingDequeTest.java deleted file mode 100644 index c62ced60bdd1ea730c436684976588bbce2009d8..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/CircularWorkStealingDequeTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package teetime.util.concurrent; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; -import teetime.util.concurrent.workstealing.CircularWorkStealingDeque; -import teetime.util.concurrent.workstealing.alternative.UntypedCircularWorkStealingDequeTest; - -public class CircularWorkStealingDequeTest { - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final CircularWorkStealingDeque<Object> deque = new CircularWorkStealingDeque<Object>(); - - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - deque.popBottom(); - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), - OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeTest.java deleted file mode 100644 index 4ed31d09b68ce915c12eb6c10e4d18109033172e..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; -import teetime.util.concurrent.workstealing.CircularWorkStealingDeque; - -public class CircularWorkStealingDequeTest { - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final CircularWorkStealingDeque<Object> deque = new CircularWorkStealingDeque<Object>(); - - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - deque.popBottom(); - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinelTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinelTest.java deleted file mode 100644 index 401c160673503e1e613b93ad9367238829e42517..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinelTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; - -public class CircularWorkStealingDequeWithSentinelTest { - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final CircularWorkStealingDequeWithSentinel<Object> deque = new CircularWorkStealingDequeWithSentinel<Object>(); - - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - deque.popBottom(); - // if (returnValue.getState() != State.EMPTY) { - // returnValue.getValue(); - // } - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinelTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinelTest.java deleted file mode 100644 index 42555e679a686e3b9a4f56bdba506f24c2962e51..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinelTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; - -public class CircularWorkStealingDequeWithThreadLocalSentinelTest { - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final CircularWorkStealingDequeWithThreadLocalSentinel<Object> deque = new CircularWorkStealingDequeWithThreadLocalSentinel<Object>(); - - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - deque.popBottom(); - // if (returnValue.getState() != State.EMPTY) { - // returnValue.getValue(); - // } - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDequeTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDequeTest.java deleted file mode 100644 index 21858b035af37dc26059cb6b4eb4d44d868aafa3..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDequeTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import teetime.util.StopWatch; -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; - -@Ignore -public class ExceptionalCircularWorkStealingDequeTest { - - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final ExceptionalCircularWorkStealingDeque<String> deque = new ExceptionalCircularWorkStealingDeque<String>(); - - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - try { - deque.popBottom(); - } catch (final DequeIsEmptyException e) { - // do not handle; we just want to compare the performance of throwing a preallocated exception vs. returning special values - } - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDequeTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDequeTest.java deleted file mode 100644 index aedc786b3a1190fbf54c5f6f6c67725d8b8ae5d2..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDequeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; - -public class UntypedCircularWorkStealingDequeTest { - - public static final int NUM_ITERATIONS = 100000000; - public static final long EXPECTED_DURATION_IN_NS = 1100*1000*1000; - - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final UntypedCircularWorkStealingDeque deque = new UntypedCircularWorkStealingDeque(); - - final int numIterations = NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - deque.popBottom(); - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - } -} diff --git a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDequeTest.java b/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDequeTest.java deleted file mode 100644 index 8ed614d13d0e31cf3558577a770906dc869bc24a..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDequeTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package teetime.util.concurrent.workstealing.alternative; - -import org.hamcrest.number.OrderingComparison; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import teetime.util.StopWatch; -import teetime.util.concurrent.workstealing.exception.DequeIsEmptyException; - -public class UntypedExceptionalCircularWorkStealingDequeTest { - - private StopWatch stopWatch; - - @Before - public void before() { - this.stopWatch = new StopWatch(); - } - - @Test - public void measureManyEmptyPulls() { - final UntypedExceptionalCircularWorkStealingDeque deque = new UntypedExceptionalCircularWorkStealingDeque(); - System.out.println(UntypedExceptionalCircularWorkStealingDeque.DEQUE_IS_EMPTY_EXCEPTION); - System.out.println(UntypedExceptionalCircularWorkStealingDeque.OPERATION_ABORTED_EXCEPTION); - - int counter = 0; - final int numIterations = UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS; - this.stopWatch.start(); - for (int i = 0; i < numIterations; i++) { - try { - deque.popBottom(); - } catch (final DequeIsEmptyException e) { - // do not handle; we just want to compare the performance of throwing a preallocated exception vs. returning special values - counter++; - } - } - this.stopWatch.end(); - - Assert.assertThat(this.stopWatch.getDurationInNs(), OrderingComparison.lessThan(UntypedCircularWorkStealingDequeTest.EXPECTED_DURATION_IN_NS)); - Assert.assertThat(counter, OrderingComparison.comparesEqualTo(UntypedCircularWorkStealingDequeTest.NUM_ITERATIONS)); - } -} diff --git a/src/performancetest/java/teetime/util/list/CommittableResizableArrayQueueTest.java b/src/performancetest/java/teetime/util/list/CommittableResizableArrayQueueTest.java deleted file mode 100644 index d78fd1828676b9755292713a5dccbdeeedbb21aa..0000000000000000000000000000000000000000 --- a/src/performancetest/java/teetime/util/list/CommittableResizableArrayQueueTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package teetime.util.list; - -import org.junit.Assert; -import org.junit.Test; - -public class CommittableResizableArrayQueueTest { - - @Test - public void testCommit() throws Exception { - CommittableResizableArrayQueue<Object> reservableArrayList = new CommittableResizableArrayQueue<Object>(null, 10); - Object element = new Object(); - reservableArrayList.addToTailUncommitted(element); - - Assert.assertTrue(reservableArrayList.isEmpty()); - - reservableArrayList.commit(); - - Assert.assertFalse(reservableArrayList.isEmpty()); - Assert.assertEquals(element, reservableArrayList.getTail()); - } - - @Test - public void testRollback() throws Exception { - CommittableResizableArrayQueue<Object> reservableArrayList = new CommittableResizableArrayQueue<Object>(null, 10); - Object element = new Object(); - reservableArrayList.addToTailUncommitted(element); - - Assert.assertTrue(reservableArrayList.isEmpty()); - - reservableArrayList.rollback(); - - Assert.assertTrue(reservableArrayList.isEmpty()); - // Assert.assertEquals(element, reservableArrayList.getLast()); - } - - @Test - public void testRemove() throws Exception { - CommittableResizableArrayQueue<Object> reservableArrayList = new CommittableResizableArrayQueue<Object>(null, 10); - Object element = new Object(); - reservableArrayList.addToTailUncommitted(element); - reservableArrayList.commit(); - - Assert.assertEquals(element, reservableArrayList.removeFromHeadUncommitted()); - Assert.assertFalse(reservableArrayList.isEmpty()); - - reservableArrayList.commit(); - - Assert.assertTrue(reservableArrayList.isEmpty()); - } -} diff --git a/src/test/java/teetime/examples/cipher/CipherConfiguration.java b/src/test/java/teetime/examples/cipher/CipherConfiguration.java deleted file mode 100644 index 5b036d173a0cf6ae0f0a14e3a5d283ebfdc2b8bc..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/examples/cipher/CipherConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -package teetime.examples.cipher; - -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.CipherByteArray; -import teetime.stage.CipherByteArray.CipherMode; -import teetime.stage.InitialElementProducer; -import teetime.stage.ZipByteArray; -import teetime.stage.ZipByteArray.ZipMode; -import teetime.stage.io.ByteArrayFileWriter; -import teetime.stage.io.File2ByteArray; - -public class CipherConfiguration extends AnalysisConfiguration { - - public CipherConfiguration(final String inputFile, final String outputFile, final String password) { - final File input = new File(inputFile); - final File output = new File(outputFile); - - InitialElementProducer<File> init = new InitialElementProducer<File>(input); - File2ByteArray f2b = new File2ByteArray(); - CipherByteArray enc = new CipherByteArray(password, CipherMode.ENCRYPT); - ZipByteArray comp = new ZipByteArray(ZipMode.COMP); - ZipByteArray decomp = new ZipByteArray(ZipMode.DECOMP); - CipherByteArray decrypt = new CipherByteArray(password, CipherMode.DECRYPT); - ByteArrayFileWriter writer = new ByteArrayFileWriter(output); - - 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()); - - this.getFiniteProducerStages().add(init); - - } -} diff --git a/src/test/java/teetime/examples/cipher/CipherTest.java b/src/test/java/teetime/examples/cipher/CipherTest.java deleted file mode 100644 index 20f54007e82672660f37776bedf7c9cfe9c72e67..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/examples/cipher/CipherTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package teetime.examples.cipher; - -import java.io.File; -import java.io.IOException; - -import org.junit.Assert; -import org.junit.Test; - -import teetime.framework.Analysis; -import teetime.framework.AnalysisConfiguration; - -import com.google.common.io.Files; - -/** - * Executes stages which modify the given file and compares the results - * Procedure: read > compress > encrypt > decrypt > decompress > write - * - * @author Nelson Tavares de Sousa - * - */ -public class CipherTest { - - @Test - public void executeTest() throws IOException { - final String inputFile = "src/test/resources/data/input.txt"; - final String outputFile = "src/test/resources/data/output.txt"; - final String password = "Password"; - - AnalysisConfiguration configuration = new CipherConfiguration(inputFile, outputFile, password); - Analysis analysis = new Analysis(configuration); - analysis.init(); - analysis.start(); - - Assert.assertTrue(Files.equal(new File(inputFile), new File(outputFile))); - } - -} diff --git a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java b/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java deleted file mode 100644 index 202843b4a90a53f869805523c537e798f04729ae..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/examples/tokenizer/TokenizerConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -package teetime.examples.tokenizer; - -import java.io.File; - -import teetime.framework.AnalysisConfiguration; -import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; -import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; -import teetime.stage.ByteArray2String; -import teetime.stage.CipherByteArray; -import teetime.stage.CipherByteArray.CipherMode; -import teetime.stage.Counter; -import teetime.stage.InitialElementProducer; -import teetime.stage.Tokenizer; -import teetime.stage.ZipByteArray; -import teetime.stage.ZipByteArray.ZipMode; -import teetime.stage.io.File2ByteArray; - -public class TokenizerConfiguration extends AnalysisConfiguration { - - private final Counter<String> counter; - - public TokenizerConfiguration(final String inputFile, final String password) { - final File input = new File(inputFile); - - InitialElementProducer<File> init = new InitialElementProducer<File>(input); - File2ByteArray f2b = new File2ByteArray(); - ZipByteArray decomp = new ZipByteArray(ZipMode.DECOMP); - CipherByteArray decrypt = new CipherByteArray(password, CipherMode.DECRYPT); - ByteArray2String b2s = new ByteArray2String(); - Tokenizer tokenizer = new Tokenizer(" "); - counter = new Counter<String>(); - - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - init.getOutputPort(), f2b.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - f2b.getOutputPort(), decomp.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - decomp.getOutputPort(), decrypt.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - decrypt.getOutputPort(), b2s.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - b2s.getOutputPort(), tokenizer.getInputPort()); - PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false).create( - tokenizer.getOutputPort(), counter.getInputPort()); - - this.getFiniteProducerStages().add(init); - } - - public int getTokenCount() { - return this.counter.getNumElementsPassed(); - } - -} diff --git a/src/test/java/teetime/examples/tokenizer/TokenizerTest.java b/src/test/java/teetime/examples/tokenizer/TokenizerTest.java deleted file mode 100644 index 2a9b2ac94fc8cdf04c4d62f0471cf733fe4c5d39..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/examples/tokenizer/TokenizerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package teetime.examples.tokenizer; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; - -import org.junit.Assert; -import org.junit.Test; - -import teetime.framework.Analysis; - -import com.google.common.io.Files; - -/** - * Reads in a compressed and encrypted file and counts the containing words - * - * @author Nelson Tavares de Sousa - * - */ -public class TokenizerTest { - - @Test - public void executeTest() throws IOException { - // Encrypted lorem ipsum - String inputFile = "src/test/resources/data/cipherInput.txt"; - String password = "Password"; - - TokenizerConfiguration configuration = new TokenizerConfiguration(inputFile, password); - Analysis analysis = new Analysis(configuration); - analysis.init(); - analysis.start(); - - String string = Files.toString(new File("src/test/resources/data/input.txt"), Charset.forName("UTF-8")); - - Assert.assertEquals(string.split(" ").length, configuration.getTokenCount()); - } - -} diff --git a/src/test/java/teetime/framework/pipe/SpScPipeTest.java b/src/test/java/teetime/framework/pipe/SpScPipeTest.java deleted file mode 100644 index 1a937afc2b63f77a2cb4fc36398d69e774566b97..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/framework/pipe/SpScPipeTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package teetime.framework.pipe; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -import teetime.framework.InputPort; -import teetime.framework.OutputPort; -import teetime.framework.signal.ISignal; -import teetime.framework.signal.StartingSignal; -import teetime.framework.signal.TerminatingSignal; -import teetime.framework.signal.ValidatingSignal; - -public class SpScPipeTest { - - @Test - public void testSignalOrdering() throws Exception { - OutputPort<? extends Object> sourcePort = null; - InputPort<Object> targetPort = null; - InterThreadPipe pipe = new SpScPipe(sourcePort, targetPort, 1); // IPipe does not provide getSignal method - - List<ISignal> list = new ArrayList<ISignal>(); - list.add(new StartingSignal()); - list.add(new TerminatingSignal()); - list.add(new ValidatingSignal()); - list.add(new StartingSignal()); - list.add(new TerminatingSignal()); - list.add(new ValidatingSignal()); - list.add(new StartingSignal()); - list.add(new TerminatingSignal()); - list.add(new ValidatingSignal()); - - for (ISignal s : list) { - pipe.sendSignal(s); - } - - List<ISignal> secondList = new ArrayList<ISignal>(); - while (true) { - ISignal temp = pipe.getSignal(); - if (temp == null) { - break; - } - secondList.add(temp); - } - Assert.assertEquals(list, secondList); - } -}