use of org.structr.cloud.message.Finish in project structr by structr.
the class ReplicationStatus method onRequest.
@Override
public void onRequest(CloudConnection serverConnection) throws IOException, FrameworkException {
final App app = StructrApp.getInstance();
this.slaveId = app.getInstanceId();
if (update) {
// this is not an error, we want the sync time for the
// given MASTER, since a slave can have multiple masters
app.setGlobalSetting(masterId, lastSync);
} else {
// this is not an error, we want the sync time for the
// given MASTER, since a slave can have multiple masters
this.lastSync = app.getGlobalSetting(masterId, 0L);
this.role = Settings.getOrCreateStringSetting("sync", "role").getValue("slave");
}
serverConnection.send(this);
serverConnection.send(new Finish());
}
use of org.structr.cloud.message.Finish in project structr by structr.
the class Synchronize method onRequest.
@Override
public void onRequest(final CloudConnection serverConnection) throws IOException, FrameworkException {
final DatabaseService graphDb = StructrApp.getInstance().getDatabaseService();
final String uuidPropertyName = GraphObject.id.dbName();
final Set<Long> visitedObjectIDs = new HashSet<>();
for (final Node node : graphDb.getAllNodes()) {
if (!visitedObjectIDs.contains(node.getId())) {
final String hash = contentHashCode(node, visitedObjectIDs);
final Object uuid = node.getProperty(uuidPropertyName, null);
if (uuid != null && uuid instanceof String) {
serverConnection.send(new Diff(uuid.toString(), hash));
}
}
}
// clear set of visited objects because node and relationship IDs are offsets and can overlap.
visitedObjectIDs.clear();
for (final Relationship relationship : graphDb.getAllRelationships()) {
if (!visitedObjectIDs.contains(relationship.getId())) {
final String hash = contentHashCode(relationship, visitedObjectIDs);
final Object uuid = relationship.getProperty(uuidPropertyName, null);
if (uuid != null && uuid instanceof String) {
serverConnection.send(new Diff(uuid.toString(), hash));
}
}
}
serverConnection.send(new Finish());
}
Aggregations