* {@inheritDoc}
*/
@Override
protected void processChangeset(XmlChangeReader xmlReader, ReplicationState replicationState) {
int intervalLength;
ReplicationFileMergerConfiguration configuration;
configuration = getConfiguration();
// Get the configured interval length.
intervalLength = configuration.getIntervalLength();
// If this is the first time through, initialise a writer for the next
// sequence number.
if (!sinkActive) {
// Increment the current sequence number.
currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1);
// Initialise an output file for the new sequence number.
LOG.finer("Opening change sink for interval with sequence number " + currentDataState.getSequenceNumber());
changeSink = buildResultWriter(currentDataState.getSequenceNumber());
}
if (intervalLength > 0) {
// If this is the first time through, align the timestamp at the
// next boundary.
if (!sinkActive) {
Date intervalEnd;
intervalEnd = new Date(currentDataState.getTimestamp().getTime() + intervalLength);
intervalEnd = alignDateToIntervalBoundary(intervalEnd, intervalLength);
currentDataState.setTimestamp(intervalEnd);
LOG.finer("End of current interval is " + intervalEnd);
}
// If the replication state has moved us past the current interval
// end point we need to
// open a new interval. This may occur many times if the current
// replication state moves
// us past several intervals.
while (replicationState.getTimestamp().compareTo(currentDataState.getTimestamp()) > 0) {
// If we have an open changeset writer, close it and save the
// current state.
LOG.finer("Closing change sink for interval with sequence number "
+ currentDataState.getSequenceNumber());
changeSink.complete();
changeSink.release();
replicationStore.saveState(currentDataState);
// Update the state to match the next interval.
currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1);
currentDataState.setTimestamp(new Date(currentDataState.getTimestamp().getTime()
+ configuration.getIntervalLength()));
// Begin a new interval.
LOG.finer("Opening change sink for interval with sequence number "
+ currentDataState.getSequenceNumber());
changeSink = buildResultWriter(currentDataState.getSequenceNumber());