org.openstreetmap.osmosis.core.merge.v0_6
Class BaseReplicationDownloader

java.lang.Object
  extended by org.openstreetmap.osmosis.core.merge.v0_6.BaseReplicationDownloader
All Implemented Interfaces:
java.lang.Runnable, RunnableTask, Task
Direct Known Subclasses:
ReplicationDownloader, ReplicationFileMerger

public abstract class BaseReplicationDownloader
extends java.lang.Object
implements RunnableTask

This class downloads a set of replication files from a HTTP server and tracks the progress of which files have already been processed. The actual processing of changeset files is performed by sub-classes. This class forms the basis of a replication mechanism.

Author:
Brett Henderson

Constructor Summary
BaseReplicationDownloader(java.io.File workingDirectory)
          Creates a new instance.
 
Method Summary
protected  java.util.Date calculateMaximumTimestamp(ReplicationDownloaderConfiguration configuration, java.util.Date serverTimestamp, java.util.Date localTimestamp)
          Determines the maximum timestamp of data to be downloaded during this invocation.
protected  java.io.File getWorkingDirectory()
          Provides sub-classes with access to the working directory.
protected abstract  void processChangeset(XmlChangeReader xmlReader, ReplicationState replicationState)
          Processes the changeset.
protected abstract  void processComplete()
          This is implemented by sub-classes and is called when all changesets have been processed.
protected abstract  void processInitialize(ReplicationState initialState)
          Invoked once during the first execution run to allow initialisation based on the initial replication state downloaded from the server.
protected abstract  void processRelease()
          This is implemented by sub-classes and is called and the completion of all processing regardless of whether it was successful or not.
 void run()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseReplicationDownloader

public BaseReplicationDownloader(java.io.File workingDirectory)
Creates a new instance.

Parameters:
workingDirectory - The directory containing configuration and tracking files.
Method Detail

getWorkingDirectory

protected java.io.File getWorkingDirectory()
Provides sub-classes with access to the working directory.

Returns:
The working directory for the task.

calculateMaximumTimestamp

protected java.util.Date calculateMaximumTimestamp(ReplicationDownloaderConfiguration configuration,
                                                   java.util.Date serverTimestamp,
                                                   java.util.Date localTimestamp)
Determines the maximum timestamp of data to be downloaded during this invocation. This may be overriden by sub-classes, but the sub-classes must call this implemention first and then limit the maximum timestamp further if needed. A sub-class may never increase the maximum timestamp beyond that calculated by this method.

Parameters:
configuration - The configuration.
serverTimestamp - The timestamp of the latest data on the server.
localTimestamp - The timestamp of the most recently downloaded data.
Returns:
The maximum timestamp for this invocation.

processInitialize

protected abstract void processInitialize(ReplicationState initialState)
Invoked once during the first execution run to allow initialisation based on the initial replication state downloaded from the server.

Parameters:
initialState - The first server state.

processChangeset

protected abstract void processChangeset(XmlChangeReader xmlReader,
                                         ReplicationState replicationState)
Processes the changeset.

Parameters:
xmlReader - The changeset reader initialised to point to the changeset file.
replicationState - The replication state associated with the changeset file.

processComplete

protected abstract void processComplete()
This is implemented by sub-classes and is called when all changesets have been processed. This should perform any completion tasks such as committing changes to a database.


processRelease

protected abstract void processRelease()
This is implemented by sub-classes and is called and the completion of all processing regardless of whether it was successful or not. This should perform any cleanup tasks such as closing files or releasing database connections.


run

public void run()

Specified by:
run in interface java.lang.Runnable