@Override public SockJSHandler bridge(BridgeOptions bridgeOptions, Handler<BridgeEvent> bridgeEventHandler) { socketHandler(new EventBusBridgeImpl(vertx, bridgeOptions, bridgeEventHandler)); return this; }
@Override public void sessionClosed() { session.writeClosed(this); close(); } }
synchronized boolean handleMessages(String messages) { String[] msgArr = parseMessageString(messages); if (msgArr == null) { return false; } handleMessages(msgArr); return true; }
private void registerHandler(Router router, Handler<SockJSSocket> sockHandler, String re, boolean streaming, SockJSHandlerOptions options) { router.postWithRegex(re).handler(rc -> { if (log.isTraceEnabled()) log.trace("XHR, post, " + rc.request().uri()); setNoCacheHeaders(rc); String sessionID = rc.request().getParam("param0"); SockJSSession session = getSession(rc, options.getSessionTimeout(), options.getHeartbeatInterval(), sessionID, sockHandler); HttpServerRequest req = rc.request(); session.register(req, streaming? new XhrStreamingListener(options.getMaxBytesStreaming(), rc, session) : new XhrPollingListener(rc, session)); }); }
private void internalHandleSendOrPub(SockJSSocket sock, boolean send, JsonObject msg) { checkCallHook(() -> new BridgeEventImpl(send ? BridgeEventType.SEND : BridgeEventType.PUBLISH, msg, sock), () -> { String address = msg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } doSendOrPub(send, sock, address, msg); }, () -> replyError(sock, "rejected")); }
private void handleMessages(String msgs) { if (!session.isClosed()) { if (msgs.equals("") || msgs.equals("[]")) { //Ignore empty frames } else if ((msgs.startsWith("[\"") && msgs.endsWith("\"]")) || (msgs.startsWith("\"") && msgs.endsWith("\""))) { session.handleMessages(msgs); } else { //Invalid JSON - we close the connection close(); } } }
private void setTimer() { if (timeout != -1) { cancelTimer(); timeoutTimerID = vertx.setTimer(timeout, id1 -> { vertx.cancelTimer(heartbeatID); if (listener == null) { shutdown(); } if (listener != null) { listener.close(); } }); } }
private synchronized void doClose() { Context ctx = transportCtx; if (ctx != Vertx.currentContext()) { ctx.runOnContext(v -> doClose()); } else { if (listener != null && handleCalled) { listener.sessionClosed(); } } }
private synchronized void writePendingMessages() { if (listener != null) { String json = JsonCodec.encode(pendingWrites.toArray()); listener.sendFrame("a" + json); pendingWrites.clear(); messagesSize = 0; if (drainHandler != null) { Handler<Void> dh = drainHandler; drainHandler = null; context.runOnContext(dh); } } }
@Override public void end() { close(); }
synchronized void resetListener() { listener = null; // We set a timer that will kick in and close the session if the client doesn't come back // We MUST ALWAYS do this or we can get a memory leak on the server setTimer(); }
private synchronized void writeOpen(TransportListener lst) { lst.sendFrame("o"); openWritten = true; } }
/** * Create a SockJS handler * * @param vertx the Vert.x instance * @param options options to configure the handler * @return the handler */ static SockJSHandler create(Vertx vertx, SockJSHandlerOptions options) { return new SockJSHandlerImpl(vertx, options); }
@Override public SockJSHandler bridge(BridgeOptions bridgeOptions) { return bridge(bridgeOptions, null); }
public void closeAfterSessionExpired() { this.close((short) 1001, "Session expired"); }
void writeClosed(TransportListener lst) { writeClosed(lst, 3000, "Go away!"); }
@Override public MultiMap headers() { if (headers == null) { headers = BaseTransport.removeCookieHeaders(ws.headers()); } return headers; }
JsonPListener(RoutingContext rc, SockJSSession session, String callback) { super(rc, session); this.callback = callback; addCloseHandler(rc.response(), session); }
public void closeAfterSessionExpired() { close(); }