Class HTTPRemoteFileRegistry

  • All Implemented Interfaces:
    CleanupIF
    Direct Known Subclasses:
    HTTPSRemoteFileRegistry

    public class HTTPRemoteFileRegistry
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      protected static HTTPRemoteFileRegistry instance
      The unique instance.
      protected int port
      Port number for generating URLs.
      protected org.mortbay.jetty.Server server
      The embedded webserver.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected HTTPRemoteFileRegistry()
      Initialise the registry.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cleanup()
      Stops the server and nulls the instance.
      static HTTPRemoteFileRegistry getInstance()
      Get the unique instance.
      protected java.lang.String getProtocol()
      Get the protocol part of URLs, that is HTTP.
      protected java.net.URLConnection openConnection​(java.net.URL url)
      Open a connection to an URL in a registry.
      java.net.URL registerFile​(java.io.File file, boolean deletable)
      Register a file for serving to an endpoint.
      protected void startServer()
      Start the server, including a handler that responds with registered files, removes registered files on request, and gives 404 otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 java.lang.String getProtocol()
        Get the protocol part of URLs, that is HTTP.
        Returns:
        "http", the protocol.
      • registerFile

        public java.net.URL registerFile​(java.io.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 java.net.URLConnection openConnection​(java.net.URL url)
                                                 throws java.io.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:
        java.io.IOException - If unable to open the connection.
      • cleanup

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