Package org.exoplatform.caldav.client
Class CalDavDeadline
java.lang.Object
org.exoplatform.caldav.client.CalDavDeadline
- All Implemented Interfaces:
AutoCloseable
One overall time budget for a sequence of CalDAV calls made on one thread —
a landing of a mail's invitation, which holds the user's click: every request
HttpCalDavClient sends while it is open is sent with the smaller of
its own timeout and the time left, a request asked for once nothing is left
is refused before it leaves (CalDavDeadlineException), and a response
body still being read when the time runs out is cut. The request timeout
bounds the connection and the wait for the response's headers; the body read
after them is bounded here.
Opened with start(java.time.Duration), closed with close() — a try-with-resources
— and per thread: a call made on another thread is not bounded by it. Opening
one inside another keeps the earlier end when it is the sooner.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcheckNotSpent(String what) Fails when the budget has run out, or a request was refused or cut for it — a call that swallows such a failure (a read that leaves "those days as they are") would otherwise let the sequence go on as if it had read.voidclose()Closes the budget: the thread's previous one, if any, applies again.static DurationThe time left of the budget open on the current thread, for a write channel that does not send throughHttpCalDavClient— one another add-on contributes for an account (CalendarObjectWriters) — so that it bounds its own calls by it.static CalDavDeadlineOpens a budget on the current thread.
-
Method Details
-
start
Opens a budget on the current thread.- Parameters:
budget- the time the calls made untilclose()may take altogether- Returns:
- the budget, to close
-
remaining
The time left of the budget open on the current thread, for a write channel that does not send throughHttpCalDavClient— one another add-on contributes for an account (CalendarObjectWriters) — so that it bounds its own calls by it.- Returns:
- the time left,
Duration.ZEROonce it has run out (the budget is then spent), null when no budget is open
-
checkNotSpent
Fails when the budget has run out, or a request was refused or cut for it — a call that swallows such a failure (a read that leaves "those days as they are") would otherwise let the sequence go on as if it had read.- Parameters:
what- the step about to run, for the refusal- Throws:
CalDavDeadlineException- when it has run out
-
close
public void close()Closes the budget: the thread's previous one, if any, applies again.- Specified by:
closein interfaceAutoCloseable
-