Class BroadcastReceiver

java.lang.Object
org.agrona.concurrent.broadcast.BroadcastReceiver

public class BroadcastReceiver extends Object
Receive messages broadcast from a BroadcastTransmitter via an underlying buffer. Receivers can join a transmission stream at any point by consuming the latest message at the point of joining and forward.

If a Receiver cannot keep up with the transmission stream then loss will be experienced. Loss is not an error condition.

Note: Each Receiver is not threadsafe but there can be zero or many receivers to a transmission stream.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new broadcast receiver based on an underlying AtomicBuffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    The underlying buffer containing the broadcast message stream.
    int
    Get the capacity of the underlying broadcast buffer.
    long
    Get the number of times the transmitter has lapped this receiver around the buffer.
    int
    The length of the next message in the transmission stream.
    int
    The offset for the beginning of the next message in the transmission stream.
    boolean
    Non-blocking receive of next message from the transmission stream.
    int
    Type of the message received.
    boolean
    Validate that the current received record is still valid and has not been overwritten.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • capacity

      public int capacity()
      Get the capacity of the underlying broadcast buffer.
      Returns:
      the capacity of the underlying broadcast buffer.
    • lappedCount

      public long lappedCount()
      Get the number of times the transmitter has lapped this receiver around the buffer. On each lap as least a buffer's worth of loss will be experienced.

      Note: This method is threadsafe for calling from an external monitoring thread. It will not provide any ordering guarantees with respect to loads/stores to other addresses.

      Returns:
      the capacity of the underlying broadcast buffer.
    • typeId

      public int typeId()
      Type of the message received.
      Returns:
      typeId of the message received.
    • offset

      public int offset()
      The offset for the beginning of the next message in the transmission stream.
      Returns:
      offset for the beginning of the next message in the transmission stream.
    • length

      public int length()
      The length of the next message in the transmission stream.
      Returns:
      length of the next message in the transmission stream.
    • buffer

      public MutableDirectBuffer buffer()
      The underlying buffer containing the broadcast message stream.
      Returns:
      the underlying buffer containing the broadcast message stream.
    • receiveNext

      public boolean receiveNext()
      Non-blocking receive of next message from the transmission stream.

      If loss has occurred then lappedCount() will be incremented.

      Returns:
      true if transmission is available with offset(), length() and typeId() set for the next message to be consumed. If no transmission is available then false.
    • validate

      public boolean validate()
      Validate that the current received record is still valid and has not been overwritten.

      If the receiver is not consuming messages fast enough to keep up with the transmitter then loss can be experienced resulting in messages being overwritten thus making them no longer valid.

      Returns:
      true if still valid otherwise false.