Commit c8a111a1 authored by Yudi Zheng's avatar Yudi Zheng

String or Thread sent without data will now be created directly as ShadowString or ShadowThread.

parent 757d1293
......@@ -6,6 +6,9 @@ import java.io.IOException;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
import ch.usi.dag.dislreserver.shadow.NetReferenceHelper;
import ch.usi.dag.dislreserver.shadow.ShadowClass;
import ch.usi.dag.dislreserver.shadow.ShadowClassTable;
import ch.usi.dag.dislreserver.shadow.ShadowObjectTable;
import ch.usi.dag.dislreserver.shadow.ShadowString;
......@@ -19,7 +22,9 @@ public class StringInfoHandler implements RequestHandler {
long net_ref = is.readLong();
String str = is.readUTF();
ShadowString sString = new ShadowString(net_ref, str);
ShadowClass klass = ShadowClassTable.get(NetReferenceHelper
.get_class_id(net_ref));
ShadowString sString = new ShadowString(net_ref, str, klass);
ShadowObjectTable.register(sString, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
......
......@@ -6,6 +6,9 @@ import java.io.IOException;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
import ch.usi.dag.dislreserver.shadow.NetReferenceHelper;
import ch.usi.dag.dislreserver.shadow.ShadowClass;
import ch.usi.dag.dislreserver.shadow.ShadowClassTable;
import ch.usi.dag.dislreserver.shadow.ShadowObjectTable;
import ch.usi.dag.dislreserver.shadow.ShadowThread;
......@@ -20,7 +23,11 @@ public class ThreadInfoHandler implements RequestHandler {
String name = is.readUTF();
boolean isDaemon = is.readBoolean();
ShadowThread sThread = new ShadowThread(net_ref, name, isDaemon);
ShadowClass klass = ShadowClassTable.get(NetReferenceHelper
.get_class_id(net_ref));
ShadowThread sThread = new ShadowThread(net_ref, name, isDaemon,
klass);
ShadowObjectTable.register(sThread, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
......
......@@ -12,14 +12,6 @@ public class ShadowObject implements Formattable {
//
ShadowObject (final long netReference) {
this (
netReference, ShadowClassTable.get (
NetReferenceHelper.get_class_id (netReference)
)
);
}
ShadowObject (final long netReference, final ShadowClass shadowClass) {
this.shadowId = NetReferenceHelper.get_object_id (netReference);
......
......@@ -35,6 +35,20 @@ public class ShadowObjectTable {
}
}
private static boolean isAssignableFromThread(ShadowClass klass) {
while ("java.lang.Object".equals(klass.getName())) {
if ("java.lang.Thread".equals(klass.getName())) {
return true;
}
klass = klass.getSuperclass();
}
return false;
}
public static ShadowObject get(long net_ref) {
long objID = NetReferenceHelper.get_object_id(net_ref);
......@@ -54,7 +68,17 @@ public class ShadowObjectTable {
throw new DiSLREServerFatalException("Unknown class instance");
} else {
// Only common shadow object will be generated here
ShadowObject tmp = new ShadowObject(net_ref);
ShadowClass klass = ShadowClassTable.get(NetReferenceHelper
.get_class_id(net_ref));
ShadowObject tmp = null;
if ("java.lang.String".equals(klass.getName())) {
tmp = new ShadowString(net_ref, null, klass);
} else if (isAssignableFromThread(klass)) {
tmp = new ShadowThread(net_ref, null, false, klass);
} else {
tmp = new ShadowObject(net_ref, klass);
}
if ((retVal = shadowObjects.putIfAbsent(objID, tmp)) == null) {
retVal = tmp;
......
package ch.usi.dag.dislreserver.shadow;
public class ShadowString extends ShadowObject {
private String value;
public ShadowString(long net_ref, String value) {
super(net_ref);
public ShadowString(long net_ref, String value, ShadowClass klass) {
super(net_ref, klass);
this.value = value;
}
// TODO warn user that it will return null when the ShadowString is not yet sent.
@Override
public String toString() {
return value;
......@@ -17,9 +19,17 @@ public class ShadowString extends ShadowObject {
@Override
public boolean equals(Object obj) {
if (obj instanceof ShadowString) {
return value.equals(((ShadowString) obj).value)
&& super.equals(obj);
if (super.equals(obj)) {
if (obj instanceof ShadowString) {
if (value == null) {
value = ((ShadowString) obj).value;
return true;
} else {
return value.equals(((ShadowString) obj).value);
}
}
}
return false;
......
......@@ -5,28 +5,42 @@ public class ShadowThread extends ShadowObject {
private String name;
private boolean isDaemon;
public ShadowThread(long net_ref, String name, boolean isDaemon) {
super(net_ref);
public ShadowThread(long net_ref, String name, boolean isDaemon,
ShadowClass klass) {
super(net_ref, klass);
this.name = name;
this.isDaemon = isDaemon;
}
// TODO warn user that it will return null when the ShadowThread is not yet sent.
public String getName() {
return name;
}
// TODO warn user that it will return false when the ShadowThread is not yet sent.
public boolean isDaemon() {
return isDaemon;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ShadowThread) {
ShadowThread t = (ShadowThread) obj;
return name.equals(t.name) && (isDaemon == t.isDaemon)
&& super.equals(obj);
if (super.equals(obj)) {
if (obj instanceof ShadowThread) {
ShadowThread t = (ShadowThread) obj;
if (name == null) {
name = t.name;
isDaemon = t.isDaemon;
return true;
} else {
return name.equals(t.name) && (isDaemon == t.isDaemon)
&& super.equals(obj);
}
}
}
return false;
......
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