Commit 71a2e3e9 authored by Lubomir Bulej's avatar Lubomir Bulej

NewClassHandler: separate IO code from handling of the received data.

NewClassHandler: only call a single method on ShadowClassTable to handle the request.
ShadowClassTable: rename load() to loadClass()
ShadowClassTable: simplify implementation of loadClass() by factoring out low-level bits.
parent e2016cbb
......@@ -7,33 +7,35 @@ import java.io.IOException;
import ch.usi.dag.dislreserver.DiSLREServerException;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
import ch.usi.dag.dislreserver.shadow.ShadowClassTable;
import ch.usi.dag.dislreserver.shadow.ShadowObject;
import ch.usi.dag.dislreserver.shadow.ShadowObjectTable;
public class NewClassHandler implements RequestHandler {
public void handle (DataInputStream is, DataOutputStream os, boolean debug)
throws DiSLREServerException {
@Override
public void handle (
final DataInputStream is, final DataOutputStream os, final boolean debug
) throws DiSLREServerException {
try {
String className = is.readUTF ();
long oid = is.readLong ();
ShadowObject classLoader = ShadowObjectTable.get (oid);
int classCodeLength = is.readInt ();
byte [] classCode = new byte [classCodeLength];
final String classInternalName = is.readUTF ();
final long classLoaderNetReference = is.readLong ();
final int classCodeLength = is.readInt ();
final byte [] classCode = new byte [classCodeLength];
is.readFully (classCode);
ShadowClassTable.load (classLoader, className, classCode, debug);
} catch (IOException e) {
ShadowClassTable.loadClass (
classInternalName, classLoaderNetReference, classCode
);
} catch (final IOException e) {
throw new DiSLREServerException (e);
}
}
@Override
public void exit () {
// do nothing
}
}
......@@ -57,29 +57,26 @@ public final class ShadowClassTable {
//
public static void load (
ShadowObject loader, final String className,
final byte [] classCode, final boolean debug
public static void loadClass (
final String classInternalName, final long classLoaderNetReference,
final byte [] classCode
) {
ConcurrentHashMap <String, byte []> classNameMap;
if (loader == null) {
// bootstrap loader
loader = BOOTSTRAP_CLASSLOADER;
}
classNameMap = classLoaderMap.get (loader);
if (classNameMap == null) {
final ConcurrentHashMap <String, byte []> tmp = new ConcurrentHashMap <> ();
if ((classNameMap = classLoaderMap.putIfAbsent (loader, tmp)) == null) {
classNameMap = tmp;
final ConcurrentHashMap <String, byte []> classNameMap = classLoaderMap.computeIfAbsent (
__safeClassLoader (ShadowObjectTable.get (classLoaderNetReference)),
cl -> new ConcurrentHashMap <> ()
);
// TODO LB: Consider using Type directly as the key.
final String className = classInternalName.replace ('/', '.');
if (classNameMap.putIfAbsent (className, classCode) != null) {
if (__log.debugIsLoggable ()) {
__log.debug ("reloading/redefining %s", classInternalName);
}
}
}
if (classNameMap.putIfAbsent (className.replace ('/', '.'), classCode) != null) {
if (debug) {
System.out.println ("DiSL-RE: Reloading/Redefining class "+ className);
}
}
private static ShadowObject __safeClassLoader (final ShadowObject classLoader) {
return (classLoader != null) ? classLoader : BOOTSTRAP_CLASSLOADER;
}
//
......@@ -162,6 +159,7 @@ public final class ShadowClassTable {
throw new DiSLREServerFatalException ("Unknown class loader");
}
// TODO LB: Consider using Type directly as the key.
final byte [] classCode = classNameMap.get (type.getClassName ());
if (classCode == null || classCode.length == 0) {
throw new DiSLREServerFatalException (
......
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