Search in sources :

Example 11 with PseudoTime

use of org.structr.net.data.time.PseudoTime in project structr by structr.

the class DefaultRepositoryObject method getProperties.

@Override
public Map<String, Object> getProperties(final PseudoTime instant, final String transactionId) {
    final Map<String, Object> map = new HashMap<>();
    // do backwards search
    final List<PseudoTime> times = new LinkedList<>(history.keySet());
    Collections.reverse(times);
    for (final PseudoTime time : times) {
        if (time.equals(instant) || time.before(instant)) {
            final PossibleValue val = history.get(time);
            if (val.isComplete(transactionId)) {
                for (final Entry<String, Object> entry : val.getData().entrySet()) {
                    if (!map.containsKey(entry.getKey())) {
                        map.put(entry.getKey(), entry.getValue());
                    }
                }
            } else if (val.isAborted()) {
                // remove aborted history entries
                history.remove(time);
            }
        }
    }
    return map;
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 12 with PseudoTime

use of org.structr.net.data.time.PseudoTime in project structr by structr.

the class History method deserialize.

@Override
public void deserialize(final DataInputStream dis) throws IOException {
    super.deserialize(dis);
    // dis.readUTF();
    this.recipient = deserializeUUID(dis);
    // dis.readUTF();
    this.objectId = deserializeUUID(dis);
    this.userId = dis.readUTF();
    this.type = dis.readUTF();
    this.creationTime = new PseudoTime();
    this.creationTime.deserialize(dis);
    this.lastModified = new PseudoTime();
    this.lastModified.deserialize(dis);
    final int size = dis.readInt();
    for (int i = 0; i < size; i++) {
        try {
            final String key = dis.readUTF();
            final Object value = deserializeObject(dis);
            data.put(key, value);
        } catch (Throwable t) {
            logger.warn("", t);
        }
    }
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime) RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 13 with PseudoTime

use of org.structr.net.data.time.PseudoTime in project structr by structr.

the class PeerToPeerService method create.

// ----- repository connection -----
public void create(final SharedNodeInterface sharedNode) {
    final String uuid = sharedNode.getUuid();
    final String type = sharedNode.getType();
    final String user = sharedNode.getUserId();
    final PseudoTime time = sharedNode.getCreationPseudoTime();
    logger.info("Shared node with UUID {} CREATED in Structr at {}", new Object[] { sharedNode.getUuid(), time.toString() });
    repository.create(uuid, type, peer.getUuid(), user, time, sharedNode.getData());
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime)

Example 14 with PseudoTime

use of org.structr.net.data.time.PseudoTime in project structr by structr.

the class PeerToPeerService method addObjectToRepository.

public void addObjectToRepository(final SharedNodeInterface node) {
    final String objectId = node.getProperty(GraphObject.id);
    final String objectType = node.getProperty(GraphObject.type);
    final PseudoTime modified = node.getLastModificationPseudoTime();
    final PseudoTime created = node.getCreationPseudoTime();
    final String transactionId = NodeServiceCommand.getNextUuid();
    final RepositoryObject obj = repository.add(objectId, objectType, peer.getUuid(), node.getUserId(), created);
    for (final Entry<String, Object> entry : node.getData().entrySet()) {
        obj.setProperty(modified, transactionId, entry.getKey(), entry.getValue());
    }
    repository.complete(transactionId);
    // add update listener
    obj.addListener(new ObjectUpdater(objectId));
}
Also used : PseudoTime(org.structr.net.data.time.PseudoTime) RepositoryObject(org.structr.net.repository.RepositoryObject) RepositoryObject(org.structr.net.repository.RepositoryObject) GraphObject(org.structr.core.GraphObject)

Aggregations

PseudoTime (org.structr.net.data.time.PseudoTime)14 RepositoryObject (org.structr.net.repository.RepositoryObject)4 LinkedList (java.util.LinkedList)2 GraphObject (org.structr.core.GraphObject)2 HashMap (java.util.HashMap)1