Class JobManager
java.lang.Object
net.simplace.sim.wrapper.rest.job.JobManager
Manages asynchronously running jobs (currently only /run) across all sessions. Jobs run in a
dedicated single-thread executor - more threads would not help, because
SessionManager.ENGINE_LOCK serialises the actual execution anyway; the executor only makes
sure that Javalin's HTTP request thread can return immediately instead of waiting for
ENGINE_LOCK.
Jobs are not persisted and not actively cleaned up (no TTL as for sessions) - they are small
and die with their session at the latest (SessionManager also removes the jobs of a session
when it is closed or evicted, see removeJobsForSession).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown if a job id is unknown (mapped to HTTP 404 by RestServer).static interfaceA consumer that may throw checked exceptions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasActiveJobs(String sessionId) voidremoveJobsForSession(String sessionId) Removes all jobs of a session.submit(String sessionId, JobManager.ThrowingConsumer<RestJob> work) Creates a job and queues its work in the worker thread.
-
Constructor Details
-
JobManager
public JobManager()
-
-
Method Details
-
submit
Creates a job and queues its work in the worker thread. The job is marked RUNNING when the work starts, DONE when it finishes and FAILED if it throws (also an Error, so that the job never stays RUNNING) or if a simulation reported an error during the run (FAILED is not overwritten).- Parameters:
sessionId- id of the session the job belongs to; used as prefix of the job idwork- the work to execute; receives the job to report progress- Returns:
- the new job (status PENDING)
-
get
- Parameters:
jobId- job id- Returns:
- the job
- Throws:
JobManager.NoSuchJobException- if there is no job with this id
-
hasActiveJobs
- Parameters:
sessionId- session id- Returns:
trueif the session has a job that is still queued (PENDING) or RUNNING
-
removeJobsForSession
Removes all jobs of a session. Jobs that are still queued or running are not cancelled.- Parameters:
sessionId- session id
-