Search in sources :

Example 1 with Delete

use of org.structr.cloud.message.Delete in project structr by structr.

the class SyncTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    int count = 0;
    try (final Tx tx = StructrApp.getInstance().tx()) {
        for (final ModificationEvent event : transaction) {
            final GraphObject graphObject = event.getGraphObject();
            if (event.isDeleted()) {
                final String id = event.getRemovedProperties().get(GraphObject.id);
                if (id != null) {
                    client.send(new Delete(id));
                }
            } else {
                try {
                    final Set<String> propertyKeys = new LinkedHashSet<>();
                    // collect all possibly modified property keys
                    mapPropertyKeysToStrings(propertyKeys, event.getNewProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getModifiedProperties().keySet());
                    mapPropertyKeysToStrings(propertyKeys, event.getRemovedProperties().keySet());
                    if (graphObject.isNode()) {
                        if (graphObject instanceof File) {
                            sendFile(client, (File) graphObject, CloudService.CHUNK_SIZE);
                        } else {
                            client.send(new NodeDataContainer(graphObject.getSyncNode(), count, propertyKeys));
                        }
                    } else {
                        client.send(new RelationshipDataContainer(graphObject.getSyncRelationship(), count, propertyKeys));
                    }
                } catch (NotFoundException nfex) {
                    logger.info("Trying to synchronize deleted entity, ignoring");
                }
            }
            count++;
        }
        tx.success();
    }
    // synchronize last sync timestamp with slave instance
    // (we're sending out own instance ID (master) for the slave to store)
    final String masterId = StructrApp.getInstance().getInstanceId();
    client.send(new ReplicationStatus(masterId, StructrApp.getInstance().getGlobalSetting(masterId + ".lastModified", 0L)));
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : Delete(org.structr.cloud.message.Delete) LinkedHashSet(java.util.LinkedHashSet) Tx(org.structr.core.graph.Tx) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) ModificationEvent(org.structr.core.graph.ModificationEvent) File(org.structr.dynamic.File)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 NotFoundException (org.structr.api.NotFoundException)1 Delete (org.structr.cloud.message.Delete)1 FileNodeDataContainer (org.structr.cloud.message.FileNodeDataContainer)1 NodeDataContainer (org.structr.cloud.message.NodeDataContainer)1 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)1 GraphObject (org.structr.core.GraphObject)1 ModificationEvent (org.structr.core.graph.ModificationEvent)1 Tx (org.structr.core.graph.Tx)1 File (org.structr.dynamic.File)1