Class MessageAsync<M extends Message>

  • All Implemented Interfaces:

    public class MessageAsync<M extends Message>
    extends SingleSender<M>
    implements MessageReceiver<M>
    A sub-class of SingleSender which lets the drain's receive method run asynchronouously in a separate thread.

    All received messages are stored internally in a buffer, and the MessageReceiver.receive(Message) method of the currently set SingelSender#receiver is executed in a loop in an own, specially constructed Thread, consuming all these messages asynchronouously.
    The caller of the here defined receive(Message) thus returns immediately, after writing the message into a buffer object. (This is currently a LinkedBlockingQueue.)
    • Field Detail

      • queue

        final java.util.concurrent.LinkedBlockingQueue<M extends Message> queue
      • interrupted

        boolean interrupted
      • thread

        final java.lang.Thread thread
    • Method Detail

      • receive

        public void receive​(M m)
        Returns immediately after storing the message to the internal buffer.

        Will block whenever this buffer is full. Normally this should never happen, since the consumer thread should not "starve" under normal scheduling discipline.
        Overrun is probably some kamikaze problem with the producer, since the buffer has a capacity of Integer.MAX_VALUE messages.
        Specified by:
        receive in interface MessageReceiver<M extends Message>