public class BinaryIntArrayReference extends AbstractReference implements ByteableIntArrayValues, BytesMarshallable
BytesStore
.
This class provides operations to access and manipulate an array of integers in binary form. The integers are stored in a BytesStore, and this class provides various methods to perform atomic operations, read/write values, and manage the state of the array.
The BinaryIntArrayReference class also contains the ability to throw exceptions in cases of buffer underflows or illegal states, and to read the array in a volatile fashion, ensuring a happens-before relationship between threads.
Example usage:
BytesStore bytesStore = ... BinaryIntArrayReference arrayRef = new BinaryIntArrayReference(); arrayRef.bytesStore(bytesStore, 0, bytesStore.capacity()); arrayRef.setOrderedValueAt(5, 12345); int value = arrayRef.getValueAt(5);
Note: This class is not thread-safe, and external synchronization may be necessary if instances are shared between threads. The data referenced is thread safe when the appropriate methods are used.
Modifier and Type | Field and Description |
---|---|
static int |
SHIFT |
bytes, offset
Constructor and Description |
---|
BinaryIntArrayReference()
Default constructor initializes the BinaryIntArrayReference with a default capacity of 0.
|
BinaryIntArrayReference(long defaultCapacity)
Constructs a new BinaryIntArrayReference with the specified default capacity.
|
Modifier and Type | Method and Description |
---|---|
protected void |
acceptNewBytesStore(@NotNull BytesStore bytes)
Assigns a new BytesStore to this BinaryIntArrayReference.
|
void |
bindValueAt(long index,
@NotNull net.openhft.chronicle.core.values.IntValue value)
Binds the value at the specified index to the provided IntValue.
|
@Nullable BytesStore |
bytesStore()
Retrieves the BytesStore.
|
void |
bytesStore(@NotNull BytesStore bytes,
long offset,
long length)
Stores a bytes sequence into the BinaryIntArrayReference.
|
ByteableIntArrayValues |
capacity(long arrayLength)
Sets the capacity of the BinaryIntArrayReference.
|
boolean |
compareAndSet(long index,
int expected,
int value)
Atomically sets the value at the specified index to the given updated value
if the current value equals the expected value.
|
static void |
forceAllToNotCompleteState()
Forces all BinaryIntArrayReferences to a not complete state.
|
long |
getCapacity()
Gets the capacity of the array.
|
long |
getUsed()
Gets the number of used elements in the array.
|
int |
getValueAt(long index)
Gets the value at the specified index.
|
int |
getVolatileValueAt(long index)
Retrieves the value at the specified index with volatile semantics.
|
boolean |
isNull()
Checks if the instance is null.
|
static void |
lazyWrite(@NotNull Bytes<?> bytes,
long capacity)
Lazily initializes the binary data in the provided Bytes object with the given capacity.
|
long |
maxSize()
Retrieves the maximum size.
|
long |
offset()
Retrieves the offset position.
|
static long |
peakLength(@NotNull BytesStore bytes,
long offset)
Calculates and returns the peak length from the BytesStore at the given offset.
|
void |
readMarshallable(BytesIn<?> bytes)
Reads and deserializes data from the input stream.
|
void |
reset()
Resets the instance to its initial state.
|
void |
setMaxUsed(long usedAtLeast)
Sets the maximum number of used elements in the array.
|
void |
setOrderedValueAt(long index,
int value)
Sets the value at the specified index with ordered semantics.
|
void |
setValueAt(long index,
int value)
Sets the value at the specified index.
|
long |
sizeInBytes(long capacity)
Calculates the size in bytes of the array with the given capacity.
|
static void |
startCollecting()
Initializes the collection that keeps references to BinaryIntArrayReference instances.
|
@NotNull String |
toString()
Returns a string representation of the BinaryIntArrayReference.
|
static void |
write(@NotNull Bytes<?> bytes,
long capacity)
Initializes the binary data in the provided Bytes object with the given capacity.
|
void |
writeMarshallable(BytesOut<?> bytes)
Serializes and writes data to the output stream.
|
address, lock, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, closeQuietly, closeQuietly
$toString, usesSelfDescribingMessage
public static final int SHIFT
public BinaryIntArrayReference()
public BinaryIntArrayReference(long defaultCapacity)
defaultCapacity
- the default capacity of the array.public static void startCollecting()
public static void forceAllToNotCompleteState() throws IllegalStateException, BufferOverflowException
IllegalStateException
- if an illegal state is encountered.BufferOverflowException
- if buffer overflows.public static void write(@NotNull @NotNull Bytes<?> bytes, long capacity) throws BufferOverflowException, IllegalArgumentException, IllegalStateException
bytes
- the Bytes object to be written.capacity
- the capacity to be set.BufferOverflowException
- if buffer overflows.IllegalArgumentException
- if an illegal argument is encountered.IllegalStateException
- if an illegal state is encountered.public static void lazyWrite(@NotNull @NotNull Bytes<?> bytes, long capacity) throws BufferOverflowException, IllegalStateException
bytes
- the Bytes object to be written.capacity
- the capacity to be set.BufferOverflowException
- if buffer overflows.IllegalStateException
- if an illegal state is encountered.public static long peakLength(@NotNull @NotNull BytesStore bytes, long offset) throws BufferUnderflowException, IllegalStateException
bytes
- the BytesStore object to read from.offset
- the offset in the BytesStore to start reading from.BufferUnderflowException
- if buffer underflows.IllegalStateException
- if an illegal state is encountered.protected void acceptNewBytesStore(@NotNull @NotNull BytesStore bytes) throws IllegalStateException
acceptNewBytesStore
in class AbstractReference
bytes
- the new BytesStore to be assigned.IllegalStateException
- if an illegal state is encountered.public long getCapacity() throws IllegalStateException
getCapacity
in interface net.openhft.chronicle.core.values.IntArrayValues
IllegalStateException
- if an illegal state is encountered.public long getUsed() throws IllegalStateException, BufferUnderflowException
getUsed
in interface net.openhft.chronicle.core.values.IntArrayValues
IllegalStateException
- if an illegal state is encountered.BufferUnderflowException
- if buffer underflows.public void setMaxUsed(long usedAtLeast) throws IllegalStateException, BufferUnderflowException
setMaxUsed
in interface net.openhft.chronicle.core.values.IntArrayValues
usedAtLeast
- the number of used elements to be set.IllegalStateException
- if an illegal state is encountered.BufferUnderflowException
- if buffer underflows.public int getValueAt(long index) throws IllegalStateException, BufferUnderflowException
getValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to retrieve the value from.IllegalStateException
- if an illegal state is encountered.BufferUnderflowException
- if buffer underflows.public void setValueAt(long index, int value) throws IllegalStateException, BufferOverflowException
setValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to set the value at.value
- the value to be set.IllegalStateException
- if an illegal state is encountered.BufferOverflowException
- if buffer overflows.public int getVolatileValueAt(long index) throws IllegalStateException, BufferUnderflowException
getVolatileValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to retrieve the value from.IllegalStateException
- if an illegal state is encountered.BufferUnderflowException
- if buffer underflows.public void bindValueAt(long index, @NotNull @NotNull net.openhft.chronicle.core.values.IntValue value) throws IllegalStateException, BufferOverflowException, IllegalArgumentException
bindValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to bind the value at.value
- the IntValue to be bound.IllegalStateException
- if an illegal state is encountered.BufferOverflowException
- if buffer overflows.IllegalArgumentException
- if the arguments are invalid.public void setOrderedValueAt(long index, int value) throws BufferOverflowException, IllegalStateException
setOrderedValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to set the value at.value
- the value to be set.BufferOverflowException
- if buffer overflows.IllegalStateException
- if an illegal state is encountered.public void bytesStore(@NotNull @NotNull BytesStore bytes, long offset, long length) throws IllegalArgumentException, IllegalStateException, BufferOverflowException
bytesStore
in interface Byteable
bytesStore
in class AbstractReference
bytes
- the bytes sequence to store.offset
- the starting position.length
- the length of bytes sequence.IllegalArgumentException
- if the length does not match the peak length.IllegalStateException
- if an illegal state is encountered.BufferOverflowException
- if buffer overflows.public void readMarshallable(BytesIn<?> bytes) throws net.openhft.chronicle.core.io.IORuntimeException, IllegalStateException, BufferUnderflowException
readMarshallable
in interface BytesMarshallable
readMarshallable
in interface ReadBytesMarshallable
bytes
- the input stream.net.openhft.chronicle.core.io.IORuntimeException
- if an IO exception occurs.IllegalStateException
- if an illegal state occurs.BufferUnderflowException
- if buffer underflow occurs.public void writeMarshallable(BytesOut<?> bytes) throws IllegalStateException, BufferOverflowException
writeMarshallable
in interface BytesMarshallable
writeMarshallable
in interface WriteBytesMarshallable
bytes
- the output stream.IllegalStateException
- if an illegal state occurs.BufferOverflowException
- if buffer overflow occurs.public boolean isNull() throws IllegalStateException
isNull
in interface net.openhft.chronicle.core.values.IntArrayValues
IllegalStateException
- if an illegal state occurs.public void reset() throws IllegalStateException
reset
in interface net.openhft.chronicle.core.values.IntArrayValues
IllegalStateException
- if an illegal state occurs.@Nullable public @Nullable BytesStore bytesStore()
bytesStore
in interface Byteable
bytesStore
in class AbstractReference
public long offset()
offset
in interface Byteable
offset
in class AbstractReference
public long maxSize()
@NotNull public @NotNull String toString()
toString
in class net.openhft.chronicle.core.io.AbstractCloseable
public long sizeInBytes(long capacity) throws IllegalStateException
sizeInBytes
in interface ByteableIntArrayValues
sizeInBytes
in interface net.openhft.chronicle.core.values.IntArrayValues
capacity
- the capacity of the array.IllegalStateException
- if an illegal state is encountered.public ByteableIntArrayValues capacity(long arrayLength) throws IllegalStateException
capacity
in interface ByteableIntArrayValues
arrayLength
- the desired capacity.IllegalStateException
- if an illegal state is encountered.public boolean compareAndSet(long index, int expected, int value) throws BufferOverflowException, IllegalStateException
compareAndSet
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index of the value to be updated.expected
- the expected value.value
- the new value.BufferOverflowException
- if buffer overflow occurs.IllegalStateException
- if an illegal state occurs.Copyright © 2023. All rights reserved.