Package dk.netarkivet.common.distribute
Class HTTPRemoteFileRegistry
- java.lang.Object
-
- dk.netarkivet.common.distribute.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
HTTPRemoteFileRegistry.HTTPRemoteFileRegistryHandler
A handler for the registry.
-
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 String
getProtocol()
Get the protocol part of URLs, that is HTTP.protected URLConnection
openConnection(URL url)
Open a connection to an URL in a registry.URL
registerFile(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.
-
-
-
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 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.
-
-