Package za.co.wethinkcode.robots.server
Class Server
java.lang.Object
za.co.wethinkcode.robots.server.Server
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 Summary
ConstructorsConstructorDescriptionServer(WorldConfig config, World world) The standard constructor of a new Server -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic voidThe main method of the Server class.static ServerStatic style configuration stage for setting up a server.static ServernewServerWithoutWebApi(String[] args) Builds a Server same way newServer(args) does, but without aHTTP_API_Runtimeweb server attached.voidsetRepository(WorldRepository repository) voidsetWebServer(HTTP_API_Runtime webServer) voidstart()Public entry point for starting this server's accept loop from outside theserverpackage (e.g.
-
Constructor Details
-
Server
The standard constructor of a new Server- Parameters:
config- the config of the world containing things like obstacles etcworld- the domain object of the world that robots are connecting to
-
-
Method Details
-
main
The main method of the Server class.- Parameters:
args- Command Line Arguments
-
newServer
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, ornullwhen parsing stops for help or invalid input - Throws:
ServerInitilisationError
-
newServerWithoutWebApi
Builds a Server same way newServer(args) does, but without aHTTP_API_Runtimeweb server attached.This is intended for tests that only need the plain socket server (e.g. the
acceptancepackage), 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
Serverwith no web server attached, ornullwhen parsing stops for help or invalid input - Throws:
ServerInitilisationError
-
start
Public entry point for starting this server's accept loop from outside theserverpackage (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
-
hasActiveConnections
public boolean hasActiveConnections() -
setWebServer
-