Class ServiceCreateRetryConfiguration.Builder
java.lang.Object
eu.cloudnetservice.driver.service.ServiceCreateRetryConfiguration.Builder
- Enclosing class:
ServiceCreateRetryConfiguration
Represents a builder for a creation retry configuration.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<ServiceCreateResult.State, List<ChannelMessageTarget>> private int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackoffStrategy(@NonNull Collection<Duration> backoffStrategy) Sets the backoff strategy when retrying a service creation.build()Builds a new retry configuration based on the previously supplied properties.fixedRetryDelay(@NonNull Duration delay) Sets the delay between each service creation retry to the given duration.maxRetries(@Range(from=1L,to=2147483647L) int maxRetries) Sets the maximum amount of times to retry the service creation.modifyBackoffStrategy(@NonNull Consumer<List<Duration>> modifier) Modifies the backoff strategy which is currently applied to this builder.notificationReceivers(@NonNull ChannelMessageTarget... receivers) Sets the receivers of state change events when a service creation which was deferred either succeeded or failed.notificationReceivers(ServiceCreateResult.State state, @NonNull ChannelMessageTarget... receivers) Sets the receivers of state change events when a service creation which was deferred reached the given target state of the service creation.notificationReceivers(@NonNull Map<ServiceCreateResult.State, List<ChannelMessageTarget>> eventReceivers) Sets the event receivers for state changes.
-
Field Details
-
maxRetries
private int maxRetries -
backoffStrategy
-
eventReceivers
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
maxRetries
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder maxRetries(@Range(from=1L,to=2147483647L) int maxRetries) Sets the maximum amount of times to retry the service creation. Only numbers higher than zero are accepted by the method.If you want zero retries (or in other words no retries) use
ServiceCreateRetryConfiguration.NO_RETRYinstead.- Parameters:
maxRetries- the maximum amount of retries to do before marking the creation as failed.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
IllegalArgumentException- if the given max retries are lower or equal to zero.
-
fixedRetryDelay
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder fixedRetryDelay(@NonNull @NonNull Duration delay) Sets the delay between each service creation retry to the given duration.- Parameters:
delay- the fixed delay between each service creation retry.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given retry duration is null.
-
backoffStrategy
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder backoffStrategy(@NonNull @NonNull Collection<Duration> backoffStrategy) Sets the backoff strategy when retrying a service creation. Each index in the given collection will be used for the retry delay, the first one as the initial delay before the first retry. If the retry count exceeds the entries in the given collection, a fixed retry delay based on the last index will be used for further retries.- Parameters:
backoffStrategy- the backoff strategy to apply when retrying a service creation.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given backoff strategy is null.
-
modifyBackoffStrategy
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder modifyBackoffStrategy(@NonNull @NonNull Consumer<List<Duration>> modifier) Modifies the backoff strategy which is currently applied to this builder.- Parameters:
modifier- the modifier to apply to the already added backoff entries of this builder.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given modifier function is null.
-
notificationReceivers
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder notificationReceivers(@NonNull @NonNull ChannelMessageTarget... receivers) Sets the receivers of state change events when a service creation which was deferred either succeeded or failed. The given targets will be notified about both these events. Already added receivers for one of the states will get overridden.The event will not be called on the receivers if no retry was needed, therefore the service either got created instantly or the creation failed because no retry was specified.
- Parameters:
receivers- the receivers for state event changes of deferred service creations.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given receivers are null.
-
notificationReceivers
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder notificationReceivers(@NonNull ServiceCreateResult.State state, @NonNull @NonNull ChannelMessageTarget... receivers) Sets the receivers of state change events when a service creation which was deferred reached the given target state of the service creation. Already added receivers for the same state will get overridden.The event will not be called on the receivers if no retry was needed, therefore the service either got created instantly or the creation failed because no retry was specified.
- Parameters:
state- the state in which the deferred service creation must run in order to call the receivers.receivers- the receivers for state event changes of deferred service creations.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given state or receivers are null.
-
notificationReceivers
@NonNull public @NonNull ServiceCreateRetryConfiguration.Builder notificationReceivers(@NonNull @NonNull Map<ServiceCreateResult.State, List<ChannelMessageTarget>> eventReceivers) Sets the event receivers for state changes. These are mapped in a state-to-receivers relation, meaning that all receivers for key state will be called when a deferred creation results in the state. Adding receivers for theDEFERREDstate is acceptable but will be without effect.The event will not be called on the receivers if no retry was needed, therefore the service either got created instantly or the creation failed because no retry was specified.
- Parameters:
eventReceivers- the receivers mapping for state changes of deferred services.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given receiver mapping is null.
-
build
Builds a new retry configuration based on the previously supplied properties.- Returns:
- a new retry configuration based on this builder.
- Throws:
IllegalArgumentException- if the backoff strategy has no entries.
-