Package io.aeron.status
Class ReadableCounter
java.lang.Object
io.aeron.status.ReadableCounter
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionReadableCounter(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 TypeMethodDescriptionvoidclose()Close this counter.intReturn the counter id.longget()Get the latest value for the counter with volatile semantics.longgetPlain()Get the value of the counter using plain memory semantics.longgetWeak()Get the value of the counter using weak ordering semantics.booleanisClosed()Has this counter been closed and should it no longer be used?label()Return the counter label.longReturn the registration id for the counter.intstate()Return the state of the counter.
-
Constructor Details
-
ReadableCounter
Construct a view of an existing counter.- Parameters:
countersReader- for getting access to the buffers.registrationId- assigned by the driver for the counter orAeron.NULL_VALUEif not known.counterId- for the counter to be viewed.- Throws:
IllegalStateException- if the id has for the counter has not been allocated.
-
ReadableCounter
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
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 theCounterit is viewing.- Specified by:
closein interfaceAutoCloseable
-
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.
-