Class ManagedAdmissionController
java.lang.Object
org.j7m.middleware.application.components.ManagedAdmissionController
- All Implemented Interfaces:
AutoCloseable
Host-local bounded admission with non-preemptive priority and ageing.
No worker threads are created. Waiting callers consume at most the configured queue capacity and observe a monotonic time budget or interruption. Closing rejects queued/new callers but does not cancel running work or release its permits. The owner must close each permit only when physical work completes, including exceptional asynchronous completion. This is a JVM-local budget, not a distributed semaphore or CPU scheduler. Instances are thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classIdempotent permit which may be released by another completion thread.static final recordAtomic aggregate host-local counters. -
Constructor Summary
ConstructorsConstructorDescriptionManagedAdmissionController(int capacity, int maximumQueued, Duration ageingStep) Creates a shared host budget. -
Method Summary
-
Constructor Details
-
ManagedAdmissionController
Creates a shared host budget.- Parameters:
capacity- simultaneous active permits, 1 through 1000000maximumQueued- maximum waiting callers, 0 through 1024ageingStep- positive interval after which a waiting caller gains one relative priority unit- Throws:
IllegalArgumentException- if bounds or the ageing interval are invalidNullPointerException- if ageingStep is null
-
-
Method Details
-
acquire
Acquires one permit, preferring higher relative priority with FIFO ties and ageing. New callers never bypass the queue through the immediate fast path. Once queued, a higher priority may overtake lower priorities. Ageing improves fairness within the waiting budget; it does not guarantee admission under sustained overload. A zero budget permits immediate acquisition only; a saturated queue rejects immediately. Interruption rejects admission without clearing the thread's interrupt status. An acquired permit remains active until explicitly closed.- Parameters:
priority- relative priority, -1024 through 1024timeout- maximum monotonic waiting time, zero through one minute- Returns:
- owned idempotent permit
- Throws:
IllegalArgumentException- for an invalid priority or timeoutorg.j7m.middleware.api.MiddlewareException- OVERLOADED for capacity rejection, DEADLINE_EXCEEDED for elapsed waiting time, CANCELLED for interruption, or UNAVAILABLE when closed
-
status
Returns aggregate counters without request/argument information.- Returns:
- atomic host-local admission state
-
close
public void close()Rejects queued and future admissions; running permits retain their accounting until closed.- Specified by:
closein interfaceAutoCloseable
-