public class MappedBytesStore extends NativeBytesStore<Void>
WARNING: Handle with care as this assumes the caller has correct bounds checking
Modifier and Type | Field and Description |
---|---|
static @NotNull MappedBytesStoreFactory |
MAPPED_BYTES_STORE_FACTORY |
protected Runnable |
writeCheck |
address, limit, maximumLimit, memory
referenceCounted, WARN_COUNT, WARN_NS
charToString
Modifier | Constructor and Description |
---|---|
protected |
MappedBytesStore(net.openhft.chronicle.core.io.ReferenceOwner owner,
MappedFile mappedFile,
long start,
long address,
long capacity,
long safeCapacity) |
Modifier and Type | Method and Description |
---|---|
default long |
addressForRead(long offset,
int buffer) |
long |
appendUtf8(long pos,
char[] chars,
int offset,
int length) |
default ByteOrder |
byteOrder() |
@NotNull Bytes<Void> |
bytesForRead()
Returns a Bytes that wraps this ByteStore from the
start to the realCapacity . |
@NotNull VanillaBytes<Void> |
bytesForWrite()
Returns a Bytes that wraps this ByteStore from the
start to the realCapacity . |
boolean |
compareAndSwapInt(long offset,
int expected,
int value)
Perform a 32-bit CAS at a given offset.
|
boolean |
compareAndSwapLong(long offset,
long expected,
long value)
Perform a 64-bit CAS at a given offset.
|
boolean |
inside(long offset)
Returns if a specified offset is inside this BytesStore limits.
|
boolean |
inside(long offset,
long buffer)
Returns if a number of bytes starting from an offset are inside this ByteStore limits.
|
default long |
lengthWritten(long startPosition)
Typically this calculates the difference however for HexDumpBytes it's not as simple.
|
FileLock |
lock(long position,
long size,
boolean shared)
Calls lock on the underlying file channel
|
void |
nativeWrite(long address,
long position,
long size)
expert level method to copy data from native memory into the BytesStore
|
protected void |
performRelease()
Sync the ByteStore if required.
|
byte |
readByte(long offset)
Read byte at an offset
|
default long |
readLimit()
If the resource is closed, the returned value is unspecified.
|
long |
readPosition()
Returns the read position.
|
default long |
realReadRemaining()
If the resource is closed, the returned value is unspecified.
|
default long |
realWriteRemaining()
If the resource is closed, the returned value is unspecified.
|
long |
safeLimit() |
long |
start() |
SyncMode |
syncMode() |
void |
syncMode(SyncMode syncMode)
Set the sync mode for this ByteStore
|
void |
syncUpTo(long position)
Synchronise from the last complete page up to this position.
|
long |
translate(long offset) |
FileLock |
tryLock(long position,
long size,
boolean shared)
Calls tryLock on the underlying file channel
|
long |
underlyingCapacity()
Fetch the capacity of the underlying file
This can differ from the exposed capacity() of this bytes store (which has been page aligned)
|
@NotNull MappedBytesStore |
write(long offsetInRDO,
byte[] byteArray,
int offset,
int length)
Copies the provided
byteArray to this Bytes object starting at writeOffset taking
content starting at readOffset but copying at most length bytes. |
void |
write(long offsetInRDO,
@NotNull ByteBuffer bytes,
int offset,
int length)
Copy from ByteBuffer into this.
|
@NotNull MappedBytesStore |
write(long writeOffset,
@NotNull RandomDataInput bytes,
long readOffset,
long length)
Copy from RandomDataInput into this.
|
void |
write0(long offsetInRDO,
@NotNull RandomDataInput bytes,
long offset,
long length) |
@NotNull MappedBytesStore |
writeByte(long offset,
byte i8)
Write an unsigned byte at an offset.
|
@NotNull MappedBytesStore |
writeDouble(long offset,
double d)
Write a double at an offset.
|
@NotNull MappedBytesStore |
writeFloat(long offset,
float f)
Write a float at an offset.
|
@NotNull MappedBytesStore |
writeInt(long offset,
int i32)
Write an int at an offset.
|
default long |
writeLimit()
Returns the write limit.
|
@NotNull MappedBytesStore |
writeLong(long offset,
long i64)
Write a long at an offset.
|
@NotNull MappedBytesStore |
writeOrderedInt(long offset,
int i)
Perform a non stalling write with a store barrier.
|
@NotNull MappedBytesStore |
writeOrderedLong(long offset,
long i)
Perform a non stalling write with a store barrier.
|
default long |
writePosition()
Returns the write position.
|
@NotNull MappedBytesStore |
writeShort(long offset,
short i16)
Write a short at an offset.
|
@NotNull MappedBytesStore |
writeVolatileByte(long offset,
byte i8) |
@NotNull MappedBytesStore |
writeVolatileInt(long offset,
int i32) |
@NotNull MappedBytesStore |
writeVolatileLong(long offset,
long i64) |
@NotNull MappedBytesStore |
writeVolatileShort(long offset,
short i16) |
@NotNull MappedBytesStore |
zeroOut(long start,
long end)
Fills the BytesStore with zeros.
|
addAndGetInt, addAndGetLong, addressForRead, addressForWrite, addressForWritePosition, backgroundPerformRelease, byteCheckSum, byteCheckSum, canReadDirect, capacity, copy, copyTo, copyToDirect, elasticByteBuffer, elasticByteBuffer, equals, fastHash, from, from, hashCode, init, isDirectMemory, isEqual, lazyNativeBytesStoreWithFixedCapacity, move, nativeRead, nativeStore, nativeStoreWithFixedCapacity, peekUnsignedByte, read, read8bit, readDouble, readFloat, readIncompleteLong, readInt, readLong, readShort, readUnsignedByte, readVolatileByte, readVolatileInt, readVolatileLong, readVolatileShort, realCapacity, setAddress, sharedMemory, testAndSetInt, toString, toTemporaryDirectByteBuffer, underlyingObject, uninit, uninitialized, wrap, write8bit, write8bit
canReleaseInBackground, readRemaining, writeRemaining
assertReferencesReleased, clearUsedByThread, createdHere, disableReferenceTracing, enableReferenceTracing, refCount, referenceId, release, releaseLast, reserve, reservedBy, reserveTransfer, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfNotReleased, throwExceptionIfReleased, tryReserve, unmonitor, warnAndReleaseIfNotReleased
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAndGetDouble, addAndGetDoubleNotAtomic, addAndGetFloat, addAndGetFloatNotAtomic, addAndGetIntNotAtomic, addAndGetShortNotAtomic, addAndGetUnsignedByteNotAtomic, bytesStore, charAt, cipher, cipher, compareAndSwapDouble, compareAndSwapFloat, contentEquals, copyTo, empty, endsWith, equalBytes, forFields, from, from, hash, isClear, isEmpty, isImmutableEmptyByteStore, length, nativePointer, nativeStoreFrom, readWrite, startsWith, startsWith, subSequence, to8bitString, toDebugString, toDebugString, wrap, wrap, writeMaxInt, writeMaxLong
canReadDirect, compareUtf8, copyTo, copyTo, createCharToString, findByte, parseLong, peekVolatileInt, printable, readBoolean, readUnsignedInt, readUnsignedInt24, readUnsignedShort, readUtf8, readUtf8Limited, readUtf8Limited, readVolatileDouble, readVolatileFloat, subBytes, toByteArray
append, append, write, write, writeBoolean, writeByte, writeInt24, writeOrderedDouble, writeOrderedFloat, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort, writeUtf8, writeUtf8Limited, writeVolatileDouble, writeVolatileFloat
refCount, release, releaseLast, releaseLast, reserve, reservedBy, reserveTransfer, tryReserve
referenceId, referenceName, temporary
chars, codePoints
@NotNull public static final @NotNull MappedBytesStoreFactory MAPPED_BYTES_STORE_FACTORY
protected final Runnable writeCheck
protected MappedBytesStore(net.openhft.chronicle.core.io.ReferenceOwner owner, MappedFile mappedFile, long start, long address, long capacity, long safeCapacity) throws IllegalStateException
IllegalStateException
public long underlyingCapacity()
@NotNull public @NotNull Bytes<Void> bytesForRead() throws IllegalStateException
BytesStore
start
to the realCapacity
.
The returned Bytes is not elastic and can be both read and written using cursors.
IllegalStateException
- if this Bytes has been released@NotNull public @NotNull VanillaBytes<Void> bytesForWrite() throws IllegalStateException
BytesStore
start
to the realCapacity
.
The returned Bytes is not elastic and can be both read and written using cursors.
bytesForWrite
in interface BytesStore<NativeBytesStore<Void>,Void>
bytesForWrite
in class NativeBytesStore<Void>
IllegalStateException
- if this BytesStore has been releasedpublic boolean inside(long offset)
BytesStore
Use this test to determine if an offset is considered safe.
offset
- the specified offset to checktrue
if offset is safepublic boolean inside(long offset, long buffer)
BytesStore
offset
- the starting index to checkbuffer
- the number of bytes after the offset to checktrue
if the bytes between the offset and offset+buffer are inside the BytesStorepublic long safeLimit()
safeLimit
in interface BytesStore<NativeBytesStore<Void>,Void>
safeLimit
in class NativeBytesStore<Void>
public byte readByte(long offset)
RandomDataInput
readByte
in interface RandomDataInput
readByte
in class NativeBytesStore<Void>
offset
- to read@NotNull public @NotNull MappedBytesStore writeOrderedInt(long offset, int i) throws IllegalStateException
RandomDataOutput
writeOrderedInt
in interface RandomDataOutput<NativeBytesStore<Void>>
writeOrderedInt
in class NativeBytesStore<Void>
offset
- to write toi
- value to writeIllegalStateException
public long translate(long offset)
translate
in class NativeBytesStore<Void>
public long start()
start
in class AbstractBytesStore<NativeBytesStore<Void>,Void>
public long readPosition()
The read position is start() <= readPosition() && readPosition() <= readLimit() && readPosition < safeLimit()
If the resource is closed, the returned value is unspecified.
readPosition
in class AbstractBytesStore<NativeBytesStore<Void>,Void>
public FileLock lock(long position, long size, boolean shared) throws IOException
IOException
public FileLock tryLock(long position, long size, boolean shared) throws IOException
IOException
@NotNull public @NotNull MappedBytesStore zeroOut(long start, long end)
BytesStore
zeroOut
in interface BytesStore<NativeBytesStore<Void>,Void>
zeroOut
in interface RandomDataOutput<NativeBytesStore<Void>>
zeroOut
in class NativeBytesStore<Void>
start
- first byte inclusiveend
- last byte exclusivepublic boolean compareAndSwapInt(long offset, int expected, int value) throws IllegalStateException
RandomDataInput
compareAndSwapInt
in interface BytesStore<NativeBytesStore<Void>,Void>
compareAndSwapInt
in interface RandomDataInput
compareAndSwapInt
in interface RandomDataOutput<NativeBytesStore<Void>>
compareAndSwapInt
in class NativeBytesStore<Void>
offset
- to perform CASexpected
- valuevalue
- to setIllegalStateException
public boolean compareAndSwapLong(long offset, long expected, long value) throws IllegalStateException
RandomDataInput
compareAndSwapLong
in interface BytesStore<NativeBytesStore<Void>,Void>
compareAndSwapLong
in interface RandomDataInput
compareAndSwapLong
in interface RandomDataOutput<NativeBytesStore<Void>>
compareAndSwapLong
in class NativeBytesStore<Void>
offset
- to perform CASexpected
- valuevalue
- to setIllegalStateException
@NotNull public @NotNull MappedBytesStore writeByte(long offset, byte i8) throws IllegalStateException
RandomDataOutput
writeByte
in interface RandomDataOutput<NativeBytesStore<Void>>
writeByte
in class NativeBytesStore<Void>
offset
- to write toi8
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeShort(long offset, short i16) throws IllegalStateException
RandomDataOutput
writeShort
in interface RandomDataOutput<NativeBytesStore<Void>>
writeShort
in class NativeBytesStore<Void>
offset
- to write toi16
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeInt(long offset, int i32) throws IllegalStateException
RandomDataOutput
writeInt
in interface RandomDataOutput<NativeBytesStore<Void>>
writeInt
in class NativeBytesStore<Void>
offset
- to write toi32
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeLong(long offset, long i64) throws IllegalStateException
RandomDataOutput
writeLong
in interface RandomDataOutput<NativeBytesStore<Void>>
writeLong
in class NativeBytesStore<Void>
offset
- to write toi64
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeOrderedLong(long offset, long i) throws IllegalStateException
RandomDataOutput
writeOrderedLong
in interface RandomDataOutput<NativeBytesStore<Void>>
writeOrderedLong
in class NativeBytesStore<Void>
offset
- to write toi
- value to writeIllegalStateException
@NotNull public @NotNull MappedBytesStore writeFloat(long offset, float f) throws IllegalStateException
RandomDataOutput
writeFloat
in interface RandomDataOutput<NativeBytesStore<Void>>
writeFloat
in class NativeBytesStore<Void>
offset
- to write tof
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeDouble(long offset, double d) throws IllegalStateException
RandomDataOutput
writeDouble
in interface RandomDataOutput<NativeBytesStore<Void>>
writeDouble
in class NativeBytesStore<Void>
offset
- to write tod
- the valueIllegalStateException
@NotNull public @NotNull MappedBytesStore writeVolatileByte(long offset, byte i8) throws IllegalStateException
writeVolatileByte
in interface RandomDataOutput<NativeBytesStore<Void>>
writeVolatileByte
in class NativeBytesStore<Void>
IllegalStateException
@NotNull public @NotNull MappedBytesStore writeVolatileShort(long offset, short i16) throws IllegalStateException
writeVolatileShort
in interface RandomDataOutput<NativeBytesStore<Void>>
writeVolatileShort
in class NativeBytesStore<Void>
IllegalStateException
@NotNull public @NotNull MappedBytesStore writeVolatileInt(long offset, int i32) throws IllegalStateException
writeVolatileInt
in interface RandomDataOutput<NativeBytesStore<Void>>
writeVolatileInt
in class NativeBytesStore<Void>
IllegalStateException
@NotNull public @NotNull MappedBytesStore writeVolatileLong(long offset, long i64) throws IllegalStateException
writeVolatileLong
in interface RandomDataOutput<NativeBytesStore<Void>>
writeVolatileLong
in class NativeBytesStore<Void>
IllegalStateException
@NotNull public @NotNull MappedBytesStore write(long offsetInRDO, byte[] byteArray, int offset, int length) throws IllegalStateException
RandomDataOutput
byteArray
to this Bytes object starting at writeOffset
taking
content starting at readOffset
but copying at most length
bytes.
Does not update cursors e.g. writePosition()
write
in interface RandomDataOutput<NativeBytesStore<Void>>
write
in class NativeBytesStore<Void>
offsetInRDO
- non-negative offset to write tobyteArray
- non-null copy from byteArrayoffset
- non-negative copy from offsetlength
- non-negative length to copyIllegalStateException
- if this Bytes object has been previously releasedpublic void write(long offsetInRDO, @NotNull @NotNull ByteBuffer bytes, int offset, int length) throws IllegalStateException
RandomDataOutput
Does not update cursors e.g. writePosition()
write
in interface RandomDataOutput<NativeBytesStore<Void>>
write
in class NativeBytesStore<Void>
offsetInRDO
- offset to write tobytes
- copy from bytesoffset
- copy from offsetIllegalStateException
@NotNull public @NotNull MappedBytesStore write(long writeOffset, @NotNull @NotNull RandomDataInput bytes, long readOffset, long length) throws BufferOverflowException, BufferUnderflowException, IllegalStateException
RandomDataOutput
writePosition()
nor RandomCommon.readPosition()
write
in interface RandomDataOutput<NativeBytesStore<Void>>
write
in class NativeBytesStore<Void>
writeOffset
- offset to write tobytes
- copy from bytesreadOffset
- copy from offsetBufferOverflowException
IllegalStateException
BufferUnderflowException
public void write0(long offsetInRDO, @NotNull @NotNull RandomDataInput bytes, long offset, long length) throws IllegalStateException
write0
in class NativeBytesStore<Void>
IllegalStateException
public void nativeWrite(long address, long position, long size) throws IllegalStateException
RandomDataOutput
nativeWrite
in interface RandomDataOutput<NativeBytesStore<Void>>
nativeWrite
in class NativeBytesStore<Void>
address
- in native memory to copy fromposition
- in BytesStore to copy tosize
- in bytesIllegalStateException
public long appendUtf8(long pos, char[] chars, int offset, int length) throws IllegalStateException
appendUtf8
in class NativeBytesStore<Void>
IllegalStateException
protected void performRelease()
performRelease
in class NativeBytesStore<Void>
public SyncMode syncMode()
public void syncMode(SyncMode syncMode)
syncMode
- public void syncUpTo(long position)
position
- to sync with the syncMode()public long writePosition()
readPosition() <= writePosition() && writePosition() <= writeLimit()
If the resource is closed, the returned value is unspecified.
public long lengthWritten(long startPosition)
If the resource is closed, the returned value is unspecified.
startPosition
- to compare againstpublic long realReadRemaining()
If the resource is closed, the returned value is unspecified.
public long realWriteRemaining()
If the resource is closed, the returned value is unspecified.
public long readLimit()
If the resource is closed, the returned value is unspecified.
public long writeLimit()
If the resource is closed, the returned value is unspecified.
public long addressForRead(long offset, int buffer) throws UnsupportedOperationException, BufferUnderflowException, IllegalStateException
public ByteOrder byteOrder()
Copyright © 2022. All rights reserved.