diff --git a/src/main/java/io/github/chronosx88/JGUN/Dispatcher.java b/src/main/java/io/github/chronosx88/JGUN/Dispatcher.java index dafaa7b..92b41a1 100644 --- a/src/main/java/io/github/chronosx88/JGUN/Dispatcher.java +++ b/src/main/java/io/github/chronosx88/JGUN/Dispatcher.java @@ -36,7 +36,7 @@ public class Dispatcher { JSONObject ack = handlePut(message); peer.emit(ack.toString()); } - if(message.has("await")) { + if(message.has("get")) { JSONObject ack = handleGet(message); peer.emit(ack.toString()); } @@ -47,7 +47,7 @@ public class Dispatcher { } private JSONObject handleGet(JSONObject getData) { - InMemoryGraph getResults = Utils.getRequest(getData.getJSONObject("await"), graphStorage); + InMemoryGraph getResults = Utils.getRequest(getData.getJSONObject("get"), graphStorage); return new JSONObject() // Acknowledgment .put( "#", dup.track(Dup.random()) ) .put( "@", getData.getString("#") ) @@ -56,23 +56,11 @@ public class Dispatcher { } private JSONObject handlePut(JSONObject message) { - InMemoryGraph diff = HAM.mix(new InMemoryGraph(message.getJSONObject("put")), graphStorage); - if(diff != null) { - for(Map.Entry entry : diff.entries()) { - if(changeListeners.containsKey(entry.getKey())) { - changeListeners.get(entry.getKey()).onChange(entry.getValue().toUserJSONObject()); - } - if(forEachListeners.containsKey(entry.getKey())) { - for(Map.Entry jsonEntry : entry.getValue().values.toMap().entrySet()) { - forEachListeners.get(entry.getKey()).onChange(jsonEntry.getKey(), jsonEntry.getValue()); - } - } - } - } + boolean success = HAM.mix(new InMemoryGraph(message.getJSONObject("put")), graphStorage, changeListeners, forEachListeners); return new JSONObject() // Acknowledgment .put( "#", dup.track(Dup.random()) ) .put( "@", message.getString("#") ) - .put( "ok", true); + .put( "ok", success); } private void handleIncomingAck(JSONObject ack) { diff --git a/src/main/java/io/github/chronosx88/JGUN/Utils.java b/src/main/java/io/github/chronosx88/JGUN/Utils.java index ceabdae..04c8ab7 100644 --- a/src/main/java/io/github/chronosx88/JGUN/Utils.java +++ b/src/main/java/io/github/chronosx88/JGUN/Utils.java @@ -97,7 +97,7 @@ public class Utils { if(field != null) { getParameters.put(".", field); } - jsonObject.put("await", getParameters); + jsonObject.put("get", getParameters); return jsonObject; }