Class JobsRest
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,AsyncJobsMixin,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig,TerminalMixin
AsyncJobRef, and the views runtime follows its streamUrl until the job settles.
The registry de-duplicates on the idempotency key itself (AsyncJobRegistry.tryCreate(IdempotencyKey)), so a
resubmit with the same key returns the same job and this resource keeps no key map of its own.
The page's job-log card posts the same restock in its flat form and follows the job's stream. A restock
with slowMs waits that long before it touches the store (cancel it then and nothing changes), and every
restock holds for holdMs (a second by default) after it has added its pets (cancel it then and the result
says the change was made).
The registry's hard timeout is 30 s, or whatever a JobsRest.HardTimeout bean on the host says; a JobsRest.GroomPeriod
bean sets the groom step and a JobsRest.SpeciesHold bean the species-row hold.
The seeded groom run is created on the first groom request rather than at construction, so a JobsRest.GroomPeriod bean
(injected after construction) can set its pace; every groom endpoint goes through it, so the page sees the same data.
The page also hosts the terminal demo: a "groom pet" job (GroomRuns) whose output is served by
TerminalMixin and shown two ways — a FreeMarker terminal card over the in-memory output, and a second
card over the same run's file-backed transcript.
Example:
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA per-host groom step period.static final recordA per-host override of the jobs hard timeout.static final recordA per-host clock for the row-key ledger, so a test can age a key past its TTL.static final recordThe restock request.static final recordA per-host species-row hold: how long a species row's restock holds after its effect.Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe default hard timeout of a restock job.static final intHow long a restock holds after its effect by default, so a late cancel lands ascancelled-after-effect.static final StringSystem property: the most restocks that may run at once (default 2; the registry's own cap is 8).static final intThe longestholdMsa restock accepts.static final intThe longestslowMsa restock accepts.static final StringWhere this resource is mounted; the terminal URLs are built from it.static final StringFields inherited from class org.apache.juneau.petstore.console.PetstoreConsolePage
PAGE_HEADER, TEMPLATESFields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEADFields inherited from interface org.apache.juneau.console.views.AsyncJobsMixin
CANCEL_PATH, JOBS_PREFIX, STREAM_PATH, STREAM_POLL_INTERVALFields inherited from interface org.apache.juneau.terminal.region.TerminalMixin
BYTES_PATH, CSS_PATH, JS_PATH, RAW_PATH, TERMINAL_PREFIX, XTERM_CSS_ASSET, XTERM_JS_ASSET -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns theAsyncJobRegistrybacking this resource's async jobs.voidStops the restock pool, the registry's timeout scheduler and the groom runs when the resource is destroyed.Starts a groom run.The Groom dialog's form source.groomRunDetail(String id) A groom run's detail panel.groomRunKey(RestRequest req, String id) Issues a regroom key bound to one groom run and the caller.page(RestRequest req, String run) Renders the Jobs page.regroom(RestRequest req, RestResponse res, String id, JsonMap json) Grooms a run's pet again.restock(RestRequest req, RestResponse res, JsonMap json) Submits a restock.The restock dialog's form source: a read-only GET returning the modal with a freshly minted self-targeted key.restockSpecies(RestRequest req, RestResponse res, String id, JsonMap json) Restocks one species from its row's detail panel.rows()speciesDetail(String id) A species row's detail panel.speciesKey(RestRequest req, String id) Issues a restock key bound to one species and the caller.terminalSource(String id, RestRequest req) Resolves the source for a terminal id, applying the application's own access rules.Methods inherited from class org.apache.juneau.petstore.console.PetstoreConsolePage
builder, freemarker, store, twinMethods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, logMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.console.views.AsyncJobsMixin
cancelJob, streamJobMethods inherited from interface org.apache.juneau.terminal.region.TerminalMixin
terminalBytes, terminalRaw, terminalScript, terminalStylesheet
-
Field Details
-
LIMIT_PROPERTY
System property: the most restocks that may run at once (default 2; the registry's own cap is 8).- See Also:
-
SPECIES_HOLD_PROPERTY
System property: how long a species row's restock holds after its effect, in milliseconds (default 1000, at most 10000).Read on every request, so a test can widen the window in which a cancel lands as
cancelled-after-effect. A sample-only knob: the row form never accepts a hold.- See Also:
-
MOUNT
Where this resource is mounted; the terminal URLs are built from it.- See Also:
-
DEFAULT_HARD_TIMEOUT
The default hard timeout of a restock job. -
MAX_SLOW_MS
The longestslowMsa restock accepts.- See Also:
-
MAX_HOLD_MS
The longestholdMsa restock accepts.- See Also:
-
DEFAULT_HOLD_MS
How long a restock holds after its effect by default, so a late cancel lands ascancelled-after-effect.- See Also:
-
-
Constructor Details
-
JobsRest
public JobsRest()
-
-
Method Details
-
asyncJobRegistry
Description copied from interface:AsyncJobsMixinReturns theAsyncJobRegistrybacking this resource's async jobs.- Specified by:
asyncJobRegistryin interfaceAsyncJobsMixin- Returns:
- The registry. Never
null .
-
closeJobs
Stops the restock pool, the registry's timeout scheduler and the groom runs when the resource is destroyed. -
page
Renders the Jobs page.- Parameters:
req- The request;?builderrenders the builder twin.run- The groom run to show, ornull for the newest.- Returns:
- The page view.
- Throws:
NotFound- If there is no groom run to show.
-
restockForm
The restock dialog's form source: a read-only GET returning the modal with a freshly minted self-targeted key.The dialog is the plain restock, so it asks only for counts and always runs with no wait and the default 1000 ms hold. The timing knobs (
slowMs,holdMs) belong to the job-log card, which exists to demonstrate cancelling before and after the effect.- Returns:
- The modal.
-
rows
- Returns:
- Submitted jobs, newest first, with their current state.
-
restock
Submits a restock.- Parameters:
req- The request.res- The response (202).json- The restock body (seeJobsRest.Restock.of(JsonMap)).- Returns:
- The job ref (202), or a 429
app:job-limitrefusal whose message names the running count, so a JSON client such as the job-log card can show it. - Throws:
BadRequest- On a missing key, an out-of-range count, or a badslowMsorholdMs(seeJobsRest.Restock.of(JsonMap)).
-
job
- Parameters:
id- The job id.- Returns:
{state: RUNNING|DONE, result}.- Throws:
NotFound- If the job is unknown or has aged out.
-
terminalSource
Description copied from interface:TerminalMixinResolves the source for a terminal id, applying the application's own access rules.- Specified by:
terminalSourcein interfaceTerminalMixin- Parameters:
id- The id from the URL path (already checked against the grammar).req- The in-flight request.- Returns:
- The source, or empty when the id is unknown or the caller may not read it.
-
groomForm
The Groom dialog's form source.- Returns:
- The modal.
-
groom
Starts a groom run.Accepts the API form
{pet, verbose}or the dialog form{action, targetId, idempotencyKey, fields:{pet, verbose}}; a resubmit with the sameidempotencyKeyreturns the same run.- Parameters:
json- The body.- Returns:
- The new run's row.
- Throws:
IOException- If the run's temp file cannot be created.
-
groomRows
- Returns:
- The groom runs, newest first.
-
speciesRows
- Returns:
- One row per species:
{id, species, available}.
-
speciesDetail
A species row's detail panel.- Parameters:
id- The species name, for exampleDOG.- Returns:
{contractVersion, fields:{available, lastRestock}}.- Throws:
NotFound- If the species is unknown.
-
speciesKey
Issues a restock key bound to one species and the caller.A POST, so it sits behind the console's CSRF boundary like every other console write; it changes nothing but the key ledger.
- Parameters:
req- The request.id- The species name.- Returns:
{contractVersion, action, targetId, idempotencyKey}.- Throws:
NotFound- If the species is unknown.
-
restockSpecies
public Object restockSpecies(RestRequest req, RestResponse res, @Path("id") String id, @Content JsonMap json) Restocks one species from its row's detail panel.The species is the path's
{id}, which must equal the body'stargetId, which the key must be bound to. The body'sfieldssupply onlycount; any other field (the panel's hiddenspeciesincluded) is ignored. A replay of a claimed key returns the same job, or aJobKeyLedger.SPENT_CODErefusal once the registry has aged the job out.- Parameters:
req- The request.res- The response (202, or 409 on a refusal).id- The species name.json- The action envelope{action, targetId, idempotencyKey, fields:{count}}.- Returns:
- The job ref (202), a 409 refusal, or a 429
app:job-limitrefusal. - Throws:
NotFound- If the species is unknown.BadRequest- If the envelope is malformed orcountis not a whole number 1-50.
-
groomRunDetail
A groom run's detail panel.- Parameters:
id- The run id.- Returns:
{contractVersion, fields:<the run's row>}.- Throws:
NotFound- If the run is unknown.
-
groomRunKey
Issues a regroom key bound to one groom run and the caller.- Parameters:
req- The request.id- The run id.- Returns:
{contractVersion, action, targetId, idempotencyKey}.- Throws:
NotFound- If the run is unknown.
-
regroom
public ActionResult regroom(RestRequest req, RestResponse res, @Path("id") String id, @Content JsonMap json) throws IOException Grooms a run's pet again.Ledger keys only, bound to the path's run: the pet comes from the server's run record, never the request.
/groomstays the dialog's self-targeted endpoint; one endpoint taking both kinds of key would be only as strong as the self-targeted one. A replay returns the same new run while it is kept, then aJobKeyLedger.SPENT_CODErefusal once the run list has evicted it; never a second run.- Parameters:
req- The request.res- The response (409 on a refusal).id- The run id.json- The action envelope{action, targetId, idempotencyKey}.- Returns:
- The new run's row, or a 409 refusal.
- Throws:
NotFound- If the key is unclaimed and the run is unknown.BadRequest- If the envelope is malformed.IOException- If the new run's temp file cannot be created.
-