Class ServerRuntime
java.lang.Object
zeroecho.pki.server.http.ServerRuntime
- All Implemented Interfaces:
AutoCloseable
Centralized owner of all bounded server-created threads, queues and permits.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceOperation executed on this runtime's bounded worker lane. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()<T> Texecute(Duration deadline, ServerRuntime.CancellableOperation<T> operation) Executes one operation through the owned bounded queue and waits for its result.voidReturns a permit previously acquired bytryAdmit().booleantryAdmit()Tries to reserve one request-admission permit without waiting.
-
Method Details
-
tryAdmit
public boolean tryAdmit()Tries to reserve one request-admission permit without waiting. A successful caller must invokereleaseAdmission()exactly once. Shutdown may start after this check, so later submission can still fail.- Returns:
- whether a permit was acquired while acceptance was observed enabled
-
releaseAdmission
public void releaseAdmission()Returns a permit previously acquired bytryAdmit(). Calling without a matching acquisition increases capacity incorrectly; the caller must enforce pairing even when request processing fails. -
execute
public <T> T execute(Duration deadline, ServerRuntime.CancellableOperation<T> operation) throws TimeoutException, InterruptedException, ExecutionException Executes one operation through the owned bounded queue and waits for its result. The caller owns admission pairing. A timeout or interruption requests cooperative cancellation and interrupts the worker; execution tracking remains until the worker actually exits. Already committed side effects are not rolled back.The operation must release its resources itself and must not transfer a live resource through the return value: a result produced after cancellation can be discarded. The caller must restore or propagate interruption.
- Type Parameters:
T- independently owned, resource-free result type- Parameters:
deadline- positive wait bound no greater than the configured maximumoperation- operation receiving the lifecycle-owned cancellation signal- Returns:
- completed operation result
- Throws:
IllegalArgumentException- if the deadline is outside the configured boundRejectedExecutionException- if the runtime is closing or its queue is fullTimeoutException- if the deadline expiresInterruptedException- if the waiting caller is interruptedExecutionException- if operation execution fails
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-