Class NotificationSession
Instances are supplied only to NotificationSessionOperation by
Database.withNotificationSession(String, NotificationSessionOperation) or
Database.withNotificationSession(java.util.Set, NotificationSessionOperation). A session is confined to
the callback thread, expires when that callback exits, and never reconnects. It exposes no lifecycle snapshot:
an apparently quiet session is not proof that its physical connection remains healthy.
Notification delivery is lossy and non-durable. Treat each returned batch as a hint to reconcile authoritative state rather than as an event count or work queue.
- Since:
- 4.6.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescription@NonNull List<@NonNull Notification> awaitNotifications(@NonNull Duration maxWait) Waits for a nonempty batch of notifications, until the best-effort elapsed-time budget expires.@NonNull List<@NonNull Notification> Polls the existing listener connection once using the adapter's driver-specific non-waiting mode.
-
Method Details
-
awaitNotifications
public @NonNull List<@NonNull Notification> awaitNotifications(@NonNull Duration maxWait) throws InterruptedException Waits for a nonempty batch of notifications, until the best-effort elapsed-time budget expires.Pyranid divides positive waits into driver calls of at most 250 milliseconds so interruption can normally be observed between calls. The budget is not a hard completion deadline: a JDBC driver call already in progress may overrun it. A zero duration has exactly the polling semantics of
drainNotifications().A nonempty batch wins over an interrupt that races after the driver returns; the batch is returned and the interrupt flag remains set for application code or the next receive to observe.
- Parameters:
maxWait- maximum best-effort elapsed time to wait, which must not be negative- Returns:
- an immutable notification batch, empty only when the budget expires without an observed notification
- Throws:
NullPointerException- ifmaxWaitis nullIllegalArgumentException- ifmaxWaitis negativeIllegalStateException- if the session is expired, failed, used from another thread, used reentrantly, or used while any Pyranid transaction is active on this threadInterruptedException- if interruption is observed before protocol work or after an empty receiveDatabaseException- if notification transport fails- Since:
- 4.6.0
-
drainNotifications
Polls the existing listener connection once using the adapter's driver-specific non-waiting mode.The method performs no acquisition, registration, sleep, reconnect, or reconciliation. A nonempty batch wins over an interrupt that races after the driver returns.
- Returns:
- an immutable notification batch, possibly empty
- Throws:
IllegalStateException- if the session is expired, failed, used from another thread, used reentrantly, or used while any Pyranid transaction is active on this threadInterruptedException- if interruption is observed before protocol work or after an empty receiveDatabaseException- if notification transport fails- Since:
- 4.6.0
-