Class DefaultServerSentEventServer
java.lang.Object
com.soklet.core.impl.DefaultServerSentEventServer
- All Implemented Interfaces:
ServerSentEventServer
,AutoCloseable
@ThreadSafe
public class DefaultServerSentEventServer
extends Object
implements ServerSentEventServer
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder used to construct instances ofDefaultServerSentEventServer
.Nested classes/interfaces inherited from interface com.soklet.core.ServerSentEventServer
ServerSentEventServer.RequestHandler
-
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.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.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.soklet.core.ServerSentEventServer
close
-
Method Details
-
withPort
-
initialize
public void initialize(@Nonnull SokletConfiguration sokletConfiguration, @Nonnull ServerSentEventServer.RequestHandler requestHandler) Description copied from interface:ServerSentEventServer
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.- Specified by:
initialize
in interfaceServerSentEventServer
- 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
-
start
Description copied from interface:ServerSentEventServer
Starts the SSE server, which makes it able to accept requests from clients.If the server is already started, no action is taken.
This method is designed for internal use by
Soklet
only and should not be invoked elsewhere.- Specified by:
start
in interfaceServerSentEventServer
-
stop
Description copied from interface:ServerSentEventServer
Stops the SSE server, which makes it unable to accept requests from clients.If the server is already stopped, no action is taken.
This method is designed for internal use by
Soklet
only and should not be invoked elsewhere.- Specified by:
stop
in interfaceServerSentEventServer
-
isStarted
Description copied from interface:ServerSentEventServer
Is this SSE server started (that is, able to handle requests from clients)?- Specified by:
isStarted
in interfaceServerSentEventServer
- Returns:
true
if the server is started,false
otherwise
-
acquireBroadcaster
@Nonnull public Optional<? extends ServerSentEventBroadcaster> acquireBroadcaster(@Nullable ResourcePath resourcePath) Description copied from interface:ServerSentEventServer
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.
- Specified by:
acquireBroadcaster
in interfaceServerSentEventServer
- 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
-
getResourceMethodsByResourcePathDeclaration
-