public class BinaryLongReference extends AbstractReference implements LongReference
BytesStore.
This class provides various operations to access and manipulate a single long integer in binary form. The long 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 8 bytes, corresponding to a 64-bit long integer.
Example usage:
BytesStore bytesStore = BytesStore.nativeStoreWithFixedCapacity(32);
try (BinaryLongReference ref = new BinaryLongReference()) {
ref.bytesStore(bytesStore, 16, 8);
ref.setValue(1234567890L);
long value = ref.getVolatileValue();
}
Note: This class is not thread-safe. External synchronization may be necessary if instances are shared between threads.
BytesStore,
LongReference| Modifier and Type | Field and Description |
|---|---|
static long |
LONG_NOT_COMPLETE |
bytes, offset| Constructor and Description |
|---|
BinaryLongReference() |
| Modifier and Type | Method and Description |
|---|---|
long |
addAtomicValue(long delta)
Adds a delta to the current 64-bit long value atomically and returns the result.
|
long |
addValue(long delta)
Adds a delta to the current 64-bit long value and returns the result.
|
void |
bytesStore(@NotNull BytesStore bytes,
long offset,
long length)
Stores bytes from the given BytesStore into this BinaryLongReference.
|
boolean |
compareAndSwapValue(long expected,
long value)
Atomically sets the 64-bit long value to the given updated value if the current value is
equal to the expected value.
|
long |
getValue()
Retrieves the 64-bit long value from the BytesStore.
|
long |
getVolatileValue()
Retrieves the 64-bit long value using volatile memory semantics.
|
long |
maxSize()
Returns the maximum size of this reference in bytes (8 bytes for a 64-bit long).
|
void |
setOrderedValue(long value)
Sets the 64-bit long value using ordered or lazy set memory semantics.
|
void |
setValue(long value)
Sets the 64-bit long value in the BytesStore.
|
void |
setVolatileValue(long value)
Sets the 64-bit long value using volatile memory semantics.
|
@NotNull String |
toString()
Returns a string representation of this BinaryLongReference.
|
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, warnAndCloseIfNotClosedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclose, getVolatileValue, isClosed, setMaxValue, setMinValuepublic static final long LONG_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 BytesStore from which bytes will be stored.offset - The starting point in bytes from where the value will be stored.length - The number of bytes that should be stored.IllegalArgumentException - If the length provided is not equal to 8.BufferOverflowException - If the bytes cannot be written.net.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 long getValue()
throws IllegalStateException
getValue in interface net.openhft.chronicle.core.values.LongValuenet.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(long value)
throws IllegalStateException
setValue in interface net.openhft.chronicle.core.values.LongValuevalue - the 64-bit long value to setnet.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 getVolatileValue()
throws IllegalStateException
getVolatileValue in interface net.openhft.chronicle.core.values.LongValuenet.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 setVolatileValue(long value)
throws IllegalStateException
setVolatileValue in interface net.openhft.chronicle.core.values.LongValuevalue - the 64-bit long value to setnet.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(long value)
throws IllegalStateException
setOrderedValue in interface net.openhft.chronicle.core.values.LongValuevalue - the 64-bit long value to setnet.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 addValue(long delta)
throws IllegalStateException
addValue in interface net.openhft.chronicle.core.values.LongValuedelta - the value to addnet.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 addAtomicValue(long delta)
throws IllegalStateException
addAtomicValue in interface net.openhft.chronicle.core.values.LongValuedelta - the value to addnet.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(long expected,
long value)
throws IllegalStateException
compareAndSwapValue in interface net.openhft.chronicle.core.values.LongValueexpected - the expected 64-bit long valuevalue - the new 64-bit long valuenet.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.