private ReplicationState download(ReplicationDownloaderConfiguration configuration, ReplicationState serverState,
ReplicationState initialLocalState) {
URL baseUrl;
ReplicationState localState;
Date maximumDownloadTimestamp;
localState = initialLocalState;
// Determine the location of download files.
baseUrl = configuration.getBaseUrl();
// Determine the maximum timestamp that can be downloaded.
maximumDownloadTimestamp =
calculateMaximumTimestamp(configuration, serverState.getTimestamp(), localState.getTimestamp());
LOG.fine("The maximum timestamp to be downloaded is " + maximumDownloadTimestamp + ".");
// Download all files and send their contents to the sink.
while (localState.getSequenceNumber() < serverState.getSequenceNumber()) {
File replicationFile;
long sequenceNumber;
ReplicationState fileReplicationState;
// Check to see if our local state has already reached the maximum
// allowable timestamp. This will typically occur if a job is run
// again before new data becomes available, or if an implementation
// of this class (eg. ReplicationFileMerger) is waiting for a full
// time period of data to become available before processing.
if (localState.getTimestamp().compareTo(maximumDownloadTimestamp) >= 0) {
break;
}
// Calculate the next sequence number.
sequenceNumber = localState.getSequenceNumber() + 1;
LOG.finer("Processing replication sequence " + sequenceNumber + ".");
// Get the state associated with the next file.
fileReplicationState = serverStateReader.getServerState(baseUrl, sequenceNumber);
// Ensure that the next state is within the allowable timestamp
// range. We must stop if the next data takes us beyond the maximum
// timestamp. This will either occur if a maximum download time
// duration limit has been imposed, or if a time-aligned boundary
// has been reached.
if (fileReplicationState.getTimestamp().compareTo(maximumDownloadTimestamp) > 0) {
// We will always allow at least one replication interval
// through to deal with the case where a single interval exceeds
// the maximum duration. This can happen if the source data has
// a long time gap between two intervals due to system downtime.
if (localState.getSequenceNumber() != initialLocalState.getSequenceNumber()) {