T
- The type of the events produced by this source@ProviderType public interface SimplePushEventSource<T> extends PushEventSource<T>, java.lang.AutoCloseable
SimplePushEventSource
is a helper that makes it simpler to write a
PushEventSource
. Users do not need to manage multiple registrations
to the stream, nor do they have to be concerned with back pressure.Modifier and Type | Method and Description |
---|---|
void |
close()
Close this source.
|
Promise<java.lang.Void> |
connectPromise()
This method can be used to delay event generation until an event source
has connected.
|
void |
endOfStream()
Close this source for now, but potentially reopen it later.
|
void |
error(java.lang.Throwable t)
Close this source for now, but potentially reopen it later.
|
boolean |
isConnected()
Determine whether there are any
PushEventConsumer s for this
PushEventSource . |
void |
publish(T t)
Asynchronously publish an event to this stream and all connected
PushEventConsumer instances. |
open
void close()
PushEventConsumer
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.AutoCloseable
void publish(T t)
PushEventConsumer
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.t
- java.lang.IllegalStateException
- if the source is closedvoid endOfStream()
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.
void error(java.lang.Throwable t)
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.
t
- the errorboolean isConnected()
PushEventConsumer
s for this
PushEventSource
. This can be used to skip expensive event
creation logic when there are no listeners.Promise<java.lang.Void> connectPromise()
PushEventConsumer
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.
Copyright © OSGi Alliance (2000, 2018). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0