Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // This software is released into the Public Domain.  See copying.txt for details.
  package org.openstreetmap.osmosis.replication.v0_6;
  
  import java.io.File;
  import java.util.Map;
  
This class manages persistence of state for replication streams into a state properties file. If used alone, it will store the state for a replication pipeline, and will discard the output. It can be used within a larger task performing processing on the replication data. It supports the initialize and complete method being called multiple times to signify multiple replication intervals being called within a single pipeline run.

Author(s):
Brett Henderson
 
 public class ReplicationStateWriter implements ChangeSink {
 
 	private static final Logger LOG = Logger.getLogger(ReplicationStateWriter.class.getName());
 	private static final String LOCK_FILE = "replicate.lock";
 	private static final String STATE_FILE = "state.txt";
 
 	private boolean lockObtained;
 	private ReplicationState state;


Creates a new instance.

Parameters:
workingDirectory The directory containing configuration and tracking files.
 
 	public ReplicationStateWriter(File workingDirectory) {
 		// Create the lock object used to ensure only a single process attempts
 		// to write to the data directory.
 		 = new FileBasedLock(new File(workingDirectory));
 
 		// Create the object used to persist current state.
 		 = new PropertiesPersister(new File(workingDirectory));
 	}
 
 
 	public void initialize(Map<StringObjectmetaData) {
 		if () {
 			throw new OsmosisRuntimeException("initialize has already been called");
 		}
 
 		// Lock the working directory.
 		 = true;
 
 		// Get the replication state from the upstream task.
 			throw new OsmosisRuntimeException("No replication state has been provided in metadata key "
 		}
 
 		// Populate the state from the existing state if it exists.
 		if (.exists()) {
 
 			// The current sequence number must now be incremented.
 
 				.finer("Replication sequence number is " + .getSequenceNumber() + ".");
 			}
 		}
 	}
 
 
 	public void process(ChangeContainer change) {
 		if (!) {
 			throw new OsmosisRuntimeException("initialize has not been called");
 		}
 
 		if (.getSequenceNumber() == 0) {
 			throw new OsmosisRuntimeException("No changes can be included for replication sequence 0.");
 		}
 	}
 
 
 	public void complete() {
		if (!) {
			throw new OsmosisRuntimeException("initialize has not been called");
		}
		// Write the global state file.
		 = null;
		// Release the lock.
		 = false;
	}
	public void release() {
		 = null;
		 = false;
	}
New to GrepCode? Check out our FAQ X