diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..578da31dee62dccaca8dd4f17da10a45723c6d9b --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.teetime</groupId> + <artifactId>teetime</artifactId> + <name>teetime</name> + <version>1.0-SNAPSHOT</version> + <url>http://maven.apache.org</url> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>versions-maven-plugin</artifactId> + <version>2.1</version> + </plugin> + <plugin> + <artifactId>maven-shade-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + </execution> + </executions> + <configuration> + <finalName>${project.artifactId}-${project.version}</finalName> + </configuration> + </plugin> + </plugins> + </build> + <repositories> + <repository> + <id>sonatype.oss.snapshots</id> + <url>https://oss.sonatype.org/content/repositories/snapshots/</url> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> +</project> + diff --git a/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/IPipeFactory.java b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/IPipeFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..b6dbc5f9ddb4be13fe4d46688c383ae60a57f9e3 --- /dev/null +++ b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/IPipeFactory.java @@ -0,0 +1,6 @@ +package teetime.variant.methodcallWithPorts.framework.core.pipe; + +public interface IPipeFactory { + + <T> IPipe<T> create(int capacity); +} diff --git a/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/PipeFactory.java b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/PipeFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..5534a69dc2a30ae110ad28e593f97b7d7e8ec84e --- /dev/null +++ b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/PipeFactory.java @@ -0,0 +1,51 @@ +package teetime.variant.methodcallWithPorts.framework.core.pipe; + +import java.util.HashMap; +import java.util.Map; + +public class PipeFactory { + + public enum ThreadCommunication { + INTER, INTRA + } + + public enum Ordering { + /** + * FIFO + */ + QUEUE_BASED, + /** + * LIFO + */ + STACK_BASED, + ARBITRARY + } + + private final Map<String, IPipeFactory> pipeFactories = new HashMap<String, IPipeFactory>(); + + /** + * Creates a new FIFO-ordered, growable pipe with an initial capacity of 1. <br> + * <i>This method is suitable for most programmers.</i> + * + * @param tc + * @return + */ + public <T> IPipe<T> create(final ThreadCommunication tc) { + return this.create(tc, Ordering.QUEUE_BASED, true, 1); + } + + public <T> IPipe<T> create(final ThreadCommunication tc, final Ordering ordering, final boolean growable, final int capacity) { + String key = this.buildKey(tc, ordering, growable); + IPipeFactory pipeClass = this.pipeFactories.get(key); + return pipeClass.create(capacity); + } + + private String buildKey(final ThreadCommunication tc, final Ordering ordering, final boolean growable) { + return tc.toString() + ordering.toString() + growable; + } + + public void register(final IPipeFactory pipeFactory, final ThreadCommunication tc, final Ordering ordering, final boolean growable) { + String key = this.buildKey(tc, ordering, growable); + this.pipeFactories.put(key, pipeFactory); + } +} diff --git a/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipe.java b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipe.java index 58dc26fcaac439d3cf4a828a374f322d5a45aec0..1c8994ccabc76c6cab9212f73cc5a4004a89303a 100644 --- a/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipe.java +++ b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipe.java @@ -26,10 +26,14 @@ public class SpScPipe<T> extends AbstractPipe<T> { public static <T> SpScPipe<T> connect(final OutputPort<T> sourcePort, final InputPort<T> targetPort, final int capacity) { SpScPipe<T> pipe = new SpScPipe<T>(capacity); - targetPort.setPipe(pipe); - sourcePort.setPipe(pipe); + return pipe.connect(sourcePort, targetPort); + } + + public SpScPipe<T> connect(final OutputPort<T> sourcePort, final InputPort<T> targetPort) { + targetPort.setPipe(this); + sourcePort.setPipe(this); sourcePort.setCachedTargetStage(targetPort.getOwningStage()); - return pipe; + return this; } @Override diff --git a/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipeFactory.java b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipeFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..745823c1576dbbff09e2c37adfa456abeb7a21e2 --- /dev/null +++ b/src/main/java/teetime/variant/methodcallWithPorts/framework/core/pipe/SpScPipeFactory.java @@ -0,0 +1,10 @@ +package teetime.variant.methodcallWithPorts.framework.core.pipe; + +public class SpScPipeFactory implements IPipeFactory { + + @Override + public <T> IPipe<T> create(final int capacity) { + return new SpScPipe<T>(capacity); + } + +}