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 |
bytesStore, 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, tryLock, unmonitor
assertCloseable, assertCloseablesClosed, close, createdHere, disableCloseableTracing, enableCloseableTracing, gcAndWaitForCloseablesToClose, isClosed, isClosing, isInUserThread, referenceId, shouldPerformCloseInBackground, shouldWaitForClosed, singleThreadedCheckDisabled, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfClosed, throwExceptionIfClosedInSetter, unmonitor, waitForCloseablesToClose, waitForClosed, warnAndCloseIfNotClosed
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, getVolatileValue, isClosed, setMaxValue, setMinValue
address, bytesStore, lock, offset, tryLock
public static final long LONG_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 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 wayIllegalStateException
public long maxSize()
@NotNull public @NotNull String toString()
toString
in class net.openhft.chronicle.core.io.AbstractCloseable
public long getValue() throws IllegalStateException
getValue
in interface net.openhft.chronicle.core.values.LongValue
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 wayIllegalStateException
public void setValue(long value) throws IllegalStateException
setValue
in interface net.openhft.chronicle.core.values.LongValue
value
- 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 wayIllegalStateException
public long getVolatileValue() throws IllegalStateException
getVolatileValue
in interface net.openhft.chronicle.core.values.LongValue
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 wayIllegalStateException
public void setVolatileValue(long value) throws IllegalStateException
setVolatileValue
in interface net.openhft.chronicle.core.values.LongValue
value
- 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 wayIllegalStateException
public void setOrderedValue(long value) throws IllegalStateException
setOrderedValue
in interface net.openhft.chronicle.core.values.LongValue
value
- 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 wayIllegalStateException
public long addValue(long delta) throws IllegalStateException
addValue
in interface net.openhft.chronicle.core.values.LongValue
delta
- 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 wayIllegalStateException
public long addAtomicValue(long delta) throws IllegalStateException
addAtomicValue
in interface net.openhft.chronicle.core.values.LongValue
delta
- 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 wayIllegalStateException
public boolean compareAndSwapValue(long expected, long value) throws IllegalStateException
compareAndSwapValue
in interface net.openhft.chronicle.core.values.LongValue
expected
- 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 wayIllegalStateException
Copyright © 2024. All rights reserved.