Search in sources :

Example 1 with Finish

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());
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Finish(org.structr.cloud.message.Finish)

Example 2 with 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());
}
Also used : Node(org.structr.api.graph.Node) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) DatabaseService(org.structr.api.DatabaseService) Finish(org.structr.cloud.message.Finish) HashSet(java.util.HashSet)

Aggregations

Finish (org.structr.cloud.message.Finish)2 HashSet (java.util.HashSet)1 DatabaseService (org.structr.api.DatabaseService)1 Node (org.structr.api.graph.Node)1 Relationship (org.structr.api.graph.Relationship)1 GraphObject (org.structr.core.GraphObject)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1