当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketConnectionCallback类代码示例

本文整理汇总了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);
}
 
开发者ID:termd,项目名称:termd,代码行数:22,代码来源:Term.java

示例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);
}
 
开发者ID:termd,项目名称:termd,代码行数:25,代码来源:Term.java

示例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();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:25,代码来源:UndertowResponseTest.java

示例4: WebSocketServlet

import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
public WebSocketServlet(WebSocketConnectionCallback callback) {
    this.callback = callback;
    this.handshakes = handshakes();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:WebSocketServlet.java

示例5: addWebsocket

import io.undertow.websockets.WebSocketConnectionCallback; //导入依赖的package包/类
public void addWebsocket(String path, WebSocketConnectionCallback callback) {
    wsRoutingHandler.add(Methods.GET, path, new WebSocketProtocolHandshakeHandler(callback, routingHandler));
}
 
开发者ID:undertow-io,项目名称:undertow.js,代码行数:4,代码来源:UndertowJS.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:Handlers.java


注:本文中的io.undertow.websockets.WebSocketConnectionCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。