Interface RequestAuthorizer.Proactive

All Superinterfaces:
RequestAuthorizer
All Known Implementing Classes:
OidcRequestAuthorizer
Enclosing interface:
RequestAuthorizer

public static interface RequestAuthorizer.Proactive extends RequestAuthorizer

An authorizer that can tell, before a request is sent, that its credential is about to stop working, and renew it first.

Without this a credential is renewed only after the service has refused it, which costs one refused request for every credential that expires. An authorizer that implements this is asked when a request is queued -- on the event dispatch thread, before the request reaches a network thread -- and may hold the request until a new credential is ready. The request is then queued as usual and RequestAuthorizer.getAuthorization(ConnectionRequest) answers with the new one. A 401 is still handled as RequestAuthorizer describes; this only makes it rare.

Nothing waits on a thread for it: the request is simply not in the queue yet. Code that waits for the request waits a little longer, and sees one answer.

  • Method Details

    • prepareAuthorization

      AsyncResource<Boolean> prepareAuthorization(ConnectionRequest request)

      Called when a request this authorizer covers is queued, on the event dispatch thread. Answer from memory and do not block: start the renewal and return.

      Several requests can be queued while one renewal runs. An implementation should renew once and hold them all on the same resource.

      Parameters
      • request: the request being queued
      Returns

      null when the request can be sent as it is; otherwise a resource that completes when it can -- with any value, or with an error: the request is sent either way, with whatever RequestAuthorizer.getAuthorization(ConnectionRequest) answers then