MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / onMessage

Method onMessage

src/main/java/fielded/webserver/Server.java:147–180  ·  view source on GitHub ↗
(WebSocket webSocket, String s)

Source from the content-addressed store, hash-verified

145
146 Log.log("remote.trace", () -> " message:<" + s + ">");
147 JSONObject o = new JSONObject(s);
148 String address = o.getString("address");
149 Object payload = o.get("payload");
150 Object originalPayload = payload;
151
152 for (Handler h : new ArrayList<>(handlers)) {
153 if (h instanceof HandlerInMainThread) {
154 if (((HandlerInMainThread) h).will(Server.this, webSocket, address, payload)) {
155 final Object p = payload;
156 Server.this.queue(new Runnable() {
157 @Override
158 public void run() {
159 currentWebSocket.set(webSocket);
160 h.handle(Server.this, webSocket, address, p);
161
162 }
163 });
164 // not threading these all through the main thread means that we don't get backlogged nearly as easily
165
166// } catch (InterruptedException | ExecutionException e) {
167// Log.log("remote.error", " exception thrown by asynchronous websocket handler <" + h + "> while servicing <" + s + " / " + address + "
168// ->" + originalPayload + " " + p, e);
169// }
170 }
171 } else {
172 currentWebSocket.set(webSocket);
173 payload = h.handle(Server.this, webSocket, address, payload);
174 }
175 }
176 }
177
178 @Override
179 public void onError(WebSocket webSocket, Exception e) {
180 Log.log("remote.error", () -> " websocket error reported :" + e);
181 e.printStackTrace();
182 }
183

Callers

nothing calls this directly

Calls 7

logMethod · 0.95
getStringMethod · 0.80
queueMethod · 0.80
getMethod · 0.65
willMethod · 0.65
setMethod · 0.65
handleMethod · 0.65

Tested by

no test coverage detected