public class BinaryLongArrayReference extends AbstractReference implements ByteableLongArrayValues, BytesMarshallable
BytesStore
.
This class provides various operations to access and manipulate an array of 64-bit long integers in binary form. The long integers are stored in a BytesStore, and this class provides methods for reading and writing values at specific indices.
Example usage:
BytesStore bytesStore = BytesStore.nativeStoreWithFixedCapacity(32); BinaryLongArrayReference ref = new BinaryLongArrayReference(4); // Creates an array with 4 longs ref.bytesStore(bytesStore, 0, ref.maxSize()); ref.setValueAt(0, 1234567890L); long value = ref.getValueAt(0);
Note: This class is not thread-safe. External synchronization may be necessary if instances are shared between threads.
BytesStore
,
BinaryLongReference
Modifier and Type | Field and Description |
---|---|
static int |
SHIFT |
bytesStore, offset
Constructor and Description |
---|
BinaryLongArrayReference()
Constructs a BinaryLongArrayReference with a default capacity of 0.
|
BinaryLongArrayReference(long defaultCapacity)
Constructs a BinaryLongArrayReference with the specified default capacity.
|
Modifier and Type | Method and Description |
---|---|
protected void |
acceptNewBytesStore(@NotNull BytesStore<?,?> bytes)
Updates the BytesStore for this reference, releasing any previous BytesStore
|
void |
bindValueAt(long index,
@NotNull net.openhft.chronicle.core.values.LongValue value) |
@Nullable BytesStore<?,?> |
bytesStore()
Returns the ByteStore to which this object currently points.
|
void |
bytesStore(@NotNull BytesStore bytes,
long offset,
long length)
Sets the underlying BytesStore to work with, along with the offset and length.
|
ByteableLongArrayValues |
capacity(long arrayLength)
Sets the capacity of the array, in terms of the number of long integers it can hold.
|
boolean |
compareAndSet(long index,
long expected,
long value) |
static void |
forceAllToNotCompleteState()
Sets all values in the BinaryLongArrayReference instances to the "not complete" state.
|
long |
getCapacity() |
long |
getUsed() |
long |
getValueAt(long index) |
long |
getVolatileValueAt(long index) |
boolean |
isNull() |
static void |
lazyWrite(@NotNull Bytes<?> bytes,
long capacity)
Lazily writes to the provided Bytes object with the given capacity.
|
long |
maxSize()
Returns the maximum size in bytes that this reference can point to.
|
long |
offset()
Returns the offset within the ByteStore to which this object currently points.
|
static long |
peakLength(@NotNull BytesStore<?,?> bytes,
long offset)
Returns the capacity from the BytesStore object and adding the fixed values size to get a length.
|
static long |
peakLength(@NotNull BytesStore<?,?> bytes,
long offset,
long capacityHint)
Returns the capacity from the BytesStore object, adding the fixed values size to get a length
If the read capacity is 0, the method writes the capacityHint at the offset and
updates the capacity with the capacityHint.
|
void |
readMarshallable(BytesIn<?> bytes)
Reads the state of this object from the bytes.
|
void |
reset() |
void |
setMaxUsed(long usedAtLeast) |
void |
setOrderedValueAt(long index,
long value) |
void |
setUsed(long used) |
void |
setValueAt(long index,
long value) |
long |
sizeInBytes(long capacity)
Calculates the size in bytes needed to store the given number of long integers.
|
static void |
startCollecting()
Enables collection of BinaryLongArrayReference instances.
|
@NotNull String |
toString() |
static void |
write(@NotNull Bytes<?> bytes,
long capacity)
Writes to the provided Bytes object with the given capacity.
|
void |
writeMarshallable(BytesOut<?> bytes)
Writes the state of this object to the bytes.
|
address, lock, 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, closeQuietly, closeQuietly
$toString, usesSelfDescribingMessage
public static final int SHIFT
public BinaryLongArrayReference()
public BinaryLongArrayReference(long defaultCapacity)
defaultCapacity
- the initial capacity of the long array in number of elements.public static void startCollecting()
This method is used for debugging and monitoring. It should not be used in production environments.
public static void forceAllToNotCompleteState() throws IllegalStateException, BufferOverflowException
This method is used for debugging and monitoring. It should not be used in production environments.
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
protected void acceptNewBytesStore(@NotNull @NotNull BytesStore<?,?> bytes) throws IllegalStateException
AbstractReference
acceptNewBytesStore
in class AbstractReference
bytes
- the new BytesStorenet.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 static void write(@NotNull @NotNull Bytes<?> bytes, long capacity) throws BufferOverflowException, IllegalArgumentException, IllegalStateException
bytes
- the Bytes object to write to.capacity
- the capacity to be written and used for subsequent zeroing.BufferOverflowException
- If there is insufficient space in the buffer.IllegalArgumentException
- If arguments violate precondition constraints.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 static void lazyWrite(@NotNull @NotNull Bytes<?> bytes, long capacity) throws BufferOverflowException, IllegalStateException
bytes
- the Bytes object to write to.capacity
- the capacity to be written.BufferOverflowException
- If there is insufficient space in the buffer.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 static long peakLength(@NotNull @NotNull BytesStore<?,?> bytes, long offset) throws BufferUnderflowException, IllegalStateException
bytes
- the BytesStore object to read from.offset
- the offset at which to start reading.BufferUnderflowException
- If there is not enough remaining data.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 static long peakLength(@NotNull @NotNull BytesStore<?,?> bytes, long offset, long capacityHint) throws BufferUnderflowException, IllegalStateException
bytes
- the BytesStore object to read from.offset
- the offset at which to start reading.capacityHint
- the capacity to be used if the initial capacity is 0.BufferUnderflowException
- If there is not enough remaining data.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 getCapacity() throws IllegalStateException
getCapacity
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
public long getUsed() throws IllegalStateException, BufferUnderflowException
getUsed
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
BufferUnderflowException
public void setMaxUsed(long usedAtLeast) throws IllegalStateException, BufferUnderflowException
setMaxUsed
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
BufferUnderflowException
public void setUsed(long used) throws IllegalStateException, BufferUnderflowException
setUsed
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
BufferUnderflowException
public long getValueAt(long index) throws BufferUnderflowException, IllegalStateException
getValueAt
in interface net.openhft.chronicle.core.values.LongArrayValues
BufferUnderflowException
IllegalStateException
public void setValueAt(long index, long value) throws BufferOverflowException, IllegalStateException
setValueAt
in interface net.openhft.chronicle.core.values.LongArrayValues
BufferOverflowException
IllegalStateException
public long getVolatileValueAt(long index) throws BufferUnderflowException, IllegalStateException
getVolatileValueAt
in interface net.openhft.chronicle.core.values.LongArrayValues
BufferUnderflowException
IllegalStateException
public void bindValueAt(long index, @NotNull @NotNull net.openhft.chronicle.core.values.LongValue value) throws IllegalStateException, BufferOverflowException
bindValueAt
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
BufferOverflowException
public void setOrderedValueAt(long index, long value) throws BufferOverflowException, IllegalStateException
setOrderedValueAt
in interface net.openhft.chronicle.core.values.LongArrayValues
BufferOverflowException
IllegalStateException
public void bytesStore(@NotNull @NotNull BytesStore bytes, long offset, long length) throws IllegalArgumentException, IllegalStateException, BufferOverflowException
AbstractReference
bytesStore
in interface Byteable
bytesStore
in class AbstractReference
bytes
- the BytesStore to setoffset
- the offset to setlength
- the length to setIllegalArgumentException
- If the arguments are invalidnet.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 wayBufferOverflowException
- If the provided buffer is too smallIllegalStateException
public void readMarshallable(BytesIn<?> bytes) throws net.openhft.chronicle.core.io.IORuntimeException, IllegalStateException, BufferUnderflowException
BytesMarshallable
readMarshallable
in interface BytesMarshallable
readMarshallable
in interface ReadBytesMarshallable
bytes
- the BytesIn object to read from.net.openhft.chronicle.core.io.IORuntimeException
- If an I/O error occurs.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 wayBufferUnderflowException
- If there is not enough data available in the buffer.IllegalStateException
public void writeMarshallable(BytesOut<?> bytes) throws IllegalStateException, BufferOverflowException, BufferUnderflowException
BytesMarshallable
writeMarshallable
in interface BytesMarshallable
writeMarshallable
in interface WriteBytesMarshallable
bytes
- the BytesOut object to write to.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 wayBufferOverflowException
- If there is not enough space in the buffer.BufferUnderflowException
- If there is not enough data available in the buffer.IllegalStateException
public boolean isNull() throws IllegalStateException
isNull
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
public void reset() throws IllegalStateException
reset
in interface net.openhft.chronicle.core.values.LongArrayValues
IllegalStateException
@Nullable public @Nullable BytesStore<?,?> bytesStore()
Byteable
bytesStore
in interface Byteable
bytesStore
in class AbstractReference
public long offset()
Byteable
offset
in interface Byteable
offset
in class AbstractReference
public long maxSize()
Byteable
@NotNull public @NotNull String toString()
toString
in class net.openhft.chronicle.core.io.AbstractCloseable
public long sizeInBytes(long capacity) throws IllegalStateException
ByteableLongArrayValues
sizeInBytes
in interface ByteableLongArrayValues
sizeInBytes
in interface net.openhft.chronicle.core.values.LongArrayValues
capacity
- the number of long integers to be stored.IllegalStateException
public ByteableLongArrayValues capacity(long arrayLength) throws IllegalStateException
ByteableLongArrayValues
capacity
in interface ByteableLongArrayValues
arrayLength
- the desired array capacity, in number of long integers.ByteableLongArrayValues
instance.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 boolean compareAndSet(long index, long expected, long value) throws BufferOverflowException, IllegalStateException
compareAndSet
in interface net.openhft.chronicle.core.values.LongArrayValues
BufferOverflowException
IllegalStateException
Copyright © 2024. All rights reserved.