Interface Server

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
DefaultServer

public interface Server extends AutoCloseable
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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Request/response processing contract for Server implementations.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    AutoCloseable-enabled synonym for stop().
    void
    initialize(SokletConfiguration sokletConfiguration, Server.RequestHandler requestHandler)
    The Soklet instance which manages this Server will invoke this method exactly once at initialization time - this allows Soklet to "talk" to your Server.
    Is this server started (that is, able to handle requests from clients)?
    void
    Starts the server, which makes it able to accept requests from clients.
    void
    Stops the server, which makes it unable to accept requests from clients.
  • Method Details

    • start

      void start()
      Starts the 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.

    • stop

      void stop()
      Stops the 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.

    • isStarted

      Is this server started (that is, able to handle requests from clients)?
      Returns:
      true if the server is started, false otherwise
    • initialize

      void initialize(@Nonnull SokletConfiguration sokletConfiguration, @Nonnull Server.RequestHandler requestHandler)
      The Soklet instance which manages this Server will invoke this method exactly once at initialization time - this allows Soklet to "talk" to your Server.

      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 server
      requestHandler - a Soklet-internal request handler which takes a Server-provided request as input and supplies a MarshaledResponse as output for the Server to write back to the client
    • close

      default void close() throws Exception
      AutoCloseable-enabled synonym for stop().

      This method is designed for internal use by Soklet only and should not be invoked elsewhere.

      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception - if an exception occurs while stopping the server