-
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 theSseEventasynchronously to the channels.java.util.List<SseEvent>decode(java.nio.ByteBuffer buffer, boolean isChunked)ReadsSseEvents from theByteBuffer.java.nio.ByteBufferencode(SseEvent... events)Encodes theSseEvents into aByteBuffer.com.airepublic.http.common.HttpRequesthandshake(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine)Performs an initial handshake for incoming requests.com.airepublic.http.common.HttpResponseoutboundHandshake(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.voidprocessRequest(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLContext sslContext, ISseRegistry sseRegistry)Processes the whole lifecycle of anSseProducer.java.util.concurrent.Future<java.lang.Void>receive(java.net.URI uri, java.util.function.Consumer<SseEvent> consumer)ReceivesSseEvents asynchronously from the URI specified in theSseConsumerand notifies theConsumerwhen an event has been read.java.util.concurrent.Future<SseEvent>send(SseEvent event, java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine)Sends theSseEventasynchronously to the channel.
-
-
-
Method Detail
-
processRequest
void processRequest(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLContext sslContext, ISseRegistry sseRegistry)Processes the whole lifecycle of anSseProducer.- accepting the incoming request
- sending the handshake response
- sending
SseEvents by calling the associatedSseProducermethod - respecting delay and maximum times configured in the
SseProducerannotation
- Parameters:
channel- the freshly acceptedSocketChannelsslContext- theSSLContextsseRegistry- theISseRegistrywhere the producer is registered
-
handshake
com.airepublic.http.common.HttpRequest handshake(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine) throws java.io.IOExceptionPerforms an initial handshake for incoming requests.- Parameters:
channel- theSocketChannelsslEngine- theSSLEngineor null- Returns:
- the
HttpRequestgenerated 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.IOExceptionPerforms the client handshake with the server found under the specified URI.- Parameters:
uri- the URI to the SSE resourceselector- the selector for theSocketChannelchannel- theSocketChannelsslEngine- theSSLEngine(optional)consumer- theSseEventConsumer- Returns:
- the
HttpResponsefrom 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 theSseEventasynchronously to the channel.- Parameters:
event- theSseEventchannel- theSocketChannelsslEngine- theSSLEngineor null- Returns:
- a
Futurecontaining 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 theSseEventasynchronously to the channels.- Parameters:
event- theSseEventchannels- theSocketChannels mapped to theirSSLEngines- Returns:
- a
Futurecontaining 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.IOExceptionReceivesSseEvents asynchronously from the URI specified in theSseConsumerand notifies theConsumerwhen an event has been read.- Parameters:
uri- theURIto the event sourceconsumer- theConsumeraccepting the receivedSseEvents- 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
ReadsSseEvents from theByteBuffer.NOTE: This method expects complete events to be contained in the buffer.
- Parameters:
buffer- theByteBufferisChunked- flag whether the connection stream is chunked- Returns:
- the
SseEvent - Throws:
java.io.IOException- if reading the event fails
-
-