Class Soklet
java.lang.Object
com.soklet.Soklet
- All Implemented Interfaces:
AutoCloseable
Soklet's main class - manages a
Server
(and optionally a ServerSentEventServer
) using the provided system configuration.
// Use out-of-the-box defaults
SokletConfig config = SokletConfig.withServer(
Server.withPort(8080).build()
).build();
try (Soklet soklet = Soklet.withConfig(config)) {
soklet.start();
System.out.println("Soklet started, press [enter] to exit");
soklet.awaitShutdown(ShutdownTrigger.ENTER_KEY);
}
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionvoid
awaitShutdown
(ShutdownTrigger... shutdownTriggers) Blocks the current thread until JVM shutdown (SIGTERM/SIGINT/System.exit(...)
and so forth), or if one of the providedshutdownTriggers
occurs.void
close()
Synonym forstop()
.Is either the managedServer
orServerSentEventServer
started?static void
runSimulator
(SokletConfig sokletConfig, Consumer<Simulator> simulatorConsumer) Runs Soklet with a special "simulator" server that is useful for integration testing.void
start()
Starts the managed server instance[s].void
stop()
Stops the managed server instance[s].static Soklet
withConfig
(SokletConfig sokletConfig) Acquires a Soklet instance with the given configuration.
-
Method Details
-
withConfig
Acquires a Soklet instance with the given configuration.- Parameters:
sokletConfig
- configuration that drives the Soklet system- Returns:
- a Soklet instance
-
start
Starts the managed server instance[s].If the managed server[s] are already started, this is a no-op.
-
stop
Stops the managed server instance[s].If the managed server[s] are already stopped, this is a no-op.
-
awaitShutdown
public void awaitShutdown(@Nullable ShutdownTrigger... shutdownTriggers) throws InterruptedException Blocks the current thread until JVM shutdown (SIGTERM/SIGINT/System.exit(...)
and so forth), or if one of the providedshutdownTriggers
occurs.This method will automatically invoke this instance's
stop()
method once it becomes unblocked.Notes regarding
ShutdownTrigger.ENTER_KEY
:- It will invoke
stop()
on all Soklet instances, as stdin is process-wide - It is only supported for environments with an interactive TTY and will be ignored if none exists (e.g. running in a Docker container) - Soklet will detect this and fire
LifecycleInterceptor.didReceiveLogEvent(LogEvent)
with an event of typeLogEventType.CONFIGURATION_UNSUPPORTED
- Parameters:
shutdownTriggers
- additional trigger[s] which signal that shutdown should occur, e.g.ShutdownTrigger.ENTER_KEY
for "enter key pressed"- Throws:
InterruptedException
- if the current thread has its interrupted status set on entry to this method, or is interrupted while waiting
- It will invoke
-
close
-
isStarted
Is either the managedServer
orServerSentEventServer
started?- Returns:
true
if at least one is started,false
otherwise
-
runSimulator
public static void runSimulator(@Nonnull SokletConfig sokletConfig, @Nonnull Consumer<Simulator> simulatorConsumer) Runs Soklet with a special "simulator" server that is useful for integration testing.See https://www.soklet.com/docs/automated-testing for how to write these tests.
- Parameters:
sokletConfig
- configuration that drives the Soklet systemsimulatorConsumer
- code to execute within the context of the simulator
-