Package org.osgi.util.pushstream
Class PushEvent<T>
java.lang.Object
org.osgi.util.pushstream.PushEvent<T>
- Type Parameters:
T
- The payload type of the event.
A PushEvent is an immutable object that is transferred through a
communication channel to push information to a downstream consumer. The event
has three different types:
PushEvent.EventType.DATA
– Provides access to a typed data element in the stream.PushEvent.EventType.CLOSE
– The stream is closed. After receiving this event, no more events will follow.PushEvent.EventType.ERROR
– The stream ran into an unrecoverable problem and is sending the reason downstream. The stream is closed and no more events will follow after this event.
- "Immutable"
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PushEvent<T>
close()
Create a new close event.static <T> PushEvent<T>
data
(T payload) Create a new data event.static <T> PushEvent<T>
Create a new error event.getData()
Return the data for this event.Return the error that terminated the stream.abstract PushEvent.EventType
getType()
Get the type of this event.boolean
Answer if no more events will follow after this event.<X> PushEvent<X>
nodata()
Convenience to cast a close/error event to another payload type.
-
Method Details
-
getType
Get the type of this event.- Returns:
- The type of this event.
-
getData
Return the data for this event.- Returns:
- The data payload.
- Throws:
IllegalStateException
- if this event is not aPushEvent.EventType.DATA
event.
-
getFailure
Return the error that terminated the stream.- Returns:
- The error that terminated the stream.
- Throws:
IllegalStateException
- if this event is not anPushEvent.EventType.ERROR
event.
-
isTerminal
public boolean isTerminal()Answer if no more events will follow after this event.- Returns:
false
if this is a data event, otherwisetrue
.
-
data
Create a new data event.- Type Parameters:
T
- The payload type.- Parameters:
payload
- The payload.- Returns:
- A new data event wrapping the specified payload.
-
error
Create a new error event.- Type Parameters:
T
- The payload type.- Parameters:
t
- The error.- Returns:
- A new error event with the specified error.
-
close
Create a new close event.- Type Parameters:
T
- The payload type.- Returns:
- A new close event.
-
nodata
Convenience to cast a close/error event to another payload type. Since the payload type is not needed for these events this is harmless. This therefore allows you to forward the close/error event downstream without creating anew event.- Type Parameters:
X
- The new payload type.- Returns:
- The current error or close event mapped to a new payload type.
- Throws:
IllegalStateException
- if the event is aPushEvent.EventType.DATA
event.
-