Class RestServer

java.lang.Object
net.simplace.sim.wrapper.rest.RestServer

public class RestServer extends Object
REST wrapper around net.simplace.sim.wrapper.SimplaceWrapper. Like all language bindings it uses only the public SimplaceWrapper API (also for the configuration), never FWSimEngine directly. Configuration is done exclusively via environment variables and deliberately NOT via a REST call, because FWSimEngine.setWorkDir/setOutputDir/... are static, process-wide fields (see FWSimEngine: private static FWSimEngine cIdentity). Setting the directories once at start-up is the only race-free option - an endpoint for changing the directories at runtime would sabotage every session running in parallel. Environment variables: SIMPLACE_WORK_DIR (required) SIMPLACE_OUTPUT_DIR (required) SIMPLACE_PROJECTS_DIR (optional, default = WORK_DIR) SIMPLACE_DATA_DIR (optional, default = WORK_DIR) SIMPLACE_CHECK_LEVEL (optional, e.g. LAZY/INTENSE/OFF - see CHECK_LEVEL enum) REST_PORT (optional, default 7070) SESSION_IDLE_MINUTES (optional, default 30 - after this time a session is closed automatically if nobody uses it any more) The browser client (net.simplace.sim.wrapper.web, command "simplace web") is a server of its own and does not use this class. Started either directly (main) or from FWSimConsole via reflection (command "rest") - see startFromConsole(Integer). The reflection detour is deliberate: FWSimConsole/simplace_core itself must not compile against Javalin/Jetty (see lib/rest), otherwise every compilation of simplace_core would depend on these third-party jars. POST /run is asynchronous (a run can take a long time): the call immediately returns 202 + jobId (see JobManager), progress is available via GET .../jobs/{jobId} (fed from FWSimulationListener events, see JobProgressListener), and the result via GET .../results/{outputName} as before, as soon as the job is DONE.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Configures the FWSimEngine from the environment variables and starts the server.
    static void
    Entry point for FWSimConsole (command "rest").
    static io.javalin.Javalin
    startOnPort(int aPort, Duration aSessionIdleTimeout)
    Starts the server on a specific port without the main()/System.exit/environment variable detour and returns the Javalin instance (for tests: call app.stop() afterwards).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RestServer

      public RestServer()
  • Method Details

    • main

      public static void main(String[] args)
      Configures the FWSimEngine from the environment variables and starts the server.
      Parameters:
      args - not used
    • startFromConsole

      public static void startFromConsole(Integer aPort)
      Entry point for FWSimConsole (command "rest"). At this point the directories (workdir/outputdir/...) have already been set on FWSimEngine by FWSimConsole - only the port is taken from the options and the server is started.
      Parameters:
      aPort - optional port; null uses the default port (see REST_PORT/7070)
    • startOnPort

      public static io.javalin.Javalin startOnPort(int aPort, Duration aSessionIdleTimeout)
      Starts the server on a specific port without the main()/System.exit/environment variable detour and returns the Javalin instance (for tests: call app.stop() afterwards). Expects the FWSimEngine directories to be set already (see configureEngine()/FWSimConsole). Intended for system tests (net.simplace.sim.tests.framework.wrapper) that want to start the real HTTP server on a test port instead of calling SimplaceWrapper directly.
      Parameters:
      aPort - port to listen on
      aSessionIdleTimeout - idle time after which unused sessions are closed
      Returns:
      the started Javalin instance