A lease can expire while its holder is paused. If that old holder resumes after another client has acquired the lease, both clients may try to write. A fencing token lets the resource reject the delayed client's stale operation.
Design a FencingTokenValidator class:
FencingTokenValidator() creates a stateless validator.boolean[] validate(int[] tokens) reports whether each write is accepted.
For each call, the resource's highest accepted token starts at 0. Process tokens in order. Accept a token only when it is strictly greater than the highest token accepted earlier, then make it the new maximum. Reject a token that is less than or equal to the current maximum without changing that maximum.
Example 1:
Input:
Output:
Explanation: Token 5 is accepted. Token 3 is stale. Token 6 becomes the new maximum, the repeated 6 is rejected, and token 7 is accepted.
Example 2:
Input:
Output:
Explanation: Acceptance is strict. Once token 2 has been accepted, later writes with the same token are stale.
Constraints
1 <= tokens.length <= 10^51 <= tokens[i] <= 2^31 - 1- Each call starts with a highest accepted token of
0. - Preserve the input order in the returned array.
- At most
100 calls are made to validate.