Class SseSubscription
java.lang.Object
org.apache.juneau.rest.server.sse.SseSubscription
- All Implemented Interfaces:
AutoCloseable,Iterable<SseEvent>
Subscriber queue for an
SseBroadcaster.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getId()The subscriber identifier.booleanisClosed()Returns whether this subscription has been closed.iterator()booleanQueues an event, dropping the oldest queued event when the queue is full.Waits up to a timeout for the next event.take()Blocks until the next event is available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getId
The subscriber identifier.- Returns:
- The subscriber identifier.
-
isClosed
Returns whether this subscription has been closed.- Returns:
trueif this subscription has been closed.
-
offer
Queues an event, dropping the oldest queued event when the queue is full.Does nothing once the subscription is closed.
SseBroadcaster.publish(SseEvent)calls this for every subscriber; call it directly to address a single subscriber.- Parameters:
event- The event. Must not benull .- Returns:
trueif the oldest queued event was dropped to make room.
-
take
Blocks until the next event is available.- Returns:
- The next event.
- Throws:
InterruptedException- If the wait was interrupted.
-
poll
Waits up to a timeout for the next event.Unlike
take(), returns once the subscription is closed (within about 50 ms of the close), so a caller whose subscription was replaced or closed from another thread never hangs. The 50 ms bound applies to a waitingpoll;take()is not woken byclose().- Parameters:
timeout- How long to wait. Must not benull .- Returns:
- The next event, or
null on timeout or once the subscription is closed. - Throws:
InterruptedException- If the wait was interrupted.
-
iterator
-
close
- Specified by:
closein interfaceAutoCloseable
-