Search in sources :

Example 6 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Peer method set.

public void set(final String objectId, final String key, final Object value) {
    final RepositoryObject sharedObject = repository.getObject(objectId);
    if (sharedObject != null) {
        try (final RemoteTransaction tx = beginTx(sharedObject)) {
            tx.setProperty(sharedObject, key, value);
            tx.commit();
        } catch (Exception tex) {
            System.out.println("Failed");
        }
    } else {
        System.out.println("No such object " + objectId);
    }
}
Also used : RemoteTransaction(org.structr.net.data.RemoteTransaction) RepositoryObject(org.structr.net.repository.RepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) TimeoutException(org.structr.net.data.TimeoutException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Peer method onPeerDiscovery.

public void onPeerDiscovery(final PeerInfo newPeer, final byte[] hash) {
    if (newPeer != null && !newPeer.getUuid().equals(getUuid())) {
        final boolean isNew = addPeer(newPeer);
        final byte[] contentHash = getContentHash();
        final boolean hasChanged = !Arrays.equals(hash, contentHash);
        if (isNew || hasChanged) {
            if (isNew) {
                System.out.println("Peer is new, sending inventory..");
            }
            if (hasChanged) {
                System.out.println("Peer has different content hash, sending inventory..");
                System.out.println(printHash(hash) + " / " + printHash(contentHash));
            }
            // send inventory
            for (final RepositoryObject obj : repository.getObjects()) {
                log("Inventory(", obj.getUuid(), ", ", obj.getUserId(), ")");
                send(newPeer, new Inventory(repository.getUuid(), obj.getUuid(), obj.getDeviceId(), obj.getLastModificationTime()));
            }
        }
    }
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject) Inventory(org.structr.net.protocol.Inventory)

Example 8 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Peer method printInfo.

public synchronized void printInfo() {
    System.out.println("#########################################");
    System.out.println("Peer " + serverSocket.getLocalAddress() + ":" + localPort);
    System.out.println("UUID: " + getUuid());
    System.out.println("Time offset: " + timeOffset);
    System.out.println(received + " messages received, " + sent + " messages sent");
    System.out.println(peers.size() + " peers");
    for (final PeerInfo info : peers.values()) {
        System.out.println("    " + info);
    }
    for (final RepositoryObject obj : repository.getObjects()) {
        System.out.println("        ##### " + obj.getUuid());
        System.out.println("        " + obj.getType() + "(" + obj.getUserId() + "): " + obj.getProperties(pte.next()));
        ((DefaultRepositoryObject) obj).printHistory();
    }
    System.out.println(outputQueue);
    System.out.flush();
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject)

Example 9 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Set method onMessage.

@Override
public void onMessage(Peer peer, PeerInfo sender) {
    // if (!peer.getUuid().equals(getSender())) {
    final RepositoryObject obj = peer.getRepository().getObject(objectId);
    if (obj != null) {
        obj.setProperty(time, transactionId, key, value);
        if (peer.getUuid().equals(recipient)) {
            // confirm reception
            peer.broadcast(new Ack(peer.getUuid(), getSender(), getId()));
        }
    } else {
        peer.log("Unknown object ", objectId, ", requesting full history..");
        // object is missing, contact owner and fetch history from beginning of time
        peer.broadcast(new GetHistory(peer.getUuid(), recipient, objectId, PseudoTime.now(peer)));
    }
// }
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject)

Example 10 with RepositoryObject

use of org.structr.net.repository.RepositoryObject in project structr by structr.

the class Get method onMessage.

@Override
public void onMessage(Peer peer, PeerInfo sender) {
    if (peer.getUuid().equals(recipient)) {
        final RepositoryObject obj = peer.getRepository().getObject(objectId);
        final Object value = obj.getProperty(time, transactionId, key);
        peer.broadcast(new Value(peer.getUuid(), getSender(), getId(), value));
    } else {
        final RepositoryObject obj = peer.getRepository().getObject(objectId);
        if (obj == null) {
            // object is missing, contact owner and fetch history from beginning of time
            peer.log("Unknown object ", objectId, ", requesting full history..");
            peer.broadcast(new GetHistory(peer.getUuid(), recipient, objectId, PseudoTime.now(peer)));
        }
    }
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject) RepositoryObject(org.structr.net.repository.RepositoryObject)

Aggregations

RepositoryObject (org.structr.net.repository.RepositoryObject)14 DefaultRepositoryObject (org.structr.net.repository.DefaultRepositoryObject)4 GraphObject (org.structr.core.GraphObject)3 PseudoTime (org.structr.net.data.time.PseudoTime)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 FrameworkException (org.structr.common.error.FrameworkException)2 RemoteTransaction (org.structr.net.data.RemoteTransaction)2 Repository (org.structr.net.repository.Repository)2 MessageDigest (java.security.MessageDigest)1 LinkedList (java.util.LinkedList)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 Tx (org.structr.core.graph.Tx)1 PropertyKey (org.structr.core.property.PropertyKey)1 TimeoutException (org.structr.net.data.TimeoutException)1 Inventory (org.structr.net.protocol.Inventory)1 ConfigurationProvider (org.structr.schema.ConfigurationProvider)1