public void handle(SockJSSocket sock) { connections.add(sock.writeHandlerID()); sock.handler(buffer -> { for (String actorID : connections) { vertx.eventBus().publish(actorID, buffer); } }); sock.endHandler(v -> connections.remove(sock.writeHandlerID())); } }));
public void handle(final SockJSSocket sock) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_CREATED, null, sock), () -> { Map<String, MessageConsumer> registrations = new HashMap<>(); sock.endHandler(v -> handleSocketClosed(sock, registrations)); sock.handler(data -> handleSocketData(sock, data, registrations)); // Start a checker to check for pings PingInfo pingInfo = new PingInfo(); pingInfo.timerID = vertx.setPeriodic(pingTimeout, id -> { if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout) { // Trigger an event to allow custom behavior before disconnecting client. checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_IDLE, null, sock), // We didn't receive a ping in time so close the socket ((SockJSSocketBase) sock)::closeAfterSessionExpired, () -> replyError(sock, "rejected")); } }); SockInfo sockInfo = new SockInfo(); sockInfo.pingInfo = pingInfo; sockInfos.put(sock, sockInfo); }, sock::close); }
public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket endHandler(Handler<Void> endHandler) { delegate.endHandler(endHandler); return this; }
public io.vertx.rxjava.ext.web.handler.sockjs.SockJSSocket endHandler(Handler<Void> endHandler) { delegate.endHandler(endHandler); return this; }
@Test public void testNoDeadlockWhenWritingFromAnotherThreadWithSseTransport() throws Exception { socketHandler = () -> { return socket -> { AtomicBoolean closed = new AtomicBoolean(); socket.endHandler(v -> { closed.set(true); testComplete(); }); new Thread(() -> { while (!closed.get()) { LockSupport.parkNanos(50); socket.write(Buffer.buffer(TestUtils.randomAlphaString(256))); } }).start(); }; }; startServers(); client.getNow("/test/400/8ne8e94a/eventsource", onSuccess(resp -> { AtomicInteger count = new AtomicInteger(); resp.handler(msg -> { if (count.incrementAndGet() == 400) { resp.request().connection().close(); } }); })); await(); }
new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> { long timerID = vertx.setPeriodic(1000, tid -> sock.write(buffer("tick!"))); sock.endHandler(v -> vertx.cancelTimer(timerID)); })); router.route("/amplify/*").handler(SockJSHandler.create(vertx,
@Override public void handle(SockJSSocket socket) { if (termHandler != null) { SockJSTtyConnection conn = new SockJSTtyConnection(charset, vertx.getOrCreateContext(), socket); socket.handler(buf -> conn.writeToDecoder(buf.toString())); socket.endHandler(v -> { Consumer<Void> closeHandler = conn.getCloseHandler(); if (closeHandler != null) { closeHandler.accept(null); } }); termHandler.handle(new TermImpl(vertx, keymap, conn)); } else { socket.close(); } } }
public void handle(final SockJSSocket sock) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_CREATED, null, sock), () -> { Map<String, MessageConsumer> registrations = new HashMap<>(); sock.endHandler(v -> handleSocketClosed(sock, registrations)); sock.handler(data -> handleSocketData(sock, data, registrations)); // Start a checker to check for pings PingInfo pingInfo = new PingInfo(); pingInfo.timerID = vertx.setPeriodic(pingTimeout, id -> { if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout) { // Trigger an event to allow custom behavior before disconnecting client. checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_IDLE, null, sock), // We didn't receive a ping in time so close the socket ((SockJSSocketBase) sock)::closeAfterSessionExpired, () -> replyError(sock, "rejected")); } }); SockInfo sockInfo = new SockInfo(); sockInfo.pingInfo = pingInfo; sockInfos.put(sock, sockInfo); }, sock::close); }
public void handle(SockJSSocket sock) { connections.add(sock.writeHandlerID()); sock.handler(buffer -> { for (String actorID : connections) { vertx.eventBus().publish(actorID, buffer); } }); sock.endHandler(v -> connections.remove(sock.writeHandlerID())); } }));
@Test public void testNoDeadlockWhenWritingFromAnotherThreadWithSseTransport() throws Exception { socketHandler = () -> { return socket -> { AtomicBoolean closed = new AtomicBoolean(); socket.endHandler(v -> { closed.set(true); testComplete(); }); new Thread(() -> { while (!closed.get()) { LockSupport.parkNanos(50); socket.write(Buffer.buffer(TestUtils.randomAlphaString(256))); } }).start(); }; }; startServers(); client.get("/test/400/8ne8e94a/eventsource", resp -> { AtomicInteger count = new AtomicInteger(); resp.handler(msg -> { if (count.incrementAndGet() == 400) { resp.request().connection().close(); } }); }).end(); await(); }
new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> { long timerID = vertx.setPeriodic(1000, tid -> sock.write(buffer("tick!"))); sock.endHandler(v -> vertx.cancelTimer(timerID)); })); router.route("/amplify/*").handler(SockJSHandler.create(vertx,