Interface Server
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DefaultServer
Contract for HTTP server implementations that are designed to be managed by a
Soklet
instance.
Most Soklet applications will use DefaultServer
and therefore do not need to implement this interface directly.
For example:
SokletConfiguration config = SokletConfiguration.withServer(
DefaultServer.withPort(8080).build()
).build();
try (Soklet soklet = new Soklet(config)) {
soklet.start();
System.out.println("Soklet started, press [enter] to exit");
System.in.read(); // or Thread.currentThread().join() in containers
}
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Request/response processing contract forServer
implementations. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
AutoCloseable
-enabled synonym forstop()
.void
initialize
(SokletConfiguration sokletConfiguration, Server.RequestHandler requestHandler) Is this server started (that is, able to handle requests from clients)?void
start()
Starts the server, which makes it able to accept requests from clients.void
stop()
Stops the server, which makes it unable to accept requests from clients.
-
Method Details
-
start
-
stop
-
isStarted
-
initialize
void initialize(@Nonnull SokletConfiguration sokletConfiguration, @Nonnull Server.RequestHandler requestHandler) TheSoklet
instance which manages thisServer
will invoke this method exactly once at initialization time - this allowsSoklet
to "talk" to yourServer
.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 aServer
-provided request as input and supplies aMarshaledResponse
as output for theServer
to write back to the client
-
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
-