Class NotificationSupervisor.Builder
java.lang.Object
com.pyranid.NotificationSupervisor.Builder
- Enclosing class:
NotificationSupervisor
Builder for a single-use supervisor. No work starts until
NotificationSupervisor.start().- Since:
- 4.8.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a supervisor without acquiring resources.Sets the nonempty, fixed channel set, copying it immediately.onReconciliationFailure(@NonNull Consumer<? super Throwable> observer) Observes recoverable managed reconciliation failures.Enables an immediate poll and subsequent fixed-delay reconciliation independent of listener I/O/backoff.Sets bounded, repeatable reconciliation, requested after registration and each nonempty batch.retry(@NonNull Predicate<? super NotificationSupervisor.RetryFailure> condition, @NonNull RetryPolicy.Backoff backoff, @NonNull Duration stabilityWindow) Enables explicit retry classification and backoff, including during startup.threadFactory(@NonNull Function<? super NotificationSupervisor.ThreadRole, ? extends ThreadFactory> factoryForRole) Customizes managed workers by logical role.
-
Method Details
-
channels
-
reconcile
Sets bounded, repeatable reconciliation, requested after registration and each nonempty batch. Managed workers also serve optional polling; requests share a successful pass begun after each request.- Parameters:
reconciler- application operation that reads or claims authoritative durable state- Returns:
- this builder
-
pollEvery
Enables an immediate poll and subsequent fixed-delay reconciliation independent of listener I/O/backoff. Recoverable database failures are retried by later polls without reconnecting the listener.- Parameters:
interval- positive delay after a pass before the next periodic pass- Returns:
- this builder
-
threadFactory
public @NonNull NotificationSupervisor.Builder threadFactory(@NonNull Function<? super NotificationSupervisor.ThreadRole, ? extends ThreadFactory> factoryForRole) Customizes managed workers by logical role. The function is resolved at start, not per task, and must return non-null factories producing distinct new, unstarted threads. The supervisor owns those workers.- Parameters:
factoryForRole- role-to-factory mapping; omit this setting to use named daemon workers- Returns:
- this builder
-
onReconciliationFailure
public @NonNull NotificationSupervisor.Builder onReconciliationFailure(@NonNull Consumer<? super Throwable> observer) Observes recoverable managed reconciliation failures. Runs on the reconciliation worker, outside locks; it must be bounded and must not await shutdown. An observer failure terminates the supervisor.- Parameters:
observer- failure observer- Returns:
- this builder
-
retry
public @NonNull NotificationSupervisor.Builder retry(@NonNull Predicate<? super NotificationSupervisor.RetryFailure> condition, @NonNull RetryPolicy.Backoff backoff, @NonNull Duration stabilityWindow) Enables explicit retry classification and backoff, including during startup.A retryable startup failure leaves first readiness pending. Reconciliation failures are offered to the policy only when they are
DatabaseExceptions. Unsupported capabilities, other application exceptions, errors, and failures in the policy terminate. Stop or interruption prevents retries and preserves observed failures. With managed polling enabled, recoverable reconciliation failures await the next poll instead of reconnecting; listener open/receive/cleanup failures still use this policy.- Parameters:
condition- decides whether a database failure is retryablebackoff- chooses a nonnegative delay after each selected failurestabilityWindow- positive established-session duration needed to reset consecutive failure escalation- Returns:
- this builder
-
build
Builds a supervisor without acquiring resources. Channels and reconciliation are required.- Returns:
- a new, unstarted supervisor
- Throws:
IllegalStateException- if channels or reconciliation have not been configured
-