Commit bb99ca9c authored by Lubomir Bulej's avatar Lubomir Bulej

ShadowClass, ShadowObject, ShadowString, ShadowThread: added formatting code...

ShadowClass, ShadowObject, ShadowString, ShadowThread: added formatting code to print out different shadow object.
ShadowObjectTable: added objects() method to provide an instance of Iterable <ShadowObject>.
parent 09bbfc56
package ch.usi.dag.dislreserver.shadow;
import java.util.Formatter;
public abstract class ShadowClass extends ShadowObject {
private final int classId;
......@@ -145,4 +147,15 @@ public abstract class ShadowClass extends ShadowObject {
return buf.toString();
}
//
@Override
public void formatTo (
final Formatter formatter,
final int flags, final int width, final int precision
) {
// FIXME LB: ShadowClass instances do not have a ShadowClass (of Class)
formatter.format ("java.lang.Class@%d <%s>", getId (), getName ());
}
}
......@@ -94,7 +94,9 @@ public class ShadowObject implements Formattable {
final Formatter formatter,
final int flags, final int width, final int precision
) {
formatter.format ("%s@%x", (shadowClass != null) ? shadowClass.getName () : "<missing>", shadowId);
formatter.format ("%s@%x", (shadowClass != null) ?
shadowClass.getName () : "<missing>", shadowId
);
}
}
......@@ -8,12 +8,12 @@ import ch.usi.dag.dislreserver.DiSLREServerFatalException;
public class ShadowObjectTable {
private static final int INITIAL_TABLE_SIZE = 10000000;
private static ConcurrentHashMap<Long, ShadowObject> shadowObjects;
private static final int INITIAL_TABLE_SIZE = 10_000_000;
static {
private static ConcurrentHashMap<Long, ShadowObject>
shadowObjects = new ConcurrentHashMap<Long, ShadowObject>(INITIAL_TABLE_SIZE);
}
//
public static void register(ShadowObject newObj, boolean debug) {
......@@ -133,4 +133,13 @@ public class ShadowObjectTable {
public static Iterator<Entry<Long, ShadowObject>> getIterator() {
return shadowObjects.entrySet().iterator();
}
public static Iterable <ShadowObject> objects () {
return new Iterable <ShadowObject>() {
@Override
public Iterator <ShadowObject> iterator () {
return shadowObjects.values ().iterator ();
}
};
}
}
package ch.usi.dag.dislreserver.shadow;
import java.util.Formatter;
// TODO ShadowString should better handle if String data are not send
// over network - throw a runtime exception ??
public class ShadowString extends ShadowObject {
......@@ -50,4 +52,19 @@ public class ShadowString extends ShadowObject {
//
return super.hashCode ();
}
//
@Override
public void formatTo (
final Formatter formatter,
final int flags, final int width, final int precision
) {
super.formatTo (formatter, flags, width, precision);
if (value != null) {
formatter.format (" <%s>", value);
}
}
}
package ch.usi.dag.dislreserver.shadow;
import java.util.Formattable;
import java.util.Formatter;
// TODO ShadowTrhead should better handle if String data are not send
// over network - throw a runtime exception ??
public class ShadowThread extends ShadowObject {
public class ShadowThread extends ShadowObject implements Formattable {
private String name;
private boolean isDaemon;
......@@ -58,4 +61,16 @@ public class ShadowThread extends ShadowObject {
public int hashCode() {
throw new UnsupportedOperationException("overriden equals, not overriden hashCode");
}
//
@Override
public void formatTo (
final Formatter formatter,
final int flags, final int width, final int precision
) {
super.formatTo (formatter, flags, width, precision);
formatter.format (" <%s>", (name != null) ? name : "unknown");
}
}
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