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

Merge branch 'new-stage-id' into 'master'

New stage id's

Modified the way how TeeTime names the stages. #76

See merge request !20
parents 3868f2c9 882156c0
No related branches found
No related tags found
No related merge requests found
package teetime.framework;
import java.util.List;
import java.util.UUID;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -9,17 +10,18 @@ import org.slf4j.LoggerFactory;
import teetime.framework.signal.ISignal;
import teetime.framework.validation.InvalidPortConnection;
public abstract class Stage {
public abstract class Stage { // NOPMD (should not start with "Abstract"
private final String id;
private static final Map<String, Integer> INSTANCES_COUNTER = new ConcurrentHashMap<String, Integer>();
/**
* A unique logger instance per stage instance
*/
protected final Logger logger; // NOPMD
protected Stage() {
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 + ")");
this.id = this.createId();
this.logger = LoggerFactory.getLogger(this.getClass().getName() + "-" + this.id);
}
public String getId() {
......@@ -31,6 +33,19 @@ public abstract class Stage {
return this.getClass().getName() + ": " + this.getId();
}
private String createId() {
String simpleName = this.getClass().getSimpleName();
Integer numInstances = INSTANCES_COUNTER.get(simpleName);
if (null == numInstances) {
numInstances = 0;
}
String newId = simpleName + "-" + numInstances;
INSTANCES_COUNTER.put(simpleName, ++numInstances);
return newId;
}
// public abstract Stage getParentStage();
//
// public abstract void setParentStage(Stage parentStage, int index);
......
package teetime.framework;
import org.junit.Assert;
import org.junit.Test;
import teetime.stage.Cache;
import teetime.stage.Counter;
public class StageTest {
@Test
public void testId() {
Counter<Object> counter0 = new Counter<Object>();
Counter<Object> counter1 = new Counter<Object>();
Assert.assertEquals("Counter-0", counter0.getId());
Assert.assertEquals("Counter-1", counter1.getId());
for (int i = 0; i < 100; i++) {
Cache<Object> cache = new Cache<Object>();
Assert.assertEquals("Cache-" + i, cache.getId());
}
}
}
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