Example usage for org.springframework.web.socket.sockjs.client TransportRequest addTimeoutTask

List of usage examples for org.springframework.web.socket.sockjs.client TransportRequest addTimeoutTask

Introduction

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

Prototype

void addTimeoutTask(Runnable runnable);

Source Link

Document

Register a timeout cleanup task to invoke if the SockJS session is not fully established within the calculated retransmission timeout period.

Usage

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

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
    SettableListenableFuture<WebSocketSession> connectFuture = new SettableListenableFuture<>();
    XhrClientSockJsSession session = new XhrClientSockJsSession(request, handler, this, connectFuture);
    request.addTimeoutTask(session.getTimeoutTask());

    URI receiveUrl = request.getTransportUrl();
    if (logger.isDebugEnabled()) {
        logger.debug("Starting XHR " + (isXhrStreamingDisabled() ? "Polling" : "Streaming") + "session url="
                + receiveUrl);// w w w .  j  av  a2 s  .  c  o m
    }

    HttpHeaders handshakeHeaders = new HttpHeaders();
    handshakeHeaders.putAll(request.getHandshakeHeaders());

    connectInternal(request, handler, receiveUrl, handshakeHeaders, session, connectFuture);
    return connectFuture;
}

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   ww  w  .j a  v a 2  s  .  co m
    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;
}