Class ReadableCounter

java.lang.Object
io.aeron.status.ReadableCounter
All Implemented Interfaces:
AutoCloseable

public final class ReadableCounter extends Object implements AutoCloseable
Readonly view of an associated Counter.

Note:The user should call isClosed() and ensure the result is false to avoid a race on reading a closed Counter.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ReadableCounter(CountersReader countersReader, int counterId)
    Construct a view of an existing counter.
    ReadableCounter(CountersReader countersReader, long registrationId, int counterId)
    Construct a view of an existing counter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close this counter.
    int
    Return the counter id.
    long
    get()
    Get the latest value for the counter with volatile semantics.
    long
    Get the value of the counter using plain memory semantics.
    long
    Get the value of the counter using weak ordering semantics.
    boolean
    Has this counter been closed and should it no longer be used?
    Return the counter label.
    long
    Return the registration id for the counter.
    int
    Return the state of the counter.

    Methods inherited from class java.lang.Object

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

    • ReadableCounter

      public ReadableCounter(CountersReader countersReader, long registrationId, int counterId)
      Construct a view of an existing counter.
      Parameters:
      countersReader - for getting access to the buffers.
      registrationId - assigned by the driver for the counter or Aeron.NULL_VALUE if not known.
      counterId - for the counter to be viewed.
      Throws:
      IllegalStateException - if the id has for the counter has not been allocated.
    • ReadableCounter

      public ReadableCounter(CountersReader countersReader, int counterId)
      Construct a view of an existing counter.
      Parameters:
      countersReader - for getting access to the buffers.
      counterId - for the counter to be viewed.
      Throws:
      IllegalStateException - if the id has for the counter has not been allocated.
  • Method Details

    • registrationId

      public long registrationId()
      Return the registration id for the counter.
      Returns:
      registration id.
    • counterId

      public int counterId()
      Return the counter id.
      Returns:
      counter id.
    • state

      public int state()
      Return the state of the counter.
      Returns:
      state for the counter.
      See Also:
    • label

      public String label()
      Return the counter label.
      Returns:
      the counter label.
    • get

      public long get()
      Get the latest value for the counter with volatile semantics.

      Note:The user should call isClosed() and ensure the result is false to avoid a race on reading a closed counter.

      Returns:
      the latest value for the counter.
    • getWeak

      public long getWeak()
      Get the value of the counter using weak ordering semantics. This is the same a standard read of a field.

      This call is identical to getPlain() and that method is preferred.

      Returns:
      the value for the counter.
    • getPlain

      public long getPlain()
      Get the value of the counter using plain memory semantics. This is the same a standard read of a field.
      Returns:
      the value for the counter.
    • close

      public void close()
      Close this counter. This has no impact on the Counter it is viewing.
      Specified by:
      close in interface AutoCloseable
    • isClosed

      public boolean isClosed()
      Has this counter been closed and should it no longer be used?
      Returns:
      true if it has been closed otherwise false.