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, tryLock
assertCloseable, 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, warnAndCloseIfNotClosed
public static final int INT_NOT_COMPLETE
public void bytesStore(@NotNull @NotNull BytesStore bytes, long offset, long length) throws IllegalStateException, IllegalArgumentException, BufferOverflowException
bytesStore
in interface Byteable
bytesStore
in class AbstractReference
bytes
- the BytesStoreoffset
- the offset within the BytesStorelength
- the length of the valueIllegalStateException
- if closedIllegalArgumentException
- if the length is not equal to maxSizeBufferOverflowException
- if the offset is too largepublic long maxSize()
@NotNull public @NotNull String toString()
toString
in class net.openhft.chronicle.core.io.AbstractCloseable
public int getValue() throws IllegalStateException, BufferUnderflowException
getValue
in interface net.openhft.chronicle.core.values.IntValue
IllegalStateException
- if closedBufferUnderflowException
- if the offset is too largepublic void setValue(int value) throws IllegalStateException, BufferOverflowException
setValue
in interface net.openhft.chronicle.core.values.IntValue
value
- the 32-bit integer value to setIllegalStateException
- if closedBufferOverflowException
- if the offset is too largepublic int getVolatileValue() throws IllegalStateException, BufferUnderflowException
getVolatileValue
in interface net.openhft.chronicle.core.values.IntValue
IllegalStateException
- if closedBufferUnderflowException
- if the offset is too largepublic void setOrderedValue(int value) throws IllegalStateException, BufferOverflowException
setOrderedValue
in interface net.openhft.chronicle.core.values.IntValue
value
- the 32-bit integer value to setIllegalStateException
- if closedBufferOverflowException
- if the offset is too largepublic int addValue(int delta) throws IllegalStateException, BufferUnderflowException
addValue
in interface net.openhft.chronicle.core.values.IntValue
delta
- the value to addIllegalStateException
- if closedBufferUnderflowException
- if the offset is too largepublic int addAtomicValue(int delta) throws IllegalStateException, BufferUnderflowException
addAtomicValue
in interface net.openhft.chronicle.core.values.IntValue
delta
- the value to addIllegalStateException
- if closedBufferUnderflowException
- if the offset is too largepublic boolean compareAndSwapValue(int expected, int value) throws IllegalStateException, BufferOverflowException
compareAndSwapValue
in interface net.openhft.chronicle.core.values.IntValue
expected
- the expected 32-bit integer valuevalue
- the new 32-bit integer valueIllegalStateException
- if closedBufferOverflowException
- if the offset is too largeCopyright © 2023. All rights reserved.