Class ClassManager
- java.lang.Object
-
- org.jcsp.net.dynamic.ClassManager
-
- All Implemented Interfaces:
CSProcess
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
NodeClassLoaderhas already been started for communication with the remote node, it will be used to retrieve the class file from that node. If aNodeClassLoaderhas not been started, one will be created and used for all subsequent requests to be issued to the remote node.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classClassManager.ClassRequestMarshals a set of parameters for passing information betweengetClassand the main process thread.private static classClassManager.RegisteredClassUsed in theclasseshash table to represent class names.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashtableclassesMapsRegisteredClassobjects tobyte[]binary images.private java.util.HashtableclassFilesMapsStringclass names tobyte[]binary images.private java.util.HashtableclassLoadersMapsNetChannelLocationobjects toNodeClassLoaderobjects to use to retrieve classes from that node.private java.util.HashtableclassManifestsMapsStringclass names toJarManifestReplyobjects.private java.util.HashtableclassPendingsMapsStringclass names toNodeClassLoaderobjects to use to retrieve them.private Any2OneChannelclassRegChanUsed to pass requests to the main process thread from calls to theregisterClassmethod.private One2OneChannelclassRegReplyChanUsed to pass replies from the main process thread to callers of theregisterClassmethod.private Any2OneChannelclassReqsUsed to pass requests to the main process thread from calls to thegetClassmethod.private java.lang.ClassLoadersystemClassLoaderA local reference to the system class loader.
-
Constructor Summary
Constructors Constructor Description ClassManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JFTP.JarManifestReplycheckForPendingClass(java.lang.String name)Attempts to load the class from a remote node if it has previously been marked as pending.private voidclassNoLongerPending(java.lang.String name)Marks a class as arrived after it was previously marked as pending.voidclassPending(java.lang.String name, java.lang.ClassLoader clToUse, JFTP.JarManifestReply jmr)Marks a class as scheduled for later arrival.voidgetClass(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.booleanpendingClassManifestAvailable(java.lang.String className)Returns true iff a manifest reply has been stored for the specified class.java.lang.ClassregisterClass(java.lang.Class cls, byte[] fileBytes)Stores the binary image for the class to optimize any further requests for the same class.voidrun()Process execution method.
-
-
-
Field Detail
-
classReqs
private Any2OneChannel classReqs
Used to pass requests to the main process thread from calls to thegetClassmethod.
-
classRegChan
private Any2OneChannel classRegChan
Used to pass requests to the main process thread from calls to theregisterClassmethod.
-
classRegReplyChan
private One2OneChannel classRegReplyChan
Used to pass replies from the main process thread to callers of theregisterClassmethod.
-
systemClassLoader
private java.lang.ClassLoader systemClassLoader
A local reference to the system class loader. This is held as an attribute so that it would be possible to change the class loader that this process tries by default when resolving classes.
-
classes
private java.util.Hashtable classes
MapsRegisteredClassobjects tobyte[]binary images.
-
classLoaders
private java.util.Hashtable classLoaders
MapsNetChannelLocationobjects toNodeClassLoaderobjects to use to retrieve classes from that node.
-
classFiles
private java.util.Hashtable classFiles
MapsStringclass names tobyte[]binary images.
-
classPendings
private java.util.Hashtable classPendings
MapsStringclass names toNodeClassLoaderobjects to use to retrieve them.
-
classManifests
private java.util.Hashtable classManifests
MapsStringclass names toJarManifestReplyobjects.
-
-
Method Detail
-
run
public void run()
Process execution method. Requests are issued to the process by calling the other methods. These will synchronize with the process thread and transfer information to it via internal channels.
-
classPending
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
NodeClassLoaderreceives aJarManifestReplyfrom 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.
- Parameters:
name- the name of the class.clToUse- the class loader that can retrieve the class.jmr- the manifest reply to associate with the class.
-
classNoLongerPending
private void classNoLongerPending(java.lang.String name)
Marks a class as arrived after it was previously marked as pending. This is called when a
NodeClassLoaderhas received a class as a result of an issued request or a JFTP process push.- Parameters:
name- the name of the class that has arrived.
-
pendingClassManifestAvailable
public boolean pendingClassManifestAvailable(java.lang.String className)
Returns true iff a manifest reply has been stored for the specified class. To retrieve the manifest reply, callcheckForPendingClasswhich will also issue a request to load the class from the remote node.- Parameters:
className- the name of the class to check.
-
checkForPendingClass
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
classPendingwill 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.
- Parameters:
name- the name of the class to check.
-
getClass
public void getClass(java.lang.String name, NetChannelLocation classSourceChannelLoc, ChannelOutput replyChan)Requests that the class manager process attempt to load the given class. This method will return once synchronization with the main thread has occurred. The caller will be notified of completion of the operation on the reply channel passed.- Parameters:
name- the name of the class to retrieve.classSourceChannelLoc- location of the channel to request fromreplyChan- reply channel to notify the caller of operation completion
-
registerClass
public 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. This method will synchronize with the main class manager thread which will update the hash tables to associate the image with the class and mark the class as having arrived if it was previously marked as pending.- Parameters:
cls- class that has been loaded.fileBytes- the binary image defining the class.- Returns:
- the class - typically the
clsparameter but possibly a different class if one has already been registered by another class loader.
-
getClassBytes
public byte[] getClassBytes(java.lang.String name)
Gets the binary image for a given class.- Parameters:
name- name of the class.- Returns:
- the binary image registered by a call to
registerClass.
-
-