dk.netarkivet.common.distribute
Class HTTPRemoteFileRegistry

java.lang.Object
  extended by dk.netarkivet.common.distribute.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.


Nested Class Summary
protected  class HTTPRemoteFileRegistry.HTTPRemoteFileRegistryHandler
          A handler for the registry.
 
Field Summary
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
protected HTTPRemoteFileRegistry()
          Initialise the registry.
 
Method Summary
 void cleanup()
          Stops the server and nulls the instance.
(package private)  java.net.URL getCleanupUrl(java.net.URL url)
          Get the url for cleaning up after a remote file registered under some URL.
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

instance

protected static HTTPRemoteFileRegistry instance
The unique instance.


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.

getInstance

public static HTTPRemoteFileRegistry getInstance()
Get the unique instance.

Returns:
The unique instance.

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

getCleanupUrl

java.net.URL getCleanupUrl(java.net.URL url)
                     throws java.net.MalformedURLException
Get the url for cleaning up after a remote file registered under some URL.

Parameters:
url - some URL
Returns:
the cleanup url.
Throws:
java.net.MalformedURLException - If unable to construct the cleanup url

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