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 |
bytesStore, 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, 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 BinaryIntArrayReference()
public BinaryIntArrayReference(long defaultCapacity)
defaultCapacity
- the default capacity of the array.public static void startCollecting()
public static void forceAllToNotCompleteState() throws IllegalStateException, BufferOverflowException
BufferOverflowException
- If buffer overflows.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 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.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 be written.capacity
- the capacity to be set.BufferOverflowException
- If buffer overflows.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 in the BytesStore to start reading from.BufferUnderflowException
- If buffer underflows.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
acceptNewBytesStore
in class AbstractReference
bytes
- the new BytesStore to be assigned.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.IntArrayValues
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 getUsed() throws IllegalStateException, BufferUnderflowException
getUsed
in interface net.openhft.chronicle.core.values.IntArrayValues
BufferUnderflowException
- If buffer underflows.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 setMaxUsed(long usedAtLeast) throws IllegalStateException, BufferUnderflowException
setMaxUsed
in interface net.openhft.chronicle.core.values.IntArrayValues
usedAtLeast
- the number of used elements to be set.BufferUnderflowException
- If buffer underflows.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 int getValueAt(long index) throws IllegalStateException, BufferUnderflowException
getValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to retrieve the value from.BufferUnderflowException
- If buffer underflows.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 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.BufferOverflowException
- If buffer overflows.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 int getVolatileValueAt(long index) throws IllegalStateException, BufferUnderflowException
getVolatileValueAt
in interface net.openhft.chronicle.core.values.IntArrayValues
index
- the index to retrieve the value from.BufferUnderflowException
- If buffer underflows.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 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.BufferOverflowException
- If buffer overflows.IllegalArgumentException
- If the arguments are invalid.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 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.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 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.BufferOverflowException
- If buffer overflows.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 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.BufferUnderflowException
- If buffer underflow 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 wayIllegalStateException
public void writeMarshallable(BytesOut<?> bytes) throws IllegalStateException, BufferOverflowException
writeMarshallable
in interface BytesMarshallable
writeMarshallable
in interface WriteBytesMarshallable
bytes
- the output stream.BufferOverflowException
- If buffer overflow 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 wayIllegalStateException
public boolean isNull() throws IllegalStateException
isNull
in interface net.openhft.chronicle.core.values.IntArrayValues
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 reset() throws IllegalStateException
reset
in interface net.openhft.chronicle.core.values.IntArrayValues
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
@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.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 ByteableIntArrayValues capacity(long arrayLength) throws IllegalStateException
capacity
in interface ByteableIntArrayValues
arrayLength
- the desired capacity.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, 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.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
Copyright © 2024. All rights reserved.