Class JFTP

  • All Implemented Interfaces:
    CSProcess

    class JFTP
    extends java.lang.Object
    implements CSProcess

    A server process for dispatching binary images of classes to nodes that do not hold suitable definitions locally. An instance of this process is started for a node by the DynamicClassLoader service. A request channel is connected to this process through which remote nodes can request images of classes.

    Classes can be retrieved from individual .class files in the class path or from a Java archive. The current implementation does not support compressed archives. If a file from an archive is requested, the remote node will be sent a manifest listing all of the other classes available in the archive. This allows the remote node to better determine where to request classes from in the case of objects being passed through a lengthy pipeline of nodes.

    Once a remote node has requested a file from an archive the rest of the archive will be queued for dispatch to that node. This preemptive forwarding of information can give more reliable performance by increasing the likelihood of a node passing on all of the definitions its peers might require before it terminates.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  JFTP.ChanSet
      Implementation of a set type structure for holding ChannelOutput objects with a flag to indicate that the request set is currently being processed.
      (package private) static class  JFTP.ClassReply
      Represents a reply to a client for a loaded class, giving the class name and binary image.
      (package private) static class  JFTP.ClassRequest
      Represents a class request, indicating the class required, the channel to reply to the client on and the flags to indicate whether a manifest is also wanted.
      (package private) static class  JFTP.JarManifestReply
      Represents a reply to a client detailing a manifest of an archive.
      private class  JFTP.QueuedClassLoaderProcess
      Child process spawned by the run() method of JFTP to retrieve a class that has been queued for output to another node.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader classLoader
      The default class loader to get locally held classes from.
      private Any2OneChannel classNotify
      Child processes spawned to load classes from disk or from another node pass the loaded data on this channel to the main process fror forwarding to the requesting clients.
      private Any2OneChannel classQueue
      Child processes spawned to load classes from Java archives will create additional requests on this channel to queue other files from the archive to be sent to a client.
      private ClassManager cm
      The local class manager for tracking classes that were dynamically loaded by this node.
      static int CR_WANT_CLASS
      Flag for indicating in a ClassRequest that the class image is required.
      static int CR_WANT_MANIFEST
      Flag for indicating in a ClassRequest that a manifest is required.
      private java.util.Hashtable outputQueue
      Queues (and combines) requests for classes by clients.
      private AltingChannelInput req
      Incoming requests from the clients.
    • Constructor Summary

      Constructors 
      Constructor Description
      JFTP​(java.lang.ClassLoader classLoader, AltingChannelInput req, ClassManager cm)
      Constructs a new JFTP process.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void findAndLoadClass​(java.lang.String className, boolean wantClass, boolean wantManifest, ChannelOutput toRequestingClient, ChannelOutput notifyOthers, ChannelOutput queueFurtherRequest)
      Attempts to load a class using the local class loader.
      void run()
      Main process thread, servicing requests sent on the req channel.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • classNotify

        private final Any2OneChannel classNotify
        Child processes spawned to load classes from disk or from another node pass the loaded data on this channel to the main process fror forwarding to the requesting clients.
      • classQueue

        private final Any2OneChannel classQueue
        Child processes spawned to load classes from Java archives will create additional requests on this channel to queue other files from the archive to be sent to a client.
      • classLoader

        private final java.lang.ClassLoader classLoader
        The default class loader to get locally held classes from.
      • cm

        private final ClassManager cm
        The local class manager for tracking classes that were dynamically loaded by this node.
      • outputQueue

        private final java.util.Hashtable outputQueue
        Queues (and combines) requests for classes by clients. Associates String class names with ChanSet objects that contain the ClassRequest objects.
      • CR_WANT_MANIFEST

        public static final int CR_WANT_MANIFEST
        Flag for indicating in a ClassRequest that a manifest is required.
        See Also:
        Constant Field Values
      • CR_WANT_CLASS

        public static final int CR_WANT_CLASS
        Flag for indicating in a ClassRequest that the class image is required.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JFTP

        public JFTP​(java.lang.ClassLoader classLoader,
                    AltingChannelInput req,
                    ClassManager cm)
        Constructs a new JFTP process.
        Parameters:
        classLoader - the class loader to obtain resources held locally from.
        req - the request channel for communication with other nodes.
        cm - the local class manager responsible for classes dynamically loaded by this node.
    • Method Detail

      • run

        public void run()
        Main process thread, servicing requests sent on the req channel. Once a request is received, a process will be spawned to complete the operation and allow another node to be serviced. Where possible, requests for the same class are combined so that it is only loaded once.
        Specified by:
        run in interface CSProcess
      • findAndLoadClass

        private void findAndLoadClass​(java.lang.String className,
                                      boolean wantClass,
                                      boolean wantManifest,
                                      ChannelOutput toRequestingClient,
                                      ChannelOutput notifyOthers,
                                      ChannelOutput queueFurtherRequest)

        Attempts to load a class using the local class loader. If the class was not found locally, the class manager is queried - the class might have been dynamically loaded. If the class manager has an image for the file it is sent. If the class manager has marked the class as pending then it will issue a request to the originating node's JFTP process.

        If the class is loaded locally from a Java archive, a manifest is generated and returned with the class to the client. The other contents of the archive are then queued for transmission to the client. If the class was dynamically loaded by this node and a manifest was received, this manifest is forwarded to the client.

        Parameters:
        className - name of the class to find.
        wantClass - true iff the binary image for the class is required.
        wantManifest - true iff a manifest reply is required.
        toRequestingClient - manifest replies to the client are sent on this channel.
        notifyOthers - the ClassReply is sent on this channel for dispatch to all clients needing it.
        queueFurtherRequest - if loading from an archive, new class requests are generated for the client on this channel.