Class HTTPRemoteFileRegistry

  • All Implemented Interfaces:
    CleanupIF
    Direct Known Subclasses:
    HTTPSRemoteFileRegistry

    public class HTTPRemoteFileRegistry
    extends Object
    implements CleanupIF
    This is a registry for HTTP remote file, meant for serving registered files to remote hosts. The embedded webserver handling remote files for HTTPRemoteFile point-to-point communication. Optimised to use direct transfer on local machine.
    • Field Detail

      • port

        protected final int port
        Port number for generating URLs. Read from settings.
      • server

        protected org.mortbay.jetty.Server server
        The embedded webserver.
    • Constructor Detail

      • HTTPRemoteFileRegistry

        protected HTTPRemoteFileRegistry()
        Initialise the registry. This includes registering an HTTP server for getting the files from this machine.
        Throws:
        IOFailure - if it cannot be initialised.
    • Method Detail

      • startServer

        protected void startServer()
        Start the server, including a handler that responds with registered files, removes registered files on request, and gives 404 otherwise.
        Throws:
        IOFailure - if it cannot be initialised.
      • getProtocol

        protected String getProtocol()
        Get the protocol part of URLs, that is HTTP.
        Returns:
        "http", the protocol.
      • getInstance

        public static HTTPRemoteFileRegistry getInstance()
        Get the unique instance.
        Returns:
        The unique instance.
      • registerFile

        public URL registerFile​(File file,
                                boolean deletable)
        Register a file for serving to an endpoint.
        Parameters:
        file - The file to register.
        deletable - Whether it should be deleted on cleanup.
        Returns:
        The URL it will be served as. It will be uniquely generated.
        Throws:
        ArgumentNotValid - on null or unreadable file.
        IOFailure - on any trouble registerring the file
      • openConnection

        protected URLConnection openConnection​(URL url)
                                        throws IOException
        Open a connection to an URL in a registry.
        Parameters:
        url - The URL to open connection to.
        Returns:
        a connection to an URL in a registry
        Throws:
        IOException - If unable to open the connection.
      • cleanup

        public void cleanup()
        Stops the server and nulls the instance.
        Specified by:
        cleanup in interface CleanupIF