Skip to content

Commit

Permalink
Be more efficient in how we look up watched WS paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-brazil committed May 10, 2019
1 parent eb2587c commit ce53fbc
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/com/carolinarollergirls/scoreboard/jetty/WS.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.Set;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -103,7 +103,7 @@ public synchronized void onMessage(String message_data) {
if (action.equals("Register")) {
JSONArray jsonPaths = json.optJSONArray("paths");
if (jsonPaths != null) {
Set<String> newPaths = new HashSet<>();
TreeSet<String> newPaths = new TreeSet<>();
for (int i = 0; i < jsonPaths.length(); i++) {
newPaths.add(jsonPaths.getString(i));
}
Expand Down Expand Up @@ -237,17 +237,15 @@ public synchronized void sendUpdates(Map<String, Object> state, Set<String> chan
sendWSUpdatesForPaths(paths, changed);
}

private void sendWSUpdatesForPaths(Set<String> watchedPaths, Set<String> changed) {
private void sendWSUpdatesForPaths(TreeSet<String> watchedPaths, Set<String> changed) {
Map<String, Object> updates = new HashMap<>();
for (String k: changed) {
for (String p : watchedPaths) {
if (k.startsWith(p)) {
if (state.get(k) == null) {
updates.put(k, JSONObject.NULL);
} else {
updates.put(k, state.get(k));
}
break;
String p = watchedPaths.floor(k);
if (p != null && k.startsWith(p)) {
if (state.get(k) == null) {
updates.put(k, JSONObject.NULL);
} else {
updates.put(k, state.get(k));
}
}
}
Expand All @@ -266,7 +264,7 @@ private void sendWSUpdatesForPaths(Set<String> watchedPaths, Set<String> changed
}

protected UUID id;
protected Set<String> paths = new HashSet<>();
protected TreeSet<String> paths = new TreeSet<>();
private Map<String, Object> state;
}
}

0 comments on commit ce53fbc

Please sign in to comment.