use of org.openstreetmap.osmosis.replication.common.ReplicationState in project osmosis by openstreetmap.
the class ReplicationLagReader method getLag.
/**
* Calculate the replication lag and print it to stdout
*/
private void getLag() {
ReplicationDownloaderConfiguration configuration;
ReplicationState serverState;
ReplicationState localState;
PropertiesPersister localStatePersistor;
// Instantiate utility objects.
configuration = new ReplicationDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
// Obtain the server state.
LOG.fine("Reading current server state.");
serverState = serverStateReader.getServerState(configuration.getBaseUrl());
// Build the local state persister which is used for both loading and storing local state.
localStatePersistor = new PropertiesPersister(new File(workingDirectory, LOCAL_STATE_FILE));
// If local state isn't available we need to fail because no lag can be calculated.
if (!localStatePersistor.exists()) {
throw new OsmosisRuntimeException("Can't read local state.");
}
// fetch the local state from the file
localState = new ReplicationState(localStatePersistor.loadMap());
// extract the time of the local and the remote state files
long local = localState.getTimestamp().getTime();
long server = serverState.getTimestamp().getTime();
// we assume the server being before the local state while calculating the difference
long lag = (server - local) / 1000;
// check if a human readable version is requested
if (this.humanReadable) {
if (lag > 86400) {
// more than a day
Object[] args = { new Long(lag / 86400), new Long((lag % 86400) / 3600) };
System.out.println(new MessageFormat("{0} day(s) and {1} hour(s)").format(args));
} else if (lag > 3600) {
// morte than an hour
Object[] args = { new Long(lag / 3600), new Long((lag % 3600) / 60) };
System.out.println(new MessageFormat("{0} hour(s) and {1} minute(s)").format(args));
} else if (lag > 60) {
// more than a minute
Object[] args = { new Long(lag / 60), new Long(lag % 60) };
System.out.println(new MessageFormat("{0} minute(s) and {1} second(s)").format(args));
} else {
Object[] args = { new Long(lag) };
// just some seconds
System.out.println(new MessageFormat("{0} second(s)").format(args));
}
} else {
// print out the raw number of seconds
System.out.println(lag);
}
}
use of org.openstreetmap.osmosis.replication.common.ReplicationState in project osmosis by openstreetmap.
the class ReplicationSequenceServerTest method testStartupShutdown.
/**
* Very basic test that launches the server, runs several replication
* iterations and then shuts down without connecting any clients.
*
* @throws InterruptedException
* if processing is interrupted.
*/
@Test
public void testStartupShutdown() throws InterruptedException {
ReplicationSequenceServer server;
server = new ReplicationSequenceServer(0);
server.setChangeSink(new MockReplicationDestination());
try {
for (int i = 0; i < 10; i++) {
ReplicationState state = new ReplicationState();
Map<String, Object> metaData = new HashMap<String, Object>();
metaData.put(ReplicationState.META_DATA_KEY, state);
server.initialize(metaData);
Thread.sleep(10);
server.complete();
}
} finally {
server.close();
}
}
use of org.openstreetmap.osmosis.replication.common.ReplicationState in project osmosis by openstreetmap.
the class ReplicationDataServerHandler method getReplicationState.
private ReplicationState getReplicationState(long sequenceNumber) {
PropertiesPersister persister = new PropertiesPersister(getStateFile(sequenceNumber));
ReplicationState state = new ReplicationState();
state.load(persister.loadMap());
return state;
}
use of org.openstreetmap.osmosis.replication.common.ReplicationState in project osmosis by openstreetmap.
the class ReplicationDataClientHandler method loadState.
private ReplicationState loadState(File stateFile) {
PropertiesPersister persister = new PropertiesPersister(stateFile);
ReplicationState state = new ReplicationState();
state.load(persister.loadMap());
return state;
}
use of org.openstreetmap.osmosis.replication.common.ReplicationState in project osmosis by openstreetmap.
the class ReplicationDataClientHandler method invokeSinkInit.
private void invokeSinkInit() {
replicationState = new ReplicationState();
Map<String, Object> metaData = new HashMap<String, Object>(1);
metaData.put(ReplicationState.META_DATA_KEY, replicationState);
changeSink.initialize(metaData);
sinkInitInvoked = true;
}
Aggregations