From b6de7545d40618dd3b117ac3e9ade0de75b305d7 Mon Sep 17 00:00:00 2001
From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de>
Date: Fri, 2 Oct 2015 15:23:13 +0200
Subject: [PATCH] introduces error codes

---
 src/changes/changes.xml                       | 57 +++++++++++++------
 .../A2InvalidThreadAssignmentCheck.java       |  3 +-
 .../framework/AbstractCompositeStage.java     |  7 +++
 .../framework/AbstractInterThreadPipe.java    |  3 +-
 .../java/teetime/framework/Execution.java     |  4 +-
 .../teetime/framework/ExecutionException.java |  2 +-
 .../framework/ExecutionInstantiation.java     |  3 +-
 .../framework/NotEnoughInputException.java    |  2 +-
 .../java/teetime/framework/ThreadService.java |  2 +-
 9 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 07a37d1e..fd900991 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -5,31 +5,43 @@
 		<title>Release Notes</title>
 	</properties>
 	<body>
+		<release version="2.1-SNAPSHOT" description="Nightly builds">
+			<action dev="ntd" type="add" issue="163">
+				Introduced error codes.
+			</action>
+		</release>
 		<release version="2.0" date="30.09.2015" description="Camellia Release">
 			<action dev="ntd" type="add" issue="93">
-				New concept: composite stages.
+				New concept: composite
+				stages.
 			</action>
 			<action dev="ntd" type="add" issue="33">
-				New concept: TeeTime automatically
+				New concept: TeeTime
+				automatically
 				chooses the correct type of pipe for all connections.
 			</action>
 			<action dev="chw" type="add" issue="207">
 				Added capacity to IPipe.
 			</action>
 			<action dev="chw" type="add" issue="197">
-				Added the ability to add ports to a merger at runtime.
+				Added the ability to add
+				ports to a merger at runtime.
 			</action>
 			<action dev="chw" type="add" issue="172">
-				Added the ability to add ports to a distributor at runtime.
+				Added the ability to add
+				ports to a distributor at runtime.
 			</action>
 			<action dev="chw" type="add" issue="183">
-				Threads can be added at runtime.
+				Threads can be added at
+				runtime.
 			</action>
 			<action dev="ntd" type="add" issue="195">
-				Configurations can only be executed once.
+				Configurations can only be
+				executed once.
 			</action>
 			<action dev="ntd" type="add" issue="165">
-				Ports can be named for better debugging.
+				Ports can be named for
+				better debugging.
 			</action>
 			<action dev="ntd" type="add">
 				Stages without any input port are
@@ -38,42 +50,51 @@
 			<action dev="ntd" type="add" issue="171">
 				Configurations are now
 				built within the Configuration class.
-				This removes any constraints on CompositeStages and
-				enables therefore multiple connections and multithreading in such stages.
+				This removes any constraints on
+				CompositeStages and
+				enables therefore multiple connections and
+				multithreading in such stages.
 			</action>
 			<action dev="ntd" type="add" issue="154">
 				All stages will be
 				initialized before starting the analysis.
 			</action>
 			<action dev="ntd" type="add" issue="122">
-				Threads can be named for better debugging.
+				Threads can be named for
+				better debugging.
 			</action>
 			<action dev="ntd" type="add" issue="170">
-				Exceptions within the initialization will now terminate the execution.
+				Exceptions within the
+				initialization will now terminate the execution.
 			</action>
 			<action dev="ntd" type="add" issue="211">
 				Added Services.
-				Any Execution can now be aborted.
+				Any
+				Execution can now be aborted.
 			</action>
-			
+
 			<action dev="ntd" type="update" issue="224">
-				Merged Stage into AbstractStage.
+				Merged Stage into
+				AbstractStage.
 			</action>
 			<action dev="chw" type="update" issue="189">
-				Merger and Distributor strategies are moved to a separate package.
+				Merger and Distributor
+				strategies are moved to a separate package.
 			</action>
 			<action dev="ntd" type="update" issue="185">
 				TerminatingExceptionListener is now the default listener.
 			</action>
 			<action dev="ntd" type="update" issue="174">
-				Removed addThreadableStage and replaced it by AbstractStage.declareActive().
+				Removed
+				addThreadableStage and replaced it by AbstractStage.declareActive().
 			</action>
 			<action dev="ntd" type="update">
 				Renamed Analysis to Execution.
 			</action>
-			
+
 			<action dev="ntd" type="remove" issue="217">
-				Removed InitializingSignal.
+				Removed
+				InitializingSignal.
 			</action>
 			<action dev="ntd" type="remove">
 				Removed pair class.
