Interface Emitter<T>

  • Type Parameters:
    T - type of payload or Message.
    All Known Implementing Classes:
    EmitterImpl

    public interface Emitter<T>
    Interface used to feed a stream from an imperative piece of code.

    Instances are injected using:

     @Inject
     @Channel("my-channel")
     Emitter<String> emitter;
     

    You can inject emitter sending payload or Messages.

    The name of the channel (given in the Channel annotation) indicates which streams is fed. It must match the name used in a method using @Incoming or an outgoing stream configured in the application configuration.

    • Method Detail

      • send

        CompletionStage<Void> send​(T msg)
        Sends a payload to the channel.
        Parameters:
        msg - the thing to send, must not be null
        Returns:
        the CompletionStage, which will be completed as sending the payload alone does not provide a callback mechanism.
        Throws:
        IllegalStateException - if the channel has been canceled or terminated.
      • send

        <M extends Message<? extends T>> void send​(M msg)
        Sends a payload to the channel.
        Type Parameters:
        M - the Message type
        Parameters:
        msg - the Message to send, must not be null
        Throws:
        IllegalStateException - if the channel has been canceled or terminated.
      • complete

        void complete()
        Sends the completion event to the channel indicating that no other events will be sent afterward.
      • error

        void error​(Exception e)
        Sends a failure event to the channel. No more events will be sent afterward.
        Parameters:
        e - the exception, must not be null
      • isCancelled

        boolean isCancelled()
        Returns:
        true if the emitter has been terminated or the subscription cancelled.
      • isRequested

        boolean isRequested()
        Returns:
        true if the subscriber accepts messages, false otherwise. Using send(Object) on an emitter not expecting message would throw an IllegalStateException.