Interface RequestLogAccess
- All Known Subinterfaces:
RequestLog
,RequestLogBuilder
,RequestOnlyLog
public interface RequestLogAccess
Provides the access to a
RequestLog
or RequestOnlyLog
, while ensuring the interested
RequestLogProperty
s are available.
The properties provided by RequestLog
are not always fully available. Use the following
methods to access the properties safely:
isComplete()
orwhenComplete()
to check if or to get notified when all request and response properties are available.isRequestComplete()
orwhenRequestComplete()
to check if or to get notified when all request properties are available.isAvailable(RequestLogProperty)
,isAvailable(RequestLogProperty...)
,isAvailable(Iterable)
,whenAvailable(RequestLogProperty)
,whenAvailable(RequestLogProperty...)
orwhenAvailable(Iterable)
to check if or to get notified when a certain set of properties are available.
If you are sure that certain properties are available, you can convert a RequestLogAccess
into
a RequestLog
or RequestOnlyLog
by using the "ensure*()"
methods, such as
ensureComplete()
and ensureRequestComplete()
.
-
Method Summary
Modifier and Type Method Description int
availabilityStamp()
Returns anint
representation of the currently available properties of thisRequestLog
.List<RequestLogAccess>
children()
Returns the list ofRequestLogAccess
es that provide access to the childRequestLog
s, ordered by the time they were added.RequestContext
context()
Returns theRequestContext
associated with theRequest
being handled.RequestLog
ensureAvailable(RequestLogProperty property)
Returns theRequestLog
that is guaranteed to have the specifiedRequestLogProperty
.RequestLog
ensureAvailable(RequestLogProperty... properties)
Returns theRequestLog
that is guaranteed to have all the specifiedRequestLogProperty
s.RequestLog
ensureAvailable(Iterable<RequestLogProperty> properties)
Returns theRequestLog
that is guaranteed to have all the specifiedRequestLogProperty
s.RequestLog
ensureComplete()
Returns theRequestLog
that is guaranteed to have all properties, for both request and response side.RequestOnlyLog
ensureRequestComplete()
Returns theRequestLog
that is guaranteed to have all request-side properties.boolean
isAvailable(RequestLogProperty property)
Returnstrue
if the specifiedRequestLogProperty
is available.boolean
isAvailable(RequestLogProperty... properties)
Returnstrue
if all of the specifiedRequestLogProperty
s are available.boolean
isAvailable(Iterable<RequestLogProperty> properties)
Returnstrue
if all of the specifiedRequestLogProperty
s are available.boolean
isComplete()
Returnstrue
if theRequest
has been processed completely and thus all properties of theRequestLog
have been collected.boolean
isRequestComplete()
Returnstrue
if theRequest
has been consumed completely and thus all properties of theRequestOnlyLog
have been collected.RequestLogAccess
parent()
Returns theRequestLogAccess
that provides access to the parentRequestLog
.RequestLog
partial()
Returns theRequestLog
for theRequest
, where all properties may not be available yet.CompletableFuture<RequestLog>
whenAvailable(RequestLogProperty property)
Returns aCompletableFuture
which will be completed when the specifiedRequestLogProperty
is collected.CompletableFuture<RequestLog>
whenAvailable(RequestLogProperty... properties)
Returns aCompletableFuture
which will be completed when all the specifiedRequestLogProperty
s are collected.CompletableFuture<RequestLog>
whenAvailable(Iterable<RequestLogProperty> properties)
Returns aCompletableFuture
which will be completed when all the specifiedRequestLogProperty
s are collected.CompletableFuture<RequestLog>
whenComplete()
Returns aCompletableFuture
which will be completed when theRequest
has been processed completely and thus all properties of theRequestLog
have been collected.CompletableFuture<RequestOnlyLog>
whenRequestComplete()
Returns aCompletableFuture
which will be completed when theRequest
has been consumed completely and thus all properties of theRequestOnlyLog
have been collected.
-
Method Details
-
isComplete
boolean isComplete()Returnstrue
if theRequest
has been processed completely and thus all properties of theRequestLog
have been collected. -
isRequestComplete
boolean isRequestComplete()Returnstrue
if theRequest
has been consumed completely and thus all properties of theRequestOnlyLog
have been collected. -
isAvailable
Returnstrue
if the specifiedRequestLogProperty
is available. -
isAvailable
Returnstrue
if all of the specifiedRequestLogProperty
s are available.- Throws:
IllegalArgumentException
- ifproperties
is empty.
-
isAvailable
Returnstrue
if all of the specifiedRequestLogProperty
s are available.- Throws:
IllegalArgumentException
- ifproperties
is empty.
-
whenComplete
CompletableFuture<RequestLog> whenComplete()Returns aCompletableFuture
which will be completed when theRequest
has been processed completely and thus all properties of theRequestLog
have been collected. The returnedCompletableFuture
is never completed exceptionally.logAccess.whenComplete().thenAccept(log -> { HttpStatus status = log.responseHeaders().status(); if (status == HttpStatus.OK) { ... } });
-
whenRequestComplete
CompletableFuture<RequestOnlyLog> whenRequestComplete()Returns aCompletableFuture
which will be completed when theRequest
has been consumed completely and thus all properties of theRequestOnlyLog
have been collected. The returnedCompletableFuture
is never completed exceptionally.logAccess.whenRequestComplete().thenAccept(log -> { SerializationFormat serFmt = log.scheme().serializationFormat(); if (serFmt == ThriftSerializationFormats.BINARY) { ... } });
-
whenAvailable
Returns aCompletableFuture
which will be completed when the specifiedRequestLogProperty
is collected. The returnedCompletableFuture
is never completed exceptionally. Note that the completion of the returnedCompletableFuture
guarantees only the availability of the specified property, which means any attempt to access other properties than specified may trigger aRequestLogAvailabilityException
. If in doubt, usewhenComplete()
orwhenRequestComplete()
.logAccess.whenAvailable(RequestLogProperty.REQUEST_HEADERS) .thenAccept(log -> { RequestHeaders headers = log.requestHeaders(); if (headers.path().startsWith("/foo/")) { ... } });
-
whenAvailable
Returns aCompletableFuture
which will be completed when all the specifiedRequestLogProperty
s are collected. The returnedCompletableFuture
is never completed exceptionally. Note that the completion of the returnedCompletableFuture
guarantees only the availability of the specified properties, which means any attempt to access other properties than specified may trigger aRequestLogAvailabilityException
. If in doubt, usewhenComplete()
orwhenRequestComplete()
.logAccess.whenAvailable(RequestLogProperty.REQUEST_HEADERS, RequestLogProperty.RESPONSE_HEADERS) .thenAccept(log -> { RequestHeaders reqHeaders = log.requestHeaders(); ResponseHeaders resHeaders = log.responseHeaders(); if (reqHeaders.path().startsWith("/foo/") && resHeaders.status() == HttpStatus.OK) { ... } });
- Throws:
IllegalArgumentException
- ifproperties
is empty.
-
whenAvailable
Returns aCompletableFuture
which will be completed when all the specifiedRequestLogProperty
s are collected. The returnedCompletableFuture
is never completed exceptionally. Note that the completion of the returnedCompletableFuture
guarantees only the availability of the specified properties, which means any attempt to access other properties than specified may trigger aRequestLogAvailabilityException
. If in doubt, usewhenComplete()
orwhenRequestComplete()
.logAccess.whenAvailable(Lists.of(RequestLogProperty.REQUEST_HEADERS, RequestLogProperty.RESPONSE_HEADERS)) .thenAccept(log -> { RequestHeaders reqHeaders = log.requestHeaders(); ResponseHeaders resHeaders = log.responseHeaders(); if (reqHeaders.path().startsWith("/foo/") && resHeaders.status() == HttpStatus.OK) { ... } });
- Throws:
IllegalArgumentException
- ifproperties
is empty.
-
ensureComplete
RequestLog ensureComplete()Returns theRequestLog
that is guaranteed to have all properties, for both request and response side.- Throws:
RequestLogAvailabilityException
- if theRequest
was not fully processed yet.
-
ensureRequestComplete
RequestOnlyLog ensureRequestComplete()Returns theRequestLog
that is guaranteed to have all request-side properties.- Throws:
RequestLogAvailabilityException
- if theRequest
was not fully consumed yet.
-
ensureAvailable
Returns theRequestLog
that is guaranteed to have the specifiedRequestLogProperty
.- Throws:
RequestLogAvailabilityException
- if the specifiedRequestLogProperty
is not available yet.
-
ensureAvailable
Returns theRequestLog
that is guaranteed to have all the specifiedRequestLogProperty
s.- Throws:
RequestLogAvailabilityException
- if any of the specifiedRequestLogProperty
s are not available yet.IllegalArgumentException
- ifproperties
is empty.
-
ensureAvailable
Returns theRequestLog
that is guaranteed to have all the specifiedRequestLogProperty
s.- Throws:
RequestLogAvailabilityException
- if any of the specifiedRequestLogProperty
s are not available yet.IllegalArgumentException
- ifproperties
is empty.
-
partial
RequestLog partial()Returns theRequestLog
for theRequest
, where all properties may not be available yet. Note that this method is potentially unsafe; an attempt to access an unavailable property will trigger aRequestLogAvailabilityException
. If in doubt, usewhenComplete()
orwhenRequestComplete()
. Always consider guarding the property access withisAvailable(RequestLogProperty)
when you have to use this method:RequestLogAccess logAccess = ...; if (logAccess.isAvailable(RequestLogProperty.REQUEST_HEADERS)) { RequestHeaders headers = logAccess.partial().requestHeaders(); ... }
-
availabilityStamp
int availabilityStamp()Returns anint
representation of the currently available properties of thisRequestLog
. This can be useful when needing to quickly compare the availability of theRequestLog
during the processing of the request. UseisAvailable(RequestLogProperty)
to actually check availability. -
context
RequestContext context()Returns theRequestContext
associated with theRequest
being handled.This method always returns non-
null
regardless of what properties are currently available. -
parent
Returns theRequestLogAccess
that provides access to the parentRequestLog
.null
is returned if theRequestLog
was not added as a child log. -
children
List<RequestLogAccess> children()Returns the list ofRequestLogAccess
es that provide access to the childRequestLog
s, ordered by the time they were added.
-