diff --git a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java
index b49832c4..60e33dae 100644
--- a/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java
+++ b/src/main/java/teetime/framework/A2InvalidThreadAssignmentCheck.java
@@ -82,7 +82,8 @@ public class A2InvalidThreadAssignmentCheck {
 			} else {
 				if (colors.containsKey(targetStage)) {
 					if (colors.get(targetStage) != color) {
-						throw new IllegalStateException("Crossing threads"); // One stage is connected to a stage of another thread (but not its "headstage")
+						throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread
+																												// (but not its "headstage")
 					}
 				}
 				colors.put(targetStage, color);
diff --git a/src/main/java/teetime/framework/AbstractCompositeStage.java b/src/main/java/teetime/framework/AbstractCompositeStage.java
index 5fbae973..db4fa8f5 100644
--- a/src/main/java/teetime/framework/AbstractCompositeStage.java
+++ b/src/main/java/teetime/framework/AbstractCompositeStage.java
@@ -59,6 +59,13 @@ public abstract class AbstractCompositeStage {
 	 *            the type of elements to be sent
 	 */
 	protected <T> void connectPorts(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) {
+		if (sourcePort == null) {
+			throw new IllegalArgumentException("1002 - sourcePort may not be null");
+		}
+		if (targetPort == null) {
+			throw new IllegalArgumentException("1003 - targetPort may not be null");
+		}
+
 		if (sourcePort.getOwningStage().getInputPorts().size() == 0) {
 			if (sourcePort.getOwningStage().getOwningThread() == null) {
 				sourcePort.getOwningStage().declareActive();
diff --git a/src/main/java/teetime/framework/AbstractInterThreadPipe.java b/src/main/java/teetime/framework/AbstractInterThreadPipe.java
index f723c2fe..0592066d 100644
--- a/src/main/java/teetime/framework/AbstractInterThreadPipe.java
+++ b/src/main/java/teetime/framework/AbstractInterThreadPipe.java
@@ -68,7 +68,8 @@ public abstract class AbstractInterThreadPipe<T> extends AbstractPipe<T> {
 	public final void waitForStartSignal() throws InterruptedException {
 		final ISignal signal = signalQueue.take();
 		if (!(signal instanceof StartingSignal)) {
-			throw new IllegalStateException("Expected StartingSignal, but was " + signal.getClass().getSimpleName());
+			throw new IllegalStateException(
+					"2001 - Expected StartingSignal, but was " + signal.getClass().getSimpleName() + " in " + getTargetPort().getOwningStage().getId());
 		}
 		cachedTargetStage.onSignal(signal, getTargetPort());
 	}
diff --git a/src/main/java/teetime/framework/Execution.java b/src/main/java/teetime/framework/Execution.java
index 669fd834..6a746f26 100644
--- a/src/main/java/teetime/framework/Execution.java
+++ b/src/main/java/teetime/framework/Execution.java
@@ -67,7 +67,7 @@ public final class Execution<T extends Configuration> {
 		this.configuration = configuration;
 		this.configurationContext = configuration.getContext();
 		if (configuration.isInitialized()) {
-			throw new IllegalStateException("Configuration was already executed");
+			throw new IllegalStateException("3001 - Configuration has already been used.");
 		}
 		configuration.setInitialized(true);
 		if (validationEnabled) {
@@ -151,7 +151,7 @@ public final class Execution<T extends Configuration> {
 	 */
 	public void executeNonBlocking() {
 		if (configuration.isExecuted()) {
-			throw new IllegalStateException("Any configuration instance may only be executed once.");
+			throw new IllegalStateException("3002 - Any configuration instance may only be executed once.");
 		}
 		configuration.setExecuted(true);
 		configurationContext.executeConfiguration();
diff --git a/src/main/java/teetime/framework/ExecutionException.java b/src/main/java/teetime/framework/ExecutionException.java
index 946ba6cd..71dd418c 100644
--- a/src/main/java/teetime/framework/ExecutionException.java
+++ b/src/main/java/teetime/framework/ExecutionException.java
@@ -31,7 +31,7 @@ public class ExecutionException extends RuntimeException {
 	private final Map<Thread, List<Exception>> exceptions;
 
 	public ExecutionException(final Map<Thread, List<Exception>> exceptions) {
-		super((exceptions.size() == 1) ? exceptions.toString() : exceptions.size() + " error(s) while execution. Check thrown exception(s).");
+		super("3003 - " + ((exceptions.size() == 1) ? exceptions.toString() : exceptions.size()) + " error(s) occurred while execution. Check thrown exception(s).");
 		this.exceptions = exceptions;
 	}
 
diff --git a/src/main/java/teetime/framework/ExecutionInstantiation.java b/src/main/java/teetime/framework/ExecutionInstantiation.java
index d9bf4fa4..e30c1ee0 100644
--- a/src/main/java/teetime/framework/ExecutionInstantiation.java
+++ b/src/main/java/teetime/framework/ExecutionInstantiation.java
@@ -95,7 +95,8 @@ class ExecutionInstantiation {
 			} else {
 				if (colors.containsKey(targetStage)) {
 					if (!colors.get(targetStage).equals(color)) {
-						throw new IllegalStateException("Crossing threads"); // One stage is connected to a stage of another thread (but not its "headstage")
+						throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread
+																												// (but not its "headstage")
 					}
 				}
 				intraThreadPipeFactory.create(outputPort, pipe.getTargetPort());
diff --git a/src/main/java/teetime/framework/NotEnoughInputException.java b/src/main/java/teetime/framework/NotEnoughInputException.java
index 883aa43b..a46d4b30 100644
--- a/src/main/java/teetime/framework/NotEnoughInputException.java
+++ b/src/main/java/teetime/framework/NotEnoughInputException.java
@@ -15,7 +15,7 @@
  */
 package teetime.framework;
 
-public final class NotEnoughInputException extends RuntimeException {
+final class NotEnoughInputException extends RuntimeException {
 
 	private static final long serialVersionUID = -2517233596919204396L;
 
diff --git a/src/main/java/teetime/framework/ThreadService.java b/src/main/java/teetime/framework/ThreadService.java
index cf9ac715..2df4b165 100644
--- a/src/main/java/teetime/framework/ThreadService.java
+++ b/src/main/java/teetime/framework/ThreadService.java
@@ -85,7 +85,7 @@ class ThreadService extends AbstractService<ThreadService> {
 
 		threadableStages.addAll(newThreadableStages);
 		if (threadableStages.isEmpty()) {
-			throw new IllegalStateException("No stage was added using the addThreadableStage(..) method. Add at least one stage.");
+			throw new IllegalStateException("1004 - No threadable stages in this configuration.");
 		}
 
 		A2InvalidThreadAssignmentCheck checker = new A2InvalidThreadAssignmentCheck(newThreadableStages);
-- 
GitLab