本文整理汇总了Java中io.undertow.websockets.WebSocketConnectionCallback类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketConnectionCallback类的具体用法?Java WebSocketConnectionCallback怎么用?Java WebSocketConnectionCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketConnectionCallback类属于io.undertow.websockets包,在下文中一共展示了WebSocketConnectionCallback类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWebSocketHandler
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
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);
}
示例2: webSocketStatusUpdateHandler
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
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);
}
示例3: end
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
@Test
public void end() throws Exception {
new MockUnit(HttpServerExchange.class, NativeWebSocket.class,
WebSocketProtocolHandshakeHandler.class)
.expect(unit -> {
HttpServerExchange exchange = unit.get(HttpServerExchange.class);
NativeWebSocket ws = unit.get(NativeWebSocket.class);
expect(exchange.getAttachment(UndertowRequest.SOCKET)).andReturn(ws);
expect(exchange.removeAttachment(UndertowRequest.SOCKET)).andReturn(null);
expect(exchange.endExchange()).andReturn(exchange);
})
.expect(unit -> {
WebSocketProtocolHandshakeHandler wsphh = unit
.get(WebSocketProtocolHandshakeHandler.class);
wsphh.handleRequest(unit.get(HttpServerExchange.class));
expectLastCall().andThrow(new IllegalStateException("intentional err"));
unit.mockStatic(Handlers.class);
expect(Handlers.websocket(isA(WebSocketConnectionCallback.class))).andReturn(wsphh);
})
.run(unit -> {
new UndertowResponse(unit.get(HttpServerExchange.class)).end();
});
}
示例4: WebSocketServlet
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
public WebSocketServlet(WebSocketConnectionCallback callback) {
this.callback = callback;
this.handshakes = handshakes();
}
示例5: addWebsocket
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
public void addWebsocket(String path, WebSocketConnectionCallback callback) {
wsRoutingHandler.add(Methods.GET, path, new WebSocketProtocolHandshakeHandler(callback, routingHandler));
}
示例6: websocket
import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
/**
* @param sessionHandler The web socket session handler
* @return The web socket handler
*/
public static WebSocketProtocolHandshakeHandler websocket(final WebSocketConnectionCallback sessionHandler) {
return new WebSocketProtocolHandshakeHandler(sessionHandler);
}