Class Client2RequestGate
Client2
request queue backpressure by blocking the calling thread.
Procedure calls are queued in the Client2
API
for the duration of their execution. If the application is
queueing calls faster than they can be processed, particularly
when using callProcedureAsync
, eventually the
queue will reach its limit. The application can be made
aware of an approaching limit by implementing a handler
for "request backpressure" events; the application is expected
to take whatever steps are needed in order to reduce the
call rate. If it does not, then eventually the hard limit
will be reached, and further calls will be rejected until
the queue length falls below that limit.
Execution will not be blocked internally to the API when
calling callProcedureAsync
.
In some simple cases, it may nevertheless be appropriate
to simply block execution of a thread that is about to
issue callProcedureAsync
This class,
Client2RequestGate
, facilitates that.
- See Also:
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
Client2RequestGate
public Client2RequestGate()
-
-
Method Details
-
waitOpen
Await gate opening.Usage: a call to this should be placed immediately before each
callProcedureAsync
request. It returns immediately, unless execution is blocked. -
waitOpen
Await gate opening with timeout.Usage: a call to this should be placed immediately before each
callProcedureAsync
request. It returns immediately, unless execution is blocked.- Parameters:
timeout
- the timeout intervalunit
- the units in which the timeout was expressed- Throws:
TimeoutException
InterruptedException
- See Also:
-
operate
public void operate(boolean closing) Set current state of the request gate.Usage: configure this method as the request-backpressure handler in your application, before creating client instances. Here,
gate
is an instance ofClient2RequestGate
.config.requestBackpressureHandler(gate::operate)
The notification is triggered when the queue length rises above the warning limit, and again when the queue length falls below the resume limit.
- Parameters:
closing
- true if gate is closing, false if opening- See Also:
-