class ClassManager extends java.lang.Object implements CSProcess
A process for retrieving and registering classes that cannot be found locally. A single instance of this process runs, with other components in the dynamic class loading infrastructure invoking the public methods to request the loading of a class.
When a class is requested, the system class loader will be tried first. If this fails, a cache
of classes received dynamically will be tried. If this fails, and a NodeClassLoader
has
already been started for communication with the remote node, it will be used to retrieve the class
file from that node. If a NodeClassLoader
has not been started, one will be created
and used for all subsequent requests to be issued to the remote node.
Modifier and Type | Class and Description |
---|---|
private static class |
ClassManager.ClassRequest
Marshals a set of parameters for passing information between
getClass and the
main process thread. |
private static class |
ClassManager.RegisteredClass
Used in the
classes hash table to represent class names. |
Modifier and Type | Field and Description |
---|---|
private java.util.Hashtable |
classes
Maps
RegisteredClass objects to byte[] binary images. |
private java.util.Hashtable |
classFiles
Maps
String class names to byte[] binary images. |
private java.util.Hashtable |
classLoaders
Maps
NetChannelLocation objects to NodeClassLoader objects to use to
retrieve classes from that node. |
private java.util.Hashtable |
classManifests
Maps
String class names to JarManifestReply objects. |
private java.util.Hashtable |
classPendings
Maps
String class names to NodeClassLoader objects to use to retrieve
them. |
private Any2OneChannel |
classRegChan
Used to pass requests to the main process thread from calls to the
registerClass
method. |
private One2OneChannel |
classRegReplyChan
Used to pass replies from the main process thread to callers of the
registerClass
method. |
private Any2OneChannel |
classReqs
Used to pass requests to the main process thread from calls to the
getClass method. |
private java.lang.ClassLoader |
systemClassLoader
A local reference to the system class loader.
|
Constructor and Description |
---|
ClassManager() |
Modifier and Type | Method and Description |
---|---|
JFTP.JarManifestReply |
checkForPendingClass(java.lang.String name)
Attempts to load the class from a remote node if it has previously been marked as pending.
|
private void |
classNoLongerPending(java.lang.String name)
Marks a class as arrived after it was previously marked as pending.
|
void |
classPending(java.lang.String name,
java.lang.ClassLoader clToUse,
JFTP.JarManifestReply jmr)
Marks a class as scheduled for later arrival.
|
void |
getClass(java.lang.String name,
NetChannelLocation classSourceChannelLoc,
ChannelOutput replyChan)
Requests that the class manager process attempt to load the given class.
|
byte[] |
getClassBytes(java.lang.String name)
Gets the binary image for a given class.
|
boolean |
pendingClassManifestAvailable(java.lang.String className)
Returns true iff a manifest reply has been stored for the specified class.
|
java.lang.Class |
registerClass(java.lang.Class cls,
byte[] fileBytes)
Stores the binary image for the class to optimize any further requests for the same class.
|
void |
run()
Process execution method.
|
private Any2OneChannel classReqs
getClass
method.private Any2OneChannel classRegChan
registerClass
method.private One2OneChannel classRegReplyChan
registerClass
method.private java.lang.ClassLoader systemClassLoader
private java.util.Hashtable classes
RegisteredClass
objects to byte[]
binary images.private java.util.Hashtable classLoaders
NetChannelLocation
objects to NodeClassLoader
objects to use to
retrieve classes from that node.private java.util.Hashtable classFiles
String
class names to byte[]
binary images.private java.util.Hashtable classPendings
String
class names to NodeClassLoader
objects to use to retrieve
them.private java.util.Hashtable classManifests
String
class names to JarManifestReply
objects.public void run()
public void classPending(java.lang.String name, java.lang.ClassLoader clToUse, JFTP.JarManifestReply jmr)
Marks a class as scheduled for later arrival. This is called when a NodeClassLoader
receives a JarManifestReply
from a remote node to indicate that requests for the
class should be directed to that class loader. If a JFTP process receives a request for a
class that is not held locally it will check the set of pending classes to determine the class
loader that it should invoke to retrieve the class.
The original manifest reply is also associated with the class so that this can be forwarded to other class loaders replicating the behaviour of the original JFTP process that loaded the class from disk.
name
- the name of the class.clToUse
- the class loader that can retrieve the class.jmr
- the manifest reply to associate with the class.private void classNoLongerPending(java.lang.String name)
Marks a class as arrived after it was previously marked as pending. This is called when a
NodeClassLoader
has received a class as a result of an issued request or a JFTP
process push.
name
- the name of the class that has arrived.public boolean pendingClassManifestAvailable(java.lang.String className)
checkForPendingClass
which will also issue a request to load
the class from the remote node.className
- the name of the class to check.public JFTP.JarManifestReply checkForPendingClass(java.lang.String name)
Attempts to load the class from a remote node if it has previously been marked as pending. The
class loader associated with the class by a call to classPending
will be used. If
there is no associated class loader, no action is taken. If there is a manifest reply associated
with the class this will be returned for possible forwarding to another node.
If this method issues a call to a class loader this may block until the class has arrived. This may take a large amount of time if the class has to be routed through a chain of JFTP processes and class loaders.
name
- the name of the class to check.public void getClass(java.lang.String name, NetChannelLocation classSourceChannelLoc, ChannelOutput replyChan)
name
- the name of the class to retrieve.classSourceChannelLoc
- location of the channel to request fromreplyChan
- reply channel to notify the caller of operation completionpublic java.lang.Class registerClass(java.lang.Class cls, byte[] fileBytes)
cls
- class that has been loaded.fileBytes
- the binary image defining the class.cls
parameter but possibly a different class if
one has already been registered by another class loader.public byte[] getClassBytes(java.lang.String name)
name
- name of the class.registerClass
.