Class Server

java.lang.Object
za.co.wethinkcode.robots.server.Server

public class Server extends Object
Represents the Robot World server. This class is responsible for loading the server configuration, creating the game world, starting the server, accepting client connections, and managing the server
  • Constructor Details

    • Server

      public Server(WorldConfig config, World world)
      The standard constructor of a new Server
      Parameters:
      config - the config of the world containing things like obstacles etc
      world - the domain object of the world that robots are connecting to
  • Method Details

    • main

      public static void main(String[] args)
      The main method of the Server class.
      Parameters:
      args - Command Line Arguments
    • newServer

      public static Server newServer(String[] args) throws ServerInitilisationError
      Static style configuration stage for setting up a server.

      This sets up registerShutdownHook() as well as applying the necessary overrides

      Parameters:
      args - args passed in directly
      Returns:
      the configured Server, or null when parsing stops for help or invalid input
      Throws:
      ServerInitilisationError
    • newServerWithoutWebApi

      public static Server newServerWithoutWebApi(String[] args) throws ServerInitilisationError
      Builds a Server same way newServer(args) does, but without a HTTP_API_Runtime web server attached.

      This is intended for tests that only need the plain socket server (e.g. the acceptance package), so they can start a real server in the background without clashing with any other embedded web server that might already be bound to the same web API port in the same JVM.

      Parameters:
      args - Command Line Arguments, e.g. {"-p", "5000"}
      Returns:
      the configured Server with no web server attached, or null when parsing stops for help or invalid input
      Throws:
      ServerInitilisationError
    • start

      public void start() throws ServerInitilisationError
      Public entry point for starting this server's accept loop from outside the server package (e.g. from a test extension that starts a real server in the background). Blocks the calling thread for as long as the server runs, so callers should invoke this from a dedicated background thread.
      Throws:
      ServerInitilisationError
    • setRepository

      public void setRepository(WorldRepository repository)
    • hasActiveConnections

      public boolean hasActiveConnections()
    • setWebServer

      public void setWebServer(HTTP_API_Runtime webServer)