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 interfaceRequest/response processing contract forServerSentEventServerimplementations. -
Method Summary
Modifier and TypeMethodDescriptionOptional<? extends ServerSentEventBroadcaster> acquireBroadcaster(ResourcePath resourcePath) Given aResourcePaththat corresponds to a Resource Method annotated withServerSentEventSource, acquire aServerSentEventBroadcasterwhich is capable of "pushing" messages to all connected Server-Sent Event clients.default voidclose()AutoCloseable-enabled synonym forstop().voidinitialize(SokletConfiguration sokletConfiguration, ServerSentEventServer.RequestHandler requestHandler) TheSokletinstance which manages thisServerSentEventServerwill invoke this method exactly once at initialization time - this allowsSokletto "talk" to yourServerSentEventServer.Is this SSE server started (that is, able to handle requests from clients)?voidstart()Starts the SSE server, which makes it able to accept requests from clients.voidstop()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
Sokletonly and should not be invoked elsewhere.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- if an exception occurs while stopping the server
-
acquireBroadcaster
@Nonnull Optional<? extends ServerSentEventBroadcaster> acquireBroadcaster(@Nullable ResourcePath resourcePath) Given aResourcePaththat corresponds to a Resource Method annotated withServerSentEventSource, acquire aServerSentEventBroadcasterwhich is capable of "pushing" messages to all connected Server-Sent Event clients.Soklet guarantees exactly one
ServerSentEventBroadcasterinstance exists perResourcePath. Soklet is responsible for the creation and management ofServerSentEventBroadcasterinstances.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) TheSokletinstance which manages thisServerSentEventServerwill invoke this method exactly once at initialization time - this allowsSokletto "talk" to yourServerSentEventServer.This method is designed for internal use by
Sokletonly 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 aMarshaledResponseas output for theServerSentEventServerto write back to the client
-