Commit cb1aa379 authored by Yudi Zheng's avatar Yudi Zheng

decouple ShadowString/ShadowThread value propagation from the equals method

parent 091ceca3
......@@ -15,24 +15,59 @@ public class ShadowObjectTable {
shadowObjects = new ConcurrentHashMap<Long, ShadowObject>(INITIAL_TABLE_SIZE);
}
public static void register(ShadowObject obj, boolean debug) {
public static void register(ShadowObject newObj, boolean debug) {
if (obj == null) {
if (newObj == null) {
throw new DiSLREServerFatalException(
"Attempting to register a null as a shadow object");
}
long objID = obj.getId();
ShadowObject exist = shadowObjects.putIfAbsent(objID, obj);
long objID = newObj.getId();
ShadowObject exist = shadowObjects.putIfAbsent(objID, newObj);
if (exist != null) {
if (exist.equals(obj)) {
if (newObj.getId() == exist.getId()) {
if (debug) {
System.out.println("Re-register a shadow object.");
}
} else {
throw new DiSLREServerFatalException("Duplicated net reference");
if (newObj.equals(exist)) {
return;
}
if (newObj instanceof ShadowString) {
if (exist instanceof ShadowString) {
ShadowString existShadowString = (ShadowString) exist;
ShadowString newShadowString = (ShadowString) newObj;
if (existShadowString.toString() == null) {
existShadowString.setValue(newShadowString
.toString());
return;
}
}
} else if (newObj instanceof ShadowThread) {
if (exist instanceof ShadowThread) {
ShadowThread existShadowThread = (ShadowThread) exist;
ShadowThread newShadowThread = (ShadowThread) newObj;
if (existShadowThread.getName() == null) {
existShadowThread
.setName(newShadowThread.getName());
existShadowThread.setDaemon(newShadowThread
.isDaemon());
return;
}
}
}
}
throw new DiSLREServerFatalException("Duplicated net reference");
}
}
......
......@@ -16,6 +16,10 @@ public class ShadowString extends ShadowObject {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
......@@ -23,11 +27,8 @@ public class ShadowString extends ShadowObject {
if (obj instanceof ShadowString) {
if (value == null) {
value = ((ShadowString) obj).value;
if (value != null && value.equals(((ShadowString) obj).value)) {
return true;
} else {
return value.equals(((ShadowString) obj).value);
}
}
}
......
......@@ -23,6 +23,14 @@ public class ShadowThread extends ShadowObject {
return isDaemon;
}
public void setName(String name) {
this.name = name;
}
public void setDaemon(boolean isDaemon) {
this.isDaemon = isDaemon;
}
@Override
public boolean equals(Object obj) {
......@@ -32,13 +40,9 @@ public class ShadowThread extends ShadowObject {
ShadowThread t = (ShadowThread) obj;
if (name == null) {
name = t.name;
isDaemon = t.isDaemon;
if (name != null && name.equals(t.name)
&& (isDaemon == t.isDaemon)) {
return true;
} else {
return name.equals(t.name) && (isDaemon == t.isDaemon)
&& super.equals(obj);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment