java.lang.Object
net.i2p.router.client.LeaseRequestState
Bundle up the data points necessary when asynchronously requesting a lease from a client.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longEarliest lease end seen so far.private final longTime past which the request is abandoned.private final JobJob run when the request fails.private final JobJob run when the request succeeds.private final LeaseSetThe lease set being requested.private booleanTrue once the outcome has been acted on.private booleanTrue once the request has succeeded.private intPublish retries used so far.(package private) static final intMaximum prompt re-requests after netdb publish() rejected the client's LeaseSet as expired.Constructor Summary
ConstructorsConstructorDescriptionLeaseRequestState(Job onGranted, Job onFailed, long currentEarliestLeastDate, long expiration, LeaseSet requested) Create a new LeaseRequestState.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) booleanClaim the single accounting resolution for this request.(package private) booleanClaim one attempt to re-request the LeaseSet after netdb publish() rejected it as expired (client clock skew or slow signing).longThe earliest lease expiration time in the current LS (NOT the requested one), or 0 if none.longWhen the request is abandoned if the client has not answered.booleanWhether the request was successful in the time allotted.The job to run if the lease set create fails or times out.The job to run once the lease set is created.The lease set this request is for.voidsetIsSuccessful(boolean is) Record whether the request was successful.toString()
Field Details
MAX_TRANSIENT_PUBLISH_RETRIES
static final int MAX_TRANSIENT_PUBLISH_RETRIESMaximum prompt re-requests after netdb publish() rejected the client's LeaseSet as expired. Bounds the retry loop when the client's clock or signer stays skewed; after the bound the timeout check resolves the request as before.- See Also:
_requestedLeaseSet
The lease set being requested._onGranted
Job run when the request succeeds._onFailed
Job run when the request fails._expiration
private final long _expirationTime past which the request is abandoned._currentEarliestLeastDate
private final long _currentEarliestLeastDateEarliest lease end seen so far._successful
private volatile boolean _successfulTrue once the request has succeeded._transientPublishRetries
private int _transientPublishRetriesPublish retries used so far._resolutionClaimed
private boolean _resolutionClaimedTrue once the outcome has been acted on.
Constructor Details
LeaseRequestState
public LeaseRequestState(Job onGranted, Job onFailed, long currentEarliestLeastDate, long expiration, LeaseSet requested) Create a new LeaseRequestState.- Parameters:
onGranted- job to run on successonFailed- job to run on failurecurrentEarliestLeastDate- absolute time, the earliest expiration in the current LS (NOT the requested one), or 0 if noneexpiration- absolute time, when the request expires (not when the LS expires)requested- LeaseSet with requested leases - this object must be updated to contain the signed version (as well as any changed/added/removed Leases) The LeaseSet contains Leases and destination only, it is unsigned.
Method Details
getRequested
The lease set this request is for.- Returns:
- the unsigned lease set, updated in place once it is signed
getOnGranted
The job to run once the lease set is created.- Returns:
- what to do once the lease set is created
getOnFailed
The job to run if the lease set create fails or times out.- Returns:
- what to do if the lease set create fails / times out
getExpiration
public long getExpiration()When the request is abandoned if the client has not answered.- Returns:
- absolute adjusted time in ms, not the lease set's own expiration
getCurrentEarliestLeaseDate
public long getCurrentEarliestLeaseDate()The earliest lease expiration time in the current LS (NOT the requested one), or 0 if none.- Returns:
- the earliest lease date
getIsSuccessful
public boolean getIsSuccessful()Whether the request was successful in the time allotted.- Returns:
- true if successful
setIsSuccessful
public void setIsSuccessful(boolean is) Record whether the request was successful.- Parameters:
is- true if successful
claimTransientPublishRetry
boolean claimTransientPublishRetry()Claim one attempt to re-request the LeaseSet after netdb publish() rejected it as expired (client clock skew or slow signing). The firstMAX_TRANSIENT_PUBLISH_RETRIEScallers receive true so the request is promptly re-run with freshly floored lease times. Later callers receive false so a persistently skewed client cannot loop.- Returns:
- true if a retry attempt is available
claimCheckResolution
boolean claimCheckResolution()Claim the single accounting resolution for this request. Exactly one resolution path (early job failure, timeout-check success, or timeout-check failure) proceeds past this claim, so onFailed fires at most once and success/timeout stats are never double-counted when several checks or a retry and a check race each other.- Returns:
- true if the caller owns the resolution
toString