| 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 | |