Class UnsafeBuffer
- All Implemented Interfaces:
Comparable<DirectBuffer>,AtomicBuffer,DirectBuffer,MutableDirectBuffer
ByteBuffer implementations, or an off Java heap memory address.
ByteOrder of a wrapped buffer is not applied to the UnsafeBuffer. UnsafeBuffers are
effectively stateless and can be used concurrently, the wrapping methods are an exception. To control
ByteOrder use the appropriate method with the ByteOrder overload.
Note: This class has a natural ordering that is inconsistent with equals. Types may be different but equal on buffer contents.
Note: The wrap methods on this class are not thread safe. Concurrent access should only happen after a successful wrap.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBuffer alignment in bytes to ensure atomic word accesses.static final StringShould bounds-checks operations be done or not.static final booleanShould bounds-checks operations be done or not.Fields inherited from class org.agrona.AbstractMutableDirectBuffer
addressOffset, byteArray, capacityFields inherited from interface org.agrona.concurrent.AtomicBuffer
STRICT_ALIGNMENT_CHECKS, STRICT_ALIGNMENT_CHECKS_PROP_NAMEFields inherited from interface org.agrona.DirectBuffer
DISABLE_ARRAY_CONTENT_PRINTOUT_PROP_NAME, STR_HEADER_LEN -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor for a reusable wrapper buffer.UnsafeBuffer(byte[] buffer) Attach a view to abyte[]for providing direct access.UnsafeBuffer(byte[] buffer, int offset, int length) Attach a view to abyte[]for providing direct access.UnsafeBuffer(long address, int length) Attach a view to an off-heap memory region by address.UnsafeBuffer(ByteBuffer buffer) Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct.UnsafeBuffer(ByteBuffer buffer, int offset, int length) Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct.UnsafeBuffer(DirectBuffer buffer) Attach a view to an existingDirectBuffer.UnsafeBuffer(DirectBuffer buffer, int offset, int length) Attach a view to an existingDirectBuffer. -
Method Summary
Modifier and TypeMethodDescriptionintaddIntOpaque(int index, int increment) Adds a value to a given index with opaque semantics.intaddIntOrdered(int index, int increment) Atomically add a value to a given index with ordered store semantics.intaddIntRelease(int index, int increment) Atomically add a value to a given index with release semantics.longaddLongOpaque(int index, long increment) Adds a value to a given index with opaque semantics.longaddLongOrdered(int index, long increment) Atomically adds a value to a given index with ordered store semantics.longaddLongRelease(int index, long increment) Atomically adds a value to a given index with ordered store semantics.Get the underlyingByteBufferif one exists.intcompareAndExchangeInt(int index, int expectedValue, int updateValue) Atomic compare and exchange of a int given an expected value.longcompareAndExchangeLong(int index, long expectedValue, long updateValue) Atomic compare and exchange of a long given an expected value.booleancompareAndSetInt(int index, int expectedValue, int updateValue) Atomic compare and set of an int given an expected value.booleancompareAndSetLong(int index, long expectedValue, long updateValue) Atomic compare and set of a long given an expected value.protected final voidensureCapacity(int index, int length) A hook to ensure the underlying buffer has enough capacity for writing data into the buffer.intgetAndAddInt(int index, int delta) Atomically add a delta to a value at a location returning the previous contents.longgetAndAddLong(int index, long delta) Atomically add a delta to a value at a location returning the previous contents.intgetAndSetInt(int index, int value) Atomically exchange a value at a location returning the previous contents.longgetAndSetLong(int index, long value) Atomically exchange a value at a location returning the previous contents.bytegetByteVolatile(int index) Atomically get the value at a given index with volatile semantics.chargetCharVolatile(int index) Atomically get the value at a given index with volatile semantics.intgetIntAcquire(int index) Atomically get the value at a given index with acquire semantics.intgetIntOpaque(int index) Atomically get a value to a given index with opaque semantics.intgetIntVolatile(int index) Atomically get the value at a given index with volatile semantics.longgetLongAcquire(int index) Atomically get the value at a given index with acquire semantics.longgetLongOpaque(int index) Atomically get a value to a given index with opaque semantics.longgetLongVolatile(int index) Atomically get the value at a given index with volatile semantics.shortgetShortVolatile(int index) Atomically get the value at a given index with volatile semantics.booleanIs this buffer expandable to accommodate putting data into it beyond the current capacity?voidputByteVolatile(int index, byte value) Atomically put a value to a given index with volatile semantics.voidputCharVolatile(int index, char value) Atomically put a value to a given index with volatile semantics.voidputIntOpaque(int index, int value) Atomically put a value to a given index with opaque semantics.voidputIntOrdered(int index, int value) Atomically put a value to a given index with ordered semantics.voidputIntRelease(int index, int value) Atomically put a value to a given index with release semantics.voidputIntVolatile(int index, int value) Atomically put a value to a given index with volatile semantics.voidputLongOpaque(int index, long value) Atomically put a value to a given index with opaque semantics.voidputLongOrdered(int index, long value) Atomically put a value to a given index with ordered store semantics.voidputLongRelease(int index, long value) Atomically put a value to a given index with release semantics.voidputLongVolatile(int index, long value) Atomically put a value to a given index with volatile semantics.voidputShortVolatile(int index, short value) Atomically put a value to a given index with volatile semantics.toString()voidVerify that the underlying buffer is correctly aligned to prevent word tearing, other ordering issues and the JVM crashes.voidwrap(byte[] buffer) Attach a view to abyte[]for providing direct access.voidwrap(byte[] buffer, int offset, int length) Attach a view to abyte[]for providing direct access.voidwrap(long address, int length) Attach a view to an off-heap memory region by address.voidwrap(ByteBuffer buffer) Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct.voidwrap(ByteBuffer buffer, int offset, int length) Attach a view to aByteBufferfor providing direct access.voidwrap(DirectBuffer buffer) Attach a view to an existingDirectBuffer.voidwrap(DirectBuffer buffer, int offset, int length) Attach a view to aDirectBufferfor providing direct access.intGet the adjustment in indices between an index in this buffer and the wrapped object.Methods inherited from class org.agrona.AbstractMutableDirectBuffer
addressOffset, boundsCheck, boundsCheck0, byteArray, capacity, checkLimit, compareTo, equals, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, getChar, getChar, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringUtf8, getStringUtf8, getStringUtf8, getStringWithoutLengthAscii, getStringWithoutLengthAscii, getStringWithoutLengthUtf8, hashCode, parseIntAscii, parseLongAscii, parseNaturalIntAscii, parseNaturalLongAscii, putByte, putBytes, putBytes, putBytes, putBytes, putBytes, putChar, putChar, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putIntAscii, putLong, putLong, putLongAscii, putNaturalIntAscii, putNaturalIntAsciiFromEnd, putNaturalLongAscii, putNaturalPaddedIntAscii, putShort, putShort, putStringAscii, putStringAscii, putStringAscii, putStringAscii, putStringUtf8, putStringUtf8, putStringUtf8, putStringUtf8, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthUtf8, setMemoryMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.agrona.DirectBuffer
addressOffset, boundsCheck, byteArray, capacity, checkLimit, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, getChar, getChar, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringAscii, getStringUtf8, getStringUtf8, getStringUtf8, getStringWithoutLengthAscii, getStringWithoutLengthAscii, getStringWithoutLengthUtf8, parseIntAscii, parseLongAscii, parseNaturalIntAscii, parseNaturalLongAsciiMethods inherited from interface org.agrona.MutableDirectBuffer
putByte, putBytes, putBytes, putBytes, putBytes, putBytes, putChar, putChar, putDouble, putDouble, putFloat, putFloat, putInt, putInt, putIntAscii, putLong, putLong, putLongAscii, putNaturalIntAscii, putNaturalIntAsciiFromEnd, putNaturalLongAscii, putNaturalPaddedIntAscii, putShort, putShort, putStringAscii, putStringAscii, putStringAscii, putStringAscii, putStringUtf8, putStringUtf8, putStringUtf8, putStringUtf8, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthAscii, putStringWithoutLengthUtf8, setMemory
-
Field Details
-
ALIGNMENT
public static final int ALIGNMENTBuffer alignment in bytes to ensure atomic word accesses.- See Also:
-
DISABLE_BOUNDS_CHECKS_PROP_NAME
Should bounds-checks operations be done or not. Controlled by theDirectBuffer.DISABLE_BOUNDS_CHECKS_PROP_NAMEsystem property. -
SHOULD_BOUNDS_CHECK
public static final boolean SHOULD_BOUNDS_CHECKShould bounds-checks operations be done or not. Controlled by theDirectBuffer.DISABLE_BOUNDS_CHECKS_PROP_NAMEsystem property.
-
-
Constructor Details
-
UnsafeBuffer
public UnsafeBuffer()Empty constructor for a reusable wrapper buffer. -
UnsafeBuffer
public UnsafeBuffer(byte[] buffer) Attach a view to abyte[]for providing direct access.- Parameters:
buffer- to which the view is attached.- See Also:
-
UnsafeBuffer
public UnsafeBuffer(byte[] buffer, int offset, int length) Attach a view to abyte[]for providing direct access.- Parameters:
buffer- to which the view is attached.offset- in bytes within the buffer to begin.length- in bytes of the buffer included in the view.- See Also:
-
UnsafeBuffer
Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct.- Parameters:
buffer- to which the view is attached.
-
UnsafeBuffer
Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct.- Parameters:
buffer- to which the view is attached.offset- in bytes within the buffer to begin.length- in bytes of the buffer included in the view.
-
UnsafeBuffer
Attach a view to an existingDirectBuffer.- Parameters:
buffer- to which the view is attached.
-
UnsafeBuffer
Attach a view to an existingDirectBuffer.- Parameters:
buffer- to which the view is attached.offset- in bytes within the buffer to begin.length- in bytes of the buffer included in the view.
-
UnsafeBuffer
public UnsafeBuffer(long address, int length) Attach a view to an off-heap memory region by address. This is useful for interacting with native libraries.- Parameters:
address- where the memory begins off-heap.length- of the buffer from the given address.
-
-
Method Details
-
wrap
public void wrap(byte[] buffer) Attach a view to abyte[]for providing direct access.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.
-
wrap
public void wrap(byte[] buffer, int offset, int length) Attach a view to abyte[]for providing direct access.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.offset- in bytes at which the view begins.length- in bytes of the buffer included in the view.
-
wrap
Attach a view to aByteBufferfor providing direct access, theByteBuffercan be heap based or direct. TheByteBuffer.order()is not relevant for accessing the wrapped buffer.When using this method to wrap the view of the ByteBuffer the entire ByteBuffer gets wrapped between index 0 and capacity. If you want to just wrap the ByteBuffer between the position and the limit then you should use the
DirectBuffer.wrap(ByteBuffer, int, int)method, eg:directBuffer.wrap(byteBuffer, byteBuffer.position(), byteBuffer.remaining());- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.
-
wrap
Attach a view to aByteBufferfor providing direct access.The
ByteBuffer.order()is not relevant for accessing the wrapped buffer.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.offset- in bytes at which the view begins.length- in bytes of the buffer included in the view.
-
wrap
Attach a view to an existingDirectBuffer.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.
-
wrap
Attach a view to aDirectBufferfor providing direct access.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
buffer- to which the view is attached.offset- in bytes at which the view begins.length- in bytes of the buffer included in the view.
-
wrap
public void wrap(long address, int length) Attach a view to an off-heap memory region by address.- Specified by:
wrapin interfaceDirectBuffer- Parameters:
address- where the memory begins off-heap.length- of the buffer from the given address.
-
byteBuffer
Get the underlyingByteBufferif one exists.NB: there may not be a one-to-one mapping between indices on this buffer and the underlying byte[], see
DirectBuffer.wrapAdjustment().- Specified by:
byteBufferin interfaceDirectBuffer- Returns:
- the underlying
ByteBufferif one exists.
-
wrapAdjustment
public int wrapAdjustment()Get the adjustment in indices between an index in this buffer and the wrapped object. The wrapped object might be aByteBufferor abyte[].You only need to use this adjustment if you plan to perform operations on the underlying byte array or byte buffer that rely on their indices.
- Specified by:
wrapAdjustmentin interfaceDirectBuffer- Returns:
- the adjustment in indices between an index in this buffer and the wrapped object.
- See Also:
-
isExpandable
public boolean isExpandable()Is this buffer expandable to accommodate putting data into it beyond the current capacity?- Specified by:
isExpandablein interfaceMutableDirectBuffer- Returns:
- true is the underlying storage can expand otherwise false.
-
verifyAlignment
public void verifyAlignment()Verify that the underlying buffer is correctly aligned to prevent word tearing, other ordering issues and the JVM crashes. In particular this method verifies that the starting offset of the underlying buffer is properly aligned. However, the actual atomic call must ensure that the index is properly aligned, i.e. it must be aligned to the size of the operand. For example a call to any of the following methodsAtomicBuffer.putIntRelease(int, int),AtomicBuffer.putIntVolatile(int, int),AtomicBuffer.addIntRelease(int, int)(int, int)},AtomicBuffer.getIntVolatile(int),AtomicBuffer.getAndAddInt(int, int)orAtomicBuffer.getAndSetInt(int, int), must have the index aligned by four bytes (e.g.0, 4, 8, 12, 60 etc.).Users are encouraged to call this method after constructing the
AtomicBufferinstance in order to ensure that the underlying buffer supports atomic access tolongvalues.Agrona provides an agent (
org.agrona.agent.BufferAlignmentAgent) that checks the alignment of indexes for all operations at runtime. The agent throws an exception if the unaligned access is detected.Note: on some platforms unaligned atomic access can lead to the JVM crashes, e.g.:
# Java VM: OpenJDK 64-Bit Server VM (25.352-b08 mixed mode bsd-aarch64 compressed oops) # # siginfo: si_signo: 10 (SIGBUS), si_code: 1 (BUS_ADRALN)- Specified by:
verifyAlignmentin interfaceAtomicBuffer- See Also:
-
getLongVolatile
public long getLongVolatile(int index) Atomically get the value at a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
getLongVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putLongVolatile
public void putLongVolatile(int index, long value) Atomically put a value to a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
putLongVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getLongAcquire
public long getLongAcquire(int index) Atomically get the value at a given index with acquire semantics.- Specified by:
getLongAcquirein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putLongOrdered
public void putLongOrdered(int index, long value) Atomically put a value to a given index with ordered store semantics.Instead of using this method, use
AtomicBuffer.putLongRelease(int, long)instead. They are identical and the putLongRelease is the preferred version.- Specified by:
putLongOrderedin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
putLongRelease
public void putLongRelease(int index, long value) Atomically put a value to a given index with release semantics.- Specified by:
putLongReleasein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
addLongOrdered
public long addLongOrdered(int index, long increment) Atomically adds a value to a given index with ordered store semantics. Use a negative increment to decrement.The load has no ordering semantics. The store has release semantics.
Instead of using this method, use
AtomicBuffer.addLongRelease(int, long)instead. They are identical but the addLongRelease is the preferred version.- Specified by:
addLongOrderedin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
addLongRelease
public long addLongRelease(int index, long increment) Atomically adds a value to a given index with ordered store semantics. Use a negative increment to decrement.The load has no ordering semantics. The store has release semantics.
- Specified by:
addLongReleasein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
putLongOpaque
public void putLongOpaque(int index, long value) Atomically put a value to a given index with opaque semantics.- Specified by:
putLongOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getLongOpaque
public long getLongOpaque(int index) Atomically get a value to a given index with opaque semantics.- Specified by:
getLongOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.- Returns:
- the value for at a given index.
-
addLongOpaque
public long addLongOpaque(int index, long increment) Adds a value to a given index with opaque semantics. The read and write will be atomic, but the combination is not atomic. So don't use this method concurrently because you can run into lost updates due to a race-condition.- Specified by:
addLongOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
compareAndSetLong
public boolean compareAndSetLong(int index, long expectedValue, long updateValue) Atomic compare and set of a long given an expected value.This call has sequential-consistent semantics.
- Specified by:
compareAndSetLongin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.expectedValue- at to be compared.updateValue- to be exchanged.- Returns:
- set successful or not.
-
compareAndExchangeLong
public long compareAndExchangeLong(int index, long expectedValue, long updateValue) Atomic compare and exchange of a long given an expected value.This call has sequential-consistent semantics.
- Specified by:
compareAndExchangeLongin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.expectedValue- at to be compared.updateValue- to be exchanged.- Returns:
- the old value no matter if the expected value was found.
-
getAndSetLong
public long getAndSetLong(int index, long value) Atomically exchange a value at a location returning the previous contents.This call has sequential-consistent semantics.
- Specified by:
getAndSetLongin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.- Returns:
- previous value at the index.
-
getAndAddLong
public long getAndAddLong(int index, long delta) Atomically add a delta to a value at a location returning the previous contents. To decrement a negative delta can be provided.This call has sequential-consistent semantics.
- Specified by:
getAndAddLongin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.delta- to be added to the value at the index.- Returns:
- previous value.
-
getIntVolatile
public int getIntVolatile(int index) Atomically get the value at a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
getIntVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putIntVolatile
public void putIntVolatile(int index, int value) Atomically put a value to a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
putIntVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getIntAcquire
public int getIntAcquire(int index) Atomically get the value at a given index with acquire semantics.- Specified by:
getIntAcquirein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putIntOrdered
public void putIntOrdered(int index, int value) Atomically put a value to a given index with ordered semantics.Instead of using this method, use
AtomicBuffer.putIntRelease(int, int)instead. They are identical but the putIntRelease is the preferred version.- Specified by:
putIntOrderedin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
putIntRelease
public void putIntRelease(int index, int value) Atomically put a value to a given index with release semantics.- Specified by:
putIntReleasein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
addIntOrdered
public int addIntOrdered(int index, int increment) Atomically add a value to a given index with ordered store semantics. Use a negative increment to decrement.The load has no ordering semantics. The store has release semantics.
Instead of using this method, use
AtomicBuffer.addIntRelease(int, int)instead. They are identical but the addIntRelease is the preferred version.- Specified by:
addIntOrderedin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
addIntRelease
public int addIntRelease(int index, int increment) Atomically add a value to a given index with release semantics. Use a negative increment to decrement.The load has no ordering semantics. The store has release semantics.
- Specified by:
addIntReleasein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
putIntOpaque
public void putIntOpaque(int index, int value) Atomically put a value to a given index with opaque semantics.- Specified by:
putIntOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getIntOpaque
public int getIntOpaque(int index) Atomically get a value to a given index with opaque semantics.- Specified by:
getIntOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.- Returns:
- the value for at a given index.
-
addIntOpaque
public int addIntOpaque(int index, int increment) Adds a value to a given index with opaque semantics. The read and write will be atomic, but the combination is not atomic. So don't use this method concurrently because you can run into lost updates due to a race-condition.- Specified by:
addIntOpaquein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.increment- by which the value at the index will be adjusted.- Returns:
- the previous value at the index.
-
compareAndSetInt
public boolean compareAndSetInt(int index, int expectedValue, int updateValue) Atomic compare and set of an int given an expected value.This call has sequential-consistent semantics.
- Specified by:
compareAndSetIntin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.expectedValue- at to be compared.updateValue- to be exchanged.- Returns:
- successful or not.
-
compareAndExchangeInt
public int compareAndExchangeInt(int index, int expectedValue, int updateValue) Atomic compare and exchange of a int given an expected value.This call has sequential-consistent semantics.
- Specified by:
compareAndExchangeIntin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.expectedValue- at to be compared.updateValue- to be exchanged.- Returns:
- the old value no matter if the expected value was found.
-
getAndSetInt
public int getAndSetInt(int index, int value) Atomically exchange a value at a location returning the previous contents.This call has sequential-consistent semantics.
- Specified by:
getAndSetIntin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.- Returns:
- previous value.
-
getAndAddInt
public int getAndAddInt(int index, int delta) Atomically add a delta to a value at a location returning the previous contents. To decrement a negative delta can be provided.This call has sequential-consistent semantics.
- Specified by:
getAndAddIntin interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.delta- to be added to the value at the index.- Returns:
- previous value.
-
getShortVolatile
public short getShortVolatile(int index) Atomically get the value at a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
getShortVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putShortVolatile
public void putShortVolatile(int index, short value) Atomically put a value to a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
putShortVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getByteVolatile
public byte getByteVolatile(int index) Atomically get the value at a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
getByteVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putByteVolatile
public void putByteVolatile(int index, byte value) Atomically put a value to a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
putByteVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
getCharVolatile
public char getCharVolatile(int index) Atomically get the value at a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
getCharVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes from which to get.- Returns:
- the value for at a given index.
-
putCharVolatile
public void putCharVolatile(int index, char value) Atomically put a value to a given index with volatile semantics.This call has sequential-consistent semantics.
- Specified by:
putCharVolatilein interfaceAtomicBuffer- Parameters:
index- in bytes for where to put.value- for at a given index.
-
toString
-
ensureCapacity
protected final void ensureCapacity(int index, int length) Description copied from class:AbstractMutableDirectBufferA hook to ensure the underlying buffer has enough capacity for writing data into the buffer.- Specified by:
ensureCapacityin classAbstractMutableDirectBuffer- Parameters:
index- at which write occurs.length- in bytes.
-