Class SnapshotConsumer.Builder
- java.lang.Object
-
- io.datareplication.consumer.snapshot.SnapshotConsumer.Builder
-
- Enclosing interface:
- SnapshotConsumer
public static class SnapshotConsumer.Builder extends java.lang.Object
A builder forSnapshotConsumer
.Each of the builder methods modifies the state of the builder and returns the same instance. Because of that, builders are not thread-safe.
- See Also:
SnapshotConsumer.builder()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NonNull SnapshotConsumer.Builder
additionalHeaders(@NonNull HttpHeader... headers)
Add the given headers to every HTTP request made by this consumer.@NonNull SnapshotConsumer.Builder
authorization(@NonNull Authorization authorization)
Use the givenAuthorization
for every HTTP request made by this consumer.@NonNull SnapshotConsumer.Builder
authorization(@NonNull java.util.function.Supplier<@NonNull Authorization> authorizationSupplier)
Use the given function to get theAuthorization
to use for HTTP requests made by this consumer.@NonNull SnapshotConsumer
build()
Build a newSnapshotConsumer
with the parameters set on this builder.@NonNull SnapshotConsumer.Builder
delayErrors(boolean delayErrors)
When enabled, collect all errors and raise them at the end after all other pages/entities have been consumed.@NonNull SnapshotConsumer.Builder
networkConcurrency(int networkConcurrency)
Set the maximum number of pages to download concurrently.
-
-
-
Method Detail
-
additionalHeaders
@NonNull public @NonNull SnapshotConsumer.Builder additionalHeaders(@NonNull @NonNull HttpHeader... headers)
Add the given headers to every HTTP request made by this consumer. Calling this method multiple times will add all the headers from all calls.- Parameters:
headers
- headers to add to every HTTP request- Returns:
- this builder
-
authorization
@NonNull public @NonNull SnapshotConsumer.Builder authorization(@NonNull @NonNull Authorization authorization)
Use the givenAuthorization
for every HTTP request made by this consumer.- Parameters:
authorization
- the Authorization to use for HTTP requests- Returns:
- this builder
-
authorization
@NonNull public @NonNull SnapshotConsumer.Builder authorization(@NonNull @NonNull java.util.function.Supplier<@NonNull Authorization> authorizationSupplier)
Use the given function to get the
Authorization
to use for HTTP requests made by this consumer. The function is called once for each request.The given function is expected to return quickly to avoid holding up requests. Because of that, the function should not perform any network requests. If your service requires a fresh authentication token periodically, the recommended approach is to perform the refresh out-of-band (e.g. on a separate thread with a timer) and write the new token to a shared memory location that the supplier function then reads from.
- Parameters:
authorizationSupplier
- a function returning the Authorization to use for HTTP requests- Returns:
- this builder
-
networkConcurrency
@NonNull public @NonNull SnapshotConsumer.Builder networkConcurrency(int networkConcurrency)
Set the maximum number of pages to download concurrently. Defaults to 2.
Setting this to 1 will will perform downloads fully sequentially; this guarantees ordering, i.e. pages will be returned exactly in the order they are listed in the index. Any value >1 may return entities and pages out of order to maximize throughput.
- Parameters:
networkConcurrency
- the number of pages to download concurrently- Returns:
- the builder
- Throws:
java.lang.IllegalArgumentException
- if the argument is <= 0
-
delayErrors
@NonNull public @NonNull SnapshotConsumer.Builder delayErrors(boolean delayErrors)
When enabled, collect all errors and raise them at the end after all other pages/entities have been consumed. Defaults to false, i.e. any error terminates the stream immediately.
When this setting is enabled, errors while downloading and parsing pages will be silently collected. Once all pages have been downloaded and returned, the collected exceptions will be raised on the stream wrapped in a
ConsumerException.CollectedErrors
object.- Parameters:
delayErrors
- when true, delay all errors until the entire snapshot has been processed- Returns:
- the builder
-
build
@NonNull public @NonNull SnapshotConsumer build()
Build a newSnapshotConsumer
with the parameters set on this builder.- Returns:
- a new
SnapshotConsumer
-
-