diff --git a/src/main/java/teetime/framework/AbstractPort.java b/src/main/java/teetime/framework/AbstractPort.java index 0725cbe873fce302ffdcb462df3c28d7506ebb69..0544c4798cdfcdb500f88db3cb974f73db506a3f 100644 --- a/src/main/java/teetime/framework/AbstractPort.java +++ b/src/main/java/teetime/framework/AbstractPort.java @@ -19,6 +19,8 @@ import teetime.framework.pipe.IPipe; public abstract class AbstractPort<T> { + private final String portName; + protected IPipe pipe; /** * The type of this port. @@ -29,8 +31,9 @@ public abstract class AbstractPort<T> { protected final Class<T> type; private final Stage owningStage; - public AbstractPort(final Class<T> type, final Stage owningStage) { + public AbstractPort(final Class<T> type, final Stage owningStage, final String portName) { super(); + this.portName = portName; this.type = type; this.owningStage = owningStage; } @@ -50,4 +53,13 @@ public abstract class AbstractPort<T> { public final Stage getOwningStage() { return owningStage; } + + @Override + public final String toString() { + if (portName == null) { + return super.toString(); + } else { + return portName; + } + } } diff --git a/src/main/java/teetime/framework/AbstractStage.java b/src/main/java/teetime/framework/AbstractStage.java index a880c185bf8c97665ea29c9756c369de0a37ee23..7d3c023f603c3eba0a3a8cc9d2d94cc0565bf30e 100644 --- a/src/main/java/teetime/framework/AbstractStage.java +++ b/src/main/java/teetime/framework/AbstractStage.java @@ -141,7 +141,7 @@ public abstract class AbstractStage extends Stage { @SuppressWarnings("unchecked") // @Deprecated protected <T> InputPort<T> createInputPort() { - return (InputPort<T>) createInputPort(null); + return (InputPort<T>) createInputPort(null, null); } /** @@ -156,7 +156,41 @@ public abstract class AbstractStage extends Stage { * @return Newly added InputPort */ protected <T> InputPort<T> createInputPort(final Class<T> type) { - final InputPort<T> inputPort = new InputPort<T>(type, this); + return createInputPort(type, null); + } + + /** + * Creates and adds an InputPort to the stage + * + * @param name + * a specific name for the new port + * @param <T> + * the type of elements to be received + * + * @return Newly added InputPort + * + */ + // * @deprecated Since 1.1. Use {@link #createInputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated + protected <T> InputPort<T> createInputPort(final String name) { + return (InputPort<T>) createInputPort(null, name); + } + + /** + * Creates and adds an InputPort to the stage + * + * @param type + * class of elements to be received + * @param name + * a specific name for the new port + * @param <T> + * the type of elements to be received + * + * @return Newly added InputPort + */ + protected <T> InputPort<T> createInputPort(final Class<T> type, final String name) { + final InputPort<T> inputPort = new InputPort<T>(type, this, name); inputPorts = addElementToArray(inputPort, inputPorts); return inputPort; } @@ -174,7 +208,7 @@ public abstract class AbstractStage extends Stage { @SuppressWarnings("unchecked") // @Deprecated protected <T> OutputPort<T> createOutputPort() { - return (OutputPort<T>) createOutputPort(null); + return (OutputPort<T>) createOutputPort(null, null); } /** @@ -189,7 +223,45 @@ public abstract class AbstractStage extends Stage { * @return Newly added OutputPort */ protected <T> OutputPort<T> createOutputPort(final Class<T> type) { - final OutputPort<T> outputPort = new OutputPort<T>(type, this); + final OutputPort<T> outputPort = new OutputPort<T>(type, this, null); + outputPorts = addElementToArray(outputPort, outputPorts); + return outputPort; + } + + /** + * Creates and adds an OutputPort to the stage + * + * @param name + * a specific name for the new port + * + * @param <T> + * the type of elements to be sent + * + * @return Newly added OutputPort + * + */ + // * @deprecated Since 1.1. Use {@link #createOutputPort(Class)} instead. + @SuppressWarnings("unchecked") + // @Deprecated + protected <T> OutputPort<T> createOutputPort(final String name) { + return (OutputPort<T>) createOutputPort(null, name); + } + + /** + * Creates and adds an OutputPort to the stage + * + * @param name + * a specific name for the new port + * @param type + * class of elements to be sent + * + * @param <T> + * the type of elements to be sent + * + * @return Newly added OutputPort + */ + protected <T> OutputPort<T> createOutputPort(final Class<T> type, final String name) { + final OutputPort<T> outputPort = new OutputPort<T>(type, this, name); outputPorts = addElementToArray(outputPort, outputPorts); return outputPort; } diff --git a/src/main/java/teetime/framework/InputPort.java b/src/main/java/teetime/framework/InputPort.java index d2ffc2590495409e7fac4371e556b088f98ba80e..bc71a2ebd0c089bd14140005c1309af83a75ac52 100644 --- a/src/main/java/teetime/framework/InputPort.java +++ b/src/main/java/teetime/framework/InputPort.java @@ -26,8 +26,8 @@ package teetime.framework; */ public final class InputPort<T> extends AbstractPort<T> { - InputPort(final Class<T> type, final Stage owningStage) { - super(type, owningStage); + InputPort(final Class<T> type, final Stage owningStage, final String portName) { + super(type, owningStage, portName); } /** diff --git a/src/main/java/teetime/framework/OutputPort.java b/src/main/java/teetime/framework/OutputPort.java index 4d23baaad7a2030dd3bbe361f8161b8bb63dca65..103402d2953aac5db2d28f61433c0e63c6272cde 100644 --- a/src/main/java/teetime/framework/OutputPort.java +++ b/src/main/java/teetime/framework/OutputPort.java @@ -29,8 +29,8 @@ import teetime.framework.signal.TerminatingSignal; */ public final class OutputPort<T> extends AbstractPort<T> { - OutputPort(final Class<T> type, final Stage owningStage) { - super(type, owningStage); + OutputPort(final Class<T> type, final Stage owningStage, final String portName) { + super(type, owningStage, portName); } /**