Class PushEvent<T>

  • Type Parameters:
    T - The payload type of the event.

    @ProviderType
    public abstract class PushEvent<T>
    extends java.lang.Object
    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.
    • Method Detail

      • getType

        public abstract PushEvent.EventType getType()
        Get the type of this event.
        Returns:
        The type of this event.
      • getData

        public T getData()
        Return the data for this event.
        Returns:
        The data payload.
        Throws:
        java.lang.IllegalStateException - if this event is not a PushEvent.EventType.DATA event.
      • getFailure

        public java.lang.Throwable getFailure()
        Return the error that terminated the stream.
        Returns:
        The error that terminated the stream.
        Throws:
        java.lang.IllegalStateException - if this event is not an PushEvent.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, otherwise true.
      • data

        public static <T> PushEvent<T> data​(T payload)
        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

        public static <T> PushEvent<T> error​(java.lang.Throwable t)
        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

        public static <T> PushEvent<T> close()
        Create a new close event.
        Type Parameters:
        T - The payload type.
        Returns:
        A new close event.
      • nodata

        public <X> PushEvent<X> 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:
        java.lang.IllegalStateException - if the event is a PushEvent.EventType.DATA event.