io.undertow.websockets.WebSocketConnectionCallback Java Examples
The following examples show how to use
io.undertow.websockets.WebSocketConnectionCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Term.java From termd with Apache License 2.0 | 6 votes |
synchronized HttpHandler getWebSocketHandler() { WebSocketConnectionCallback onWebSocketConnected = (exchange, webSocketChannel) -> { if (webSocketTtyConnection == null) { webSocketTtyConnection = new WebSocketTtyConnection(webSocketChannel, executor); webSocketChannel.addCloseTask((task) -> {webSocketTtyConnection.removeWebSocketChannel(); destroyIfInactiveAndDisconnected();}); TtyBridge ttyBridge = new TtyBridge(webSocketTtyConnection); ttyBridge .setProcessListener(onTaskCreated()) .readline(); } else { if (webSocketTtyConnection.isOpen()) { webSocketTtyConnection.addReadonlyChannel(webSocketChannel); webSocketChannel.addCloseTask((task) -> {webSocketTtyConnection.removeReadonlyChannel(webSocketChannel); destroyIfInactiveAndDisconnected();}); } else { webSocketTtyConnection.setWebSocketChannel(webSocketChannel); webSocketChannel.addCloseTask((task) -> {webSocketTtyConnection.removeWebSocketChannel(); destroyIfInactiveAndDisconnected();}); } } }; return new WebSocketProtocolHandshakeHandler(onWebSocketConnected); }
Example #2
Source File: Term.java From termd with Apache License 2.0 | 6 votes |
HttpHandler webSocketStatusUpdateHandler() { WebSocketConnectionCallback webSocketConnectionCallback = (exchange, webSocketChannel) -> { Consumer<TaskStatusUpdateEvent> statusUpdateListener = event -> { Map<String, Object> statusUpdate = new HashMap<>(); statusUpdate.put("action", "status-update"); statusUpdate.put("event", event); ObjectMapper objectMapper = new ObjectMapper(); try { String message = objectMapper.writeValueAsString(statusUpdate); WebSockets.sendText(message, webSocketChannel, null); } catch (JsonProcessingException e) { log.error("Cannot write object to JSON", e); String errorMessage = "Cannot write object to JSON: " + e.getMessage(); WebSockets.sendClose(CloseMessage.UNEXPECTED_ERROR, errorMessage, webSocketChannel, null); } }; log.debug("Registering new status update listener {}.", statusUpdateListener); addStatusUpdateListener(statusUpdateListener); webSocketChannel.addCloseTask((task) -> removeStatusUpdateListener(statusUpdateListener)); }; return new WebSocketProtocolHandshakeHandler(webSocketConnectionCallback); }
Example #3
Source File: WebSocketServlet.java From lams with GNU General Public License v2.0 | 4 votes |
public WebSocketServlet(WebSocketConnectionCallback callback) { this.callback = callback; this.handshakes = handshakes(); }
Example #4
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * @param sessionHandler The web socket session handler * @return The web socket handler */ public static WebSocketProtocolHandshakeHandler websocket(final WebSocketConnectionCallback sessionHandler) { return new WebSocketProtocolHandshakeHandler(sessionHandler); }
Example #5
Source File: Handlers.java From lams with GNU General Public License v2.0 | 2 votes |
/** * @param sessionHandler The web socket session handler * @param next The handler to invoke if the web socket connection fails * @return The web socket handler */ public static WebSocketProtocolHandshakeHandler websocket(final WebSocketConnectionCallback sessionHandler, final HttpHandler next) { return new WebSocketProtocolHandshakeHandler(sessionHandler, next); }