Class UndertowHttpServerConnector

java.lang.Object
org.nustaq.kontraktor.remoting.http.AbstractHttpServerConnector
org.nustaq.kontraktor.remoting.http.undertow.UndertowHttpServerConnector
All Implemented Interfaces:
io.undertow.server.HttpHandler, org.nustaq.kontraktor.remoting.base.ActorServerConnector

public class UndertowHttpServerConnector
extends AbstractHttpServerConnector
implements io.undertow.server.HttpHandler
Created by ruedi on 12.05.2015. A longpoll+shortpoll+nopoll based connector. Binary/MinBin/Json coding using POST requests is supported Algorithm/Expected client behaviour: Longpoll request is held until an event occurs or timeout. An incoming lp request reports last seen sequence in its url ../sessionId/sequence such that in case of network failure messages can be delivered more than once from a short (outgoing) message history. Regular requests are expected to come in ordered (so next request is done only if first one was replied). This is necessary due to http 1.1 limitations (multiple connections+reordering would be required otherwise). Responses to regular requests (actor messages) are piggy backed with long-poll-data if avaiable. This may lead to out of sequence long polls (network race). So a client has to implement sequence checking in order to prevent double processing of incoming messages. For shortpoll, a client sends "{ 'SP', sequence }" to indicate the poll request should return immediately. With many clients and connection limited clients (browser,mobiles) a short poll with larger intervals (>3s) might scale better at cost of latency. When used no-poll, streaming results to a callback is not supported. Only 'tellMsg' (void methods) and 'askMsg' (IPromise-returning) messages can be used. ATTENTION: parts of stuff was pulled up into an abstract class TODO: support temporary/discardable websocket connections as a LP optimization. TODO: investigate http 2.0
  • Constructor Details

  • Method Details

    • handleRequest

      public void handleRequest​(io.undertow.server.HttpServerExchange exchange) throws Exception
      if relpath is empty, this is considered as a connect/open and a session id is sent back. Else /sessionId/sequ or just /sessionId is expected posted content might contain an authentication information related object
      Specified by:
      handleRequest in interface io.undertow.server.HttpHandler
      Parameters:
      exchange -
      Throws:
      Exception
    • requestReceived

      protected void requestReceived​(io.undertow.server.HttpServerExchange exchange, byte[] postData, String path)
    • handleClientRequest

      public void handleClientRequest​(io.undertow.server.HttpServerExchange exchange, HttpObjectSocket httpObjectSocket, byte[] postData, String lastSeenSequence, String sid)
    • createLongPollTask

      protected org.nustaq.kontraktor.util.Pair<Runnable,​KHttpExchange> createLongPollTask​(KHttpExchange exchange, HttpObjectSocket httpObjectSocket, org.xnio.channels.StreamSinkChannel sinkchannel, String sid)
    • replyFromHistory

      protected void replyFromHistory​(io.undertow.server.HttpServerExchange exchange, org.xnio.channels.StreamSinkChannel sinkchannel, byte[] msg, String sid)
    • handleRegularRequest

      protected void handleRegularRequest​(io.undertow.server.HttpServerExchange exchange, HttpObjectSocket httpObjectSocket, Object[] received, org.xnio.channels.StreamSinkChannel sinkchannel, String sid)
      handle a remote method call (not a long poll)
      Parameters:
      exchange -
      httpObjectSocket -
      received -
      sinkchannel -
      sid -