class SimplePushEventSourceImpl<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> extends java.lang.Object implements SimplePushEventSource<T>
| Modifier and Type | Field and Description |
|---|---|
private boolean |
closed |
private java.util.List<PushEventConsumer<? super T>> |
connected |
private Deferred<java.lang.Void> |
connectPromise |
private java.lang.Object |
lock |
private java.lang.Runnable |
onClose |
private int |
parallelism |
private PromiseFactory |
promiseFactory |
private U |
queue |
private QueuePolicy<T,U> |
queuePolicy |
private PromiseFactory |
sameThread |
private java.util.concurrent.Semaphore |
semaphore |
private boolean |
waitForFinishes |
| Constructor and Description |
|---|
SimplePushEventSourceImpl(PromiseFactory promiseFactory,
QueuePolicy<T,U> queuePolicy,
U queue,
int parallelism,
java.lang.Runnable onClose) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this source.
|
private void |
close(PushEvent<T> event) |
private void |
closeConsumer(PushEventConsumer<? super T> pec,
PushEvent<T> event) |
private Promise<java.lang.Void> |
closedConnectPromise() |
Promise<java.lang.Void> |
connectPromise()
This method can be used to delay event generation until an event source
has connected.
|
private Promise<java.lang.Long> |
deliver(java.util.List<PushEventConsumer<? super T>> toCall,
PushEvent<T> event) |
private Promise<java.lang.Long> |
doCall(PushEvent<T> event,
PushEventConsumer<? super T> pec) |
private void |
doSend(PushEventConsumer<? super T> pec,
PushEvent<T> event) |
private Promise<java.lang.Long> |
doSendWithBackPressure(PushEventConsumer<? super T> pec,
PushEvent<T> event) |
void |
endOfStream()
Close this source for now, but potentially reopen it later.
|
private void |
enqueueEvent(PushEvent<T> event) |
void |
error(java.lang.Throwable t)
Close this source for now, but potentially reopen it later.
|
private void |
handleReset(boolean resetWait) |
boolean |
isConnected()
Determine whether there are any
PushEventConsumers for this
PushEventSource. |
java.lang.AutoCloseable |
open(PushEventConsumer<? super T> pec)
Open the asynchronous channel between the source and the consumer.
|
void |
publish(T t)
Asynchronously publish an event to this stream and all connected
PushEventConsumer instances. |
private long |
safePush(PushEventConsumer<? super T> pec,
PushEvent<T> event) |
private void |
startWorker() |
private final java.lang.Object lock
private final PromiseFactory promiseFactory
private final PromiseFactory sameThread
private final QueuePolicy<T,U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> queuePolicy
private final int parallelism
private final java.util.concurrent.Semaphore semaphore
private final java.util.List<PushEventConsumer<? super T>> connected
private final java.lang.Runnable onClose
private boolean closed
private Deferred<java.lang.Void> connectPromise
private boolean waitForFinishes
public SimplePushEventSourceImpl(PromiseFactory promiseFactory, QueuePolicy<T,U> queuePolicy, U queue, int parallelism, java.lang.Runnable onClose)
public java.lang.AutoCloseable open(PushEventConsumer<? super T> pec) throws java.lang.Exception
PushEventSourceAutoCloseable. This can be closed, and should
close the channel, including sending a Close event if the channel was not
already closed. The returned object must be able to be closed multiple
times without sending more than one Close events.open in interface PushEventSource<T>pec - the consumer (not null)AutoCloseable that can be used to close the streamjava.lang.Exceptionprivate void closeConsumer(PushEventConsumer<? super T> pec, PushEvent<T> event)
private void doSend(PushEventConsumer<? super T> pec, PushEvent<T> event)
private Promise<java.lang.Long> doSendWithBackPressure(PushEventConsumer<? super T> pec, PushEvent<T> event)
private long safePush(PushEventConsumer<? super T> pec, PushEvent<T> event)
public void close()
SimplePushEventSourcePushEventConsumer that tries to PushEventSource.open(PushEventConsumer)
this source will immediately receive a close event, and will not see any
remaining buffered events.close in interface java.lang.AutoCloseableclose in interface SimplePushEventSource<T>public void publish(T t)
SimplePushEventSourcePushEventConsumer instances. When this method returns there is no
guarantee that all consumers have been notified. Events published by a
single thread will maintain their relative ordering, however they may be
interleaved with events from other threads.publish in interface SimplePushEventSource<T>public void endOfStream()
SimplePushEventSourceSimplePushEventSource.publish(Object) method will be delivered before this close
event.
After calling this method any PushEventConsumer that wishes may
PushEventSource.open(PushEventConsumer) this source, and will receive subsequent
events.
endOfStream in interface SimplePushEventSource<T>public void error(java.lang.Throwable t)
SimplePushEventSourceSimplePushEventSource.publish(Object) method will be delivered before this error
event.
After calling this method any PushEventConsumer that wishes may
PushEventSource.open(PushEventConsumer) this source, and will receive subsequent
events.
error in interface SimplePushEventSource<T>t - the errorprivate void startWorker()
private void handleReset(boolean resetWait)
private Promise<java.lang.Long> deliver(java.util.List<PushEventConsumer<? super T>> toCall, PushEvent<T> event)
private Promise<java.lang.Long> doCall(PushEvent<T> event, PushEventConsumer<? super T> pec)
public boolean isConnected()
SimplePushEventSourcePushEventConsumers for this
PushEventSource. This can be used to skip expensive event
creation logic when there are no listeners.isConnected in interface SimplePushEventSource<T>public Promise<java.lang.Void> connectPromise()
SimplePushEventSourcePushEventConsumer instances have opened the
SimplePushEventSource.
The returned promise may already be resolved if this
SimplePushEventSource already has connected consumers. If the
SimplePushEventSource is closed before the returned Promise
resolves then it will be failed with an IllegalStateException.
Note that the connected consumers are able to asynchronously close their
connections to this SimplePushEventSource, and therefore it is
possible that once the promise resolves this
SimplePushEventSource may no longer be connected to any
consumers.
connectPromise in interface SimplePushEventSource<T>private Promise<java.lang.Void> closedConnectPromise()