Interface ISseService


  • public interface ISseService
    • Method Summary

      Modifier and Type Method Description
      java.util.concurrent.Future<SseEvent> broadcast​(SseEvent event, java.util.Map<java.nio.channels.SocketChannel,​javax.net.ssl.SSLEngine> channels)
      Broadcasts the SseEvent asynchronously to the channels.
      java.util.List<SseEvent> decode​(java.nio.ByteBuffer buffer, boolean isChunked)
      Reads SseEvents from the ByteBuffer.
      java.nio.ByteBuffer encode​(SseEvent... events)
      Encodes the SseEvents into a ByteBuffer.
      com.airepublic.http.common.HttpResponse getHandshakeResponse()
      Gets the handshake HttpResponse to the client.
      com.airepublic.http.common.HttpRequest handshake​(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine)
      Performs an initial handshake for incoming requests.
      com.airepublic.http.common.HttpResponse outboundHandshake​(java.net.URI uri, java.nio.channels.Selector selector, java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine, java.util.function.Consumer<SseEvent> consumer)
      Performs the client handshake with the server found under the specified URI.
      void processRequest​(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLContext sslContext, ISseRegistry sseRegistry)
      Processes the whole lifecycle of an SseProducer.
      java.util.concurrent.Future<java.lang.Void> receive​(java.net.URI uri, java.util.function.Consumer<SseEvent> consumer)
      Receives SseEvents asynchronously from the URI specified in the SseConsumer and notifies the Consumer when an event has been read.
      java.util.concurrent.Future<SseEvent> send​(SseEvent event, java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine)
      Sends the SseEvent asynchronously to the channel.
      void sendHandshakeResponse​(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine)
      Sends the handshake response to the client.
    • Method Detail

      • processRequest

        void processRequest​(java.nio.channels.SocketChannel channel,
                            javax.net.ssl.SSLContext sslContext,
                            ISseRegistry sseRegistry)
        Processes the whole lifecycle of an SseProducer.
        • accepting the incoming request
        • sending the handshake response
        • sending SseEvents by calling the associated SseProducer method
        • respecting delay and maximum times configured in the SseProducer annotation
        Parameters:
        channel - the freshly accepted SocketChannel
        sslContext - the SSLContext
        sseRegistry - the ISseRegistry where the producer is registered
      • handshake

        com.airepublic.http.common.HttpRequest handshake​(java.nio.channels.SocketChannel channel,
                                                         javax.net.ssl.SSLEngine sslEngine)
                                                  throws java.io.IOException
        Performs an initial handshake for incoming requests.
        Parameters:
        channel - the SocketChannel
        sslEngine - the SSLEngine or null
        Returns:
        the HttpRequest generated for the handshake
        Throws:
        java.io.IOException - if handshake fails
      • outboundHandshake

        com.airepublic.http.common.HttpResponse outboundHandshake​(java.net.URI uri,
                                                                  java.nio.channels.Selector selector,
                                                                  java.nio.channels.SocketChannel channel,
                                                                  javax.net.ssl.SSLEngine sslEngine,
                                                                  java.util.function.Consumer<SseEvent> consumer)
                                                           throws java.io.IOException
        Performs the client handshake with the server found under the specified URI.
        Parameters:
        uri - the URI to the SSE resource
        selector - the selector for the SocketChannel
        channel - the SocketChannel
        sslEngine - the SSLEngine (optional)
        consumer - the SseEvent Consumer
        Returns:
        the HttpResponse from the server
        Throws:
        java.io.IOException - if the communication fails
      • send

        java.util.concurrent.Future<SseEvent> send​(SseEvent event,
                                                   java.nio.channels.SocketChannel channel,
                                                   javax.net.ssl.SSLEngine sslEngine)
                                            throws java.io.IOException
        Sends the SseEvent asynchronously to the channel.
        Parameters:
        event - the SseEvent
        channel - the SocketChannel
        sslEngine - the SSLEngine or null
        Returns:
        a Future containing the original event
        Throws:
        java.io.IOException - if sending fails
      • broadcast

        java.util.concurrent.Future<SseEvent> broadcast​(SseEvent event,
                                                        java.util.Map<java.nio.channels.SocketChannel,​javax.net.ssl.SSLEngine> channels)
                                                 throws java.io.IOException
        Broadcasts the SseEvent asynchronously to the channels.
        Parameters:
        event - the SseEvent
        channels - the SocketChannels mapped to their SSLEngines
        Returns:
        a Future containing the original event
        Throws:
        java.io.IOException - if sending fails
      • receive

        java.util.concurrent.Future<java.lang.Void> receive​(java.net.URI uri,
                                                            java.util.function.Consumer<SseEvent> consumer)
                                                     throws java.io.IOException
        Receives SseEvents asynchronously from the URI specified in the SseConsumer and notifies the Consumer when an event has been read.
        Parameters:
        uri - the URI to the event source
        consumer - the Consumer accepting the received SseEvents
        Returns:
        a Future
        Throws:
        java.io.IOException - if sending fails
      • decode

        java.util.List<SseEvent> decode​(java.nio.ByteBuffer buffer,
                                        boolean isChunked)
                                 throws java.io.IOException
        Reads SseEvents from the ByteBuffer.

        NOTE: This method expects complete events to be contained in the buffer.

        Parameters:
        buffer - the ByteBuffer
        isChunked - flag whether the connection stream is chunked
        Returns:
        the SseEvent
        Throws:
        java.io.IOException - if reading the event fails
      • encode

        java.nio.ByteBuffer encode​(SseEvent... events)
                            throws java.io.IOException
        Encodes the SseEvents into a ByteBuffer.
        Parameters:
        events - the SseEvents
        Returns:
        the ByteBuffer containing the event
        Throws:
        java.io.IOException - if something fails
      • getHandshakeResponse

        com.airepublic.http.common.HttpResponse getHandshakeResponse()
        Gets the handshake HttpResponse to the client.
        Returns:
        the HttpResponse containing the un-encoded response
      • sendHandshakeResponse

        void sendHandshakeResponse​(java.nio.channels.SocketChannel channel,
                                   javax.net.ssl.SSLEngine sslEngine)
                            throws java.io.IOException
        Sends the handshake response to the client.
        Parameters:
        channel - the SocketChannel to the client
        sslEngine - the SSLEngine
        Throws:
        java.io.IOException - if sending fails