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

added pipe factory concept

parent a08622dd
No related branches found
No related tags found
No related merge requests found
<?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>
package teetime.variant.methodcallWithPorts.framework.core.pipe;
public interface IPipeFactory {
<T> IPipe<T> create(int capacity);
}
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);
}
}
......@@ -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
......
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment