Interface ServerSentEventServer
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultServerSentEventServer
A special HTTP server whose only purpose is to provide Server-Sent Event functionality.
A Soklet application which supports Server-Sent Events will be configured with both a Server
and a ServerSentEventServer
.
See https://www.soklet.com/docs/server-sent-events for detailed documentation.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Request/response processing contract forServerSentEventServer
implementations. -
Method Summary
Modifier and TypeMethodDescriptionOptional
<? extends ServerSentEventBroadcaster> acquireBroadcaster
(ResourcePath resourcePath) Given aResourcePath
that corresponds to a Resource Method annotated withServerSentEventSource
, acquire aServerSentEventBroadcaster
which is capable of "pushing" messages to all connected Server-Sent Event clients.default void
close()
AutoCloseable
-enabled synonym forstop()
.void
initialize
(SokletConfiguration sokletConfiguration, ServerSentEventServer.RequestHandler requestHandler) TheSoklet
instance which manages thisServerSentEventServer
will invoke this method exactly once at initialization time - this allowsSoklet
to "talk" to yourServerSentEventServer
.Is this SSE server started (that is, able to handle requests from clients)?void
start()
Starts the SSE server, which makes it able to accept requests from clients.void
stop()
Stops the SSE server, which makes it unable to accept requests from clients.
-
Method Details
-
start
-
stop
-
isStarted
-
close
AutoCloseable
-enabled synonym forstop()
.This method is designed for internal use by
Soklet
only and should not be invoked elsewhere.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
- if an exception occurs while stopping the server
-
acquireBroadcaster
@Nonnull Optional<? extends ServerSentEventBroadcaster> acquireBroadcaster(@Nullable ResourcePath resourcePath) Given aResourcePath
that corresponds to a Resource Method annotated withServerSentEventSource
, acquire aServerSentEventBroadcaster
which is capable of "pushing" messages to all connected Server-Sent Event clients.Soklet guarantees exactly one
ServerSentEventBroadcaster
instance exists perResourcePath
. Soklet is responsible for the creation and management ofServerSentEventBroadcaster
instances.See https://www.soklet.com/docs/server-sent-events for detailed documentation.
- Parameters:
resourcePath
- theServerSentEventSource
-annotated Resource Method for which to acquire a broadcaster- Returns:
- a broadcaster for the given
ResourcePath
, orOptional.empty()
if there is no broadcaster available
-
initialize
void initialize(@Nonnull SokletConfiguration sokletConfiguration, @Nonnull ServerSentEventServer.RequestHandler requestHandler) TheSoklet
instance which manages thisServerSentEventServer
will invoke this method exactly once at initialization time - this allowsSoklet
to "talk" to yourServerSentEventServer
.This method is designed for internal use by
Soklet
only and should not be invoked elsewhere.- Parameters:
sokletConfiguration
- configuration for the Soklet instance that controls this serverrequestHandler
- aSoklet
-internal request handler which takes aServerSentEventServer
-provided request as input and supplies aMarshaledResponse
as output for theServerSentEventServer
to write back to the client
-