public class BinaryIntReference extends AbstractReference implements net.openhft.chronicle.core.values.IntValue
BytesStore.
This class provides various operations to access and manipulate a single integer in binary form. The integer is stored in a BytesStore, and this class provides methods for atomic operations, reading/writing the value, and managing its state.
The class also supports volatile reads, ordered writes, and compare-and-swap operations. The maximum size of the backing storage is 4 bytes, corresponding to a 32-bit integer.
Example usage:
BytesStore bytesStore = BytesStore.nativeStoreWithFixedCapacity(32);
try (BinaryIntReference ref = new BinaryIntReference()) {
ref.bytesStore(bytesStore, 16, 4);
ref.setValue(10);
int value = ref.getVolatileValue();
}
Note: This class is not thread-safe. External synchronization may be necessary if instances are shared between threads.
BytesStore,
IntValue| Modifier and Type | Field and Description |
|---|---|
static int |
INT_NOT_COMPLETE |
bytes, offset| Constructor and Description |
|---|
BinaryIntReference() |
| Modifier and Type | Method and Description |
|---|---|
int |
addAtomicValue(int delta)
Adds a delta to the current 32-bit integer value atomically and returns the result.
|
int |
addValue(int delta)
Adds a delta to the current 32-bit integer value and returns the result.
|
void |
bytesStore(@NotNull BytesStore bytes,
long offset,
long length)
Sets the BytesStore which this reference points to.
|
boolean |
compareAndSwapValue(int expected,
int value)
Atomically sets the 32-bit integer value to the given updated value if the current value is
equal to the expected value.
|
int |
getValue()
Retrieves the 32-bit integer value from the BytesStore.
|
int |
getVolatileValue()
Retrieves the 32-bit integer value using volatile memory semantics.
|
long |
maxSize()
Returns the maximum size of this reference in bytes (4 bytes for a 32-bit integer).
|
void |
setOrderedValue(int value)
Sets the 32-bit integer value using ordered or lazy set memory semantics.
|
void |
setValue(int value)
Sets the 32-bit integer value in the BytesStore.
|
@NotNull String |
toString()
Returns a string representation of this BinaryIntReference.
|
acceptNewBytesStore, address, bytesStore, lock, offset, performClose, tryLockassertCloseable, assertCloseablesClosed, clearUsedByThread, close, createdHere, disableCloseableTracing, disableThreadSafetyCheck, disableThreadSafetyCheck, enableCloseableTracing, gcAndWaitForCloseablesToClose, isClosed, isClosing, isInUserThread, referenceId, resetUsedByThread, shouldPerformCloseInBackground, shouldWaitForClosed, singleThreadedCheckDisabled, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfClosed, throwExceptionIfClosedInSetter, unmonitor, waitForCloseablesToClose, waitForClosed, warnAndCloseIfNotClosedpublic static final int INT_NOT_COMPLETE
public void bytesStore(@NotNull
@NotNull BytesStore bytes,
long offset,
long length)
throws IllegalStateException,
IllegalArgumentException,
BufferOverflowException
bytesStore in interface ByteablebytesStore in class AbstractReferencebytes - the BytesStoreoffset - the offset within the BytesStorelength - the length of the valueIllegalArgumentException - If the length is not equal to maxSizeBufferOverflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic long maxSize()
@NotNull public @NotNull String toString()
toString in class net.openhft.chronicle.core.io.AbstractCloseablepublic int getValue()
throws IllegalStateException,
BufferUnderflowException
getValue in interface net.openhft.chronicle.core.values.IntValueBufferUnderflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic void setValue(int value)
throws IllegalStateException,
BufferOverflowException
setValue in interface net.openhft.chronicle.core.values.IntValuevalue - the 32-bit integer value to setBufferOverflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic int getVolatileValue()
throws IllegalStateException,
BufferUnderflowException
getVolatileValue in interface net.openhft.chronicle.core.values.IntValueBufferUnderflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic void setOrderedValue(int value)
throws IllegalStateException,
BufferOverflowException
setOrderedValue in interface net.openhft.chronicle.core.values.IntValuevalue - the 32-bit integer value to setBufferOverflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic int addValue(int delta)
throws IllegalStateException,
BufferUnderflowException
addValue in interface net.openhft.chronicle.core.values.IntValuedelta - the value to addBufferUnderflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic int addAtomicValue(int delta)
throws IllegalStateException,
BufferUnderflowException
addAtomicValue in interface net.openhft.chronicle.core.values.IntValuedelta - the value to addBufferUnderflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionpublic boolean compareAndSwapValue(int expected,
int value)
throws IllegalStateException,
BufferOverflowException
compareAndSwapValue in interface net.openhft.chronicle.core.values.IntValueexpected - the expected 32-bit integer valuevalue - the new 32-bit integer valueBufferOverflowException - If the offset is too largenet.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe wayIllegalStateExceptionCopyright © 2023. All rights reserved.