@Override protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) throws IOException { String payload = message.getData(); KMessage msg = KMessageLoader.load(payload); switch (msg.type()) { case KMessageLoader.GET_RES_TYPE: { GetResult getResult = (GetResult) msg; Object callbackRegistered = _callbacks.get(getResult.id); if (callbackRegistered != null) { ((KCallback) callbackRegistered).on(getResult.values); } else { System.err.println(); } _callbacks.remove(getResult.id); } break; case KMessageLoader.PUT_RES_TYPE: { PutResult putResult = (PutResult) msg; Object callbackRegistered = _callbacks.get(putResult.id); if (callbackRegistered != null) { ((KCallback) callbackRegistered).on(null); } else { System.err.println(); } } break; case KMessageLoader.ATOMIC_GET_INC_RESULT_TYPE: { AtomicGetIncrementResult atomicGetResult = (AtomicGetIncrementResult) msg; Object callbackRegistered = _callbacks.get(atomicGetResult.id); if (callbackRegistered != null) { ((KCallback) callbackRegistered).on(atomicGetResult.value); } else { System.err.println(); } } break; case KMessageLoader.EVENTS_TYPE: { Events eventsMessage = (Events) msg; this._manager.reload( eventsMessage.allKeys(), new KCallback<Throwable>() { @Override public void on(Throwable throwable) { WebSocketClient.this._localEventListeners.dispatch(eventsMessage); } }); } break; default: { System.err.println("MessageType not supported:" + msg.type()); } } }
@Override public void send(KMessage msg) { _localEventListeners.dispatch(msg); WebSockets.sendText(msg.json(), _client.getChannel(), null); }