Example usage for org.springframework.web.socket.sockjs.client WebSocketClientSockJsSession getTimeoutTask

List of usage examples for org.springframework.web.socket.sockjs.client WebSocketClientSockJsSession getTimeoutTask

Introduction

In this page you can find the example usage for org.springframework.web.socket.sockjs.client WebSocketClientSockJsSession getTimeoutTask.

Prototype

Runnable getTimeoutTask() 

Source Link

Document

Return a timeout cleanup task to invoke if the SockJS sessions is not fully established within the retransmission timeout period calculated in SockJsRequest based on the duration of the initial SockJS "Info" request.

Usage

From source file:org.springframework.web.socket.sockjs.client.WebSocketTransport.java

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
    final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<>();
    WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
    handler = new ClientSockJsWebSocketHandler(session);
    request.addTimeoutTask(session.getTimeoutTask());

    URI url = request.getTransportUrl();
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
    if (logger.isDebugEnabled()) {
        logger.debug("Starting WebSocket session on " + url);
    }/*from w ww .  ja v a 2 s  .  com*/
    this.webSocketClient.doHandshake(handler, headers, url)
            .addCallback(new ListenableFutureCallback<WebSocketSession>() {
                @Override
                public void onSuccess(@Nullable WebSocketSession webSocketSession) {
                    // WebSocket session ready, SockJS Session not yet
                }

                @Override
                public void onFailure(Throwable ex) {
                    future.setException(ex);
                }
            });
    return future;
}