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);
}
}
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()));
}
}
}
}
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();
}
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)));
}
// }
}
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)));
}
}
}
Aggregations