public abstract class MappedFile
extends net.openhft.chronicle.core.io.AbstractCloseableReferenceCounted
The class is abstract, and specific implementations may differ in how they manage the chunks and underlying file storage.
| Modifier and Type | Field and Description |
|---|---|
static SyncMode |
DEFAULT_SYNC_MODE
The default disk synchronization mode for this mapped file.
|
protected NewChunkListener |
newChunkListener
Listener for the event when a new chunk is created.
|
protected static boolean |
RETAIN
Flag to indicate if the mapped file should be retained.
|
| Modifier | Constructor and Description |
|---|---|
protected |
MappedFile(@NotNull File file,
boolean readOnly)
Constructs a new MappedFile with the specified file and read-only flag.
|
| Modifier and Type | Method and Description |
|---|---|
@NotNull Bytes<?> |
acquireBytesForRead(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position)
Acquires bytes for read at the specified position, without the need to release the BytesStore.
|
void |
acquireBytesForRead(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
@NotNull VanillaBytes<?> bytes)
Acquires bytes for read at the specified position and stores them in the provided VanillaBytes object.
|
@NotNull Bytes<?> |
acquireBytesForWrite(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position)
Acquires bytes for write at the specified position.
|
void |
acquireBytesForWrite(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
@NotNull VanillaBytes<?> bytes)
Acquires bytes for write at the specified position and stores them in the provided VanillaBytes object.
|
@NotNull MappedBytesStore |
acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position)
Acquires a byte store at the specified position.
|
@NotNull MappedBytesStore |
acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
BytesStore<?,?> oldByteStore)
Acquires a byte store at the specified position with the ability to re-use an existing byte store.
|
abstract @NotNull MappedBytesStore |
acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
BytesStore<?,?> oldByteStore,
@NotNull MappedBytesStoreFactory mappedBytesStoreFactory)
Acquires a byte store at the specified position with the ability to re-use an existing byte store,
and specify a custom byte store factory.
|
abstract long |
actualSize()
Returns the actual size of the mapped file in bytes, including any space reserved
for metadata, headers, etc.
|
protected boolean |
canReleaseInBackground()
Indicates whether the release operation can be performed in the background.
|
abstract long |
capacity()
Returns the capacity of the mapped file in bytes.
|
abstract long |
chunkCount()
Returns the number of chunks in this mapped file.
|
abstract void |
chunkCount(long[] chunkCount)
Populates the provided array with detailed chunk count information.
|
abstract long |
chunkSize()
Returns the size of each chunk in the mapped file in bytes.
|
abstract MappedBytes |
createBytesFor()
Creates a MappedBytes object for this mapped file.
|
@NotNull File |
file()
Returns the File object associated with this MappedFile.
|
protected void |
finalize()
This finalize() is used to detect when a component is not released deterministically.
|
NewChunkListener |
getNewChunkListener()
Returns the listener that is notified when a new chunk is created.
|
protected String |
internalizedToken()
Returns an internalized String that represents a token based on the
underlying file's canonical path and some other factors including a
per JVM random string.
|
abstract FileLock |
lock(long position,
long size,
boolean shared)
Locks a specified region of this mapped file.
|
static @NotNull MappedFile |
mappedFile(@NotNull File file,
long chunkSize)
Creates and returns a MappedFile instance for the specified file with the given chunk size.
|
static @NotNull MappedFile |
mappedFile(@NotNull File file,
long chunkSize,
long overlapSize)
Creates and returns a MappedFile instance for the specified file with the given chunk size and overlap size.
|
static @NotNull MappedFile |
mappedFile(@NotNull File file,
long chunkSize,
long overlapSize,
boolean readOnly)
Creates and returns a MappedFile instance for the specified file with the given chunk size, overlap size, and read-only mode.
|
static @NotNull MappedFile |
mappedFile(@NotNull File file,
long capacity,
long chunkSize,
long overlapSize,
boolean readOnly)
Creates and returns a MappedFile instance with the specified file, capacity, chunk size,
overlap size, and read-only mode.
|
static @NotNull MappedFile |
mappedFile(@NotNull String filename,
long chunkSize)
Creates and returns a MappedFile instance for the specified file with the given chunk size.
|
static @NotNull MappedFile |
mappedFile(@NotNull String filename,
long chunkSize,
long overlapSize)
Creates and returns a MappedFile instance for the specified file with the given chunk size and overlap size.
|
static @NotNull MappedFile |
of(@NotNull File file,
long chunkSize,
long overlapSize,
boolean readOnly) |
static @NotNull MappedFile |
of(@NotNull File file,
long chunkSize,
long overlapSize,
int pageSize,
boolean readOnly)
Creates and returns a MappedFile instance with the specified file, chunk size, overlap size, pageSize
and read-only mode.
|
static @NotNull MappedFile |
ofSingle(@NotNull File file,
long capacity,
boolean readOnly)
Creates and returns a MappedFile instance representing a single chunk of the specified file.
|
abstract long |
overlapSize()
Returns the size of the overlap between consecutive chunks in the mapped file in bytes.
|
abstract @NotNull RandomAccessFile |
raf()
Returns the RandomAccessFile associated with the mapped file.
|
boolean |
readOnly()
Checks if this MappedFile is read-only.
|
static @NotNull MappedFile |
readOnly(@NotNull File file)
Creates and returns a read-only MappedFile instance for the specified file.
|
abstract @NotNull String |
referenceCounts()
Returns a string representation of the reference counts for the underlying mapped byte stores.
|
void |
setNewChunkListener(NewChunkListener listener)
Sets the listener to be notified when a new chunk is created.
|
abstract void |
syncMode(SyncMode syncMode)
This mode determines whether an MS_ASYNC or MS_SYNC should be performed on a chunk release.
|
protected boolean |
threadSafetyCheck(boolean isUsed)
Performs a thread safety check on the component.
|
abstract FileLock |
tryLock(long position,
long size,
boolean shared)
Attempts to lock a specified region of this mapped file.
|
static void |
warmup()
Warms up the memory-mapped file by accessing its contents.
|
backgroundPerformRelease, close, isClosed, release, releaseLast, reserve, reserveTransfer, setClosed, setClosing, throwExceptionIfClosed, throwExceptionIfClosedInSetter, tryReserve, unmonitoraddReferenceChangeListener, assertReferencesReleased, createdHere, disableReferenceTracing, enableReferenceTracing, performRelease, refCount, referenceCountedUnmonitored, referenceId, removeReferenceChangeListener, singleThreadedCheckDisabled, singleThreadedCheckReset, throwExceptionIfNotReleased, throwExceptionIfReleased, toString, unmonitor, warnAndReleaseIfNotReleasedclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitcreatedHere, warnAndCloseIfNotClosedpublic static final SyncMode DEFAULT_SYNC_MODE
protected static final boolean RETAIN
protected NewChunkListener newChunkListener
protected MappedFile(@NotNull
@NotNull File file,
boolean readOnly)
throws net.openhft.chronicle.core.io.IORuntimeException
file - The file to be memory-mapped.readOnly - True if the file should be read-only, false otherwise.net.openhft.chronicle.core.io.IORuntimeException - if an I/O error occurs.@NotNull public static @NotNull MappedFile of(@NotNull @NotNull File file, long chunkSize, long overlapSize, boolean readOnly) throws FileNotFoundException
FileNotFoundExceptionof(File, long, long, int, boolean)@NotNull public static @NotNull MappedFile of(@NotNull @NotNull File file, long chunkSize, long overlapSize, int pageSize, boolean readOnly) throws FileNotFoundException
file - The file to be memory-mapped.chunkSize - The size of each chunk in bytes.overlapSize - The size of the overlapping regions between chunks in bytes.pageSize - The custom page size in bytes.readOnly - If true, the file is opened in read-only mode; if false, it is opened for read-write.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile ofSingle(@NotNull @NotNull File file, long capacity, boolean readOnly) throws FileNotFoundException
file - The file to be memory-mapped.capacity - The capacity of the memory-mapped file in bytes.readOnly - If true, the file is opened in read-only mode; if false, it is opened for read-write.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull File file, long chunkSize) throws FileNotFoundException
file - The file to be memory-mapped.chunkSize - The size of each chunk in bytes.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull String filename, long chunkSize) throws FileNotFoundException
filename - The name of the file to be memory-mapped.chunkSize - The size of each chunk in bytes.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull String filename, long chunkSize, long overlapSize) throws FileNotFoundException
filename - The name of the file to be memory-mapped.chunkSize - The size of each chunk in bytes.overlapSize - The size of the overlapping regions between chunks in bytes.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull File file, long chunkSize, long overlapSize) throws FileNotFoundException
file - The file to be memory-mapped.chunkSize - The size of each chunk in bytes.overlapSize - The size of the overlapping regions between chunks in bytes.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull File file, long chunkSize, long overlapSize, boolean readOnly) throws FileNotFoundException
file - The file to be memory-mapped.chunkSize - The size of each chunk in bytes.overlapSize - The size of the overlapping regions between chunks in bytes.readOnly - If true, the file is opened in read-only mode; if false, it is opened for read-write.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile readOnly(@NotNull @NotNull File file) throws FileNotFoundException
file - The file to be memory-mapped.FileNotFoundException - If the specified file does not exist.@NotNull public static @NotNull MappedFile mappedFile(@NotNull @NotNull File file, long capacity, long chunkSize, long overlapSize, boolean readOnly) throws IOException
file - The file to be memory-mapped.capacity - The total size that the file should take up, in bytes.chunkSize - The size of each chunk in bytes.overlapSize - The size of the overlapping regions between chunks in bytes.readOnly - If true, the file is opened in read-only mode; if false, it is opened for read-write.IOException - If an I/O error occurs.public static void warmup()
@NotNull public @NotNull File file()
public boolean readOnly()
@NotNull public @NotNull MappedBytesStore acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner, long position) throws IOException, IllegalArgumentException, IllegalStateException
owner - The owner of the byte store.position - The position at which the byte store should be acquired.IOException - If an I/O error occurs.IllegalArgumentException - If the position is negative.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@NotNull public @NotNull MappedBytesStore acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner, long position, BytesStore<?,?> oldByteStore) throws IOException, IllegalStateException
owner - The owner of the byte store.position - The position at which the byte store should be acquired.oldByteStore - The old byte store that can be re-used, or null if not available.IOException - 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 wayIllegalStateException@NotNull public abstract @NotNull MappedBytesStore acquireByteStore(net.openhft.chronicle.core.io.ReferenceOwner owner, long position, BytesStore<?,?> oldByteStore, @NotNull @NotNull MappedBytesStoreFactory mappedBytesStoreFactory) throws IOException, IllegalArgumentException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
owner - The owner of the byte store.position - The position at which the byte store should be acquired.oldByteStore - The old byte store that can be re-used, or null if not available.mappedBytesStoreFactory - The factory to use for creating the MappedBytesStore.IOException - If an I/O error occurs.IllegalArgumentException - If an illegal argument is provided.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 way@NotNull public @NotNull Bytes<?> acquireBytesForRead(net.openhft.chronicle.core.io.ReferenceOwner owner, long position) throws IOException, BufferUnderflowException, net.openhft.chronicle.core.io.ClosedIllegalStateException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
owner - The owner of the bytes.position - The position at which the bytes should be acquired.IOException - If an I/O error occurs.BufferUnderflowException - If the position is beyond the limit.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 waypublic void acquireBytesForRead(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
@NotNull
@NotNull VanillaBytes<?> bytes)
throws IOException,
IllegalStateException,
IllegalArgumentException,
BufferUnderflowException,
BufferOverflowException,
net.openhft.chronicle.core.io.ClosedIllegalStateException,
net.openhft.chronicle.core.io.ThreadingIllegalStateException
owner - The owner of the bytes.position - The position at which the bytes should be acquired.bytes - The VanillaBytes object to store the acquired bytes.IOException - If an I/O error occurs.IllegalArgumentException - If an illegal argument is provided.BufferUnderflowException - If there is not enough data available.BufferOverflowException - If there is too much 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@NotNull public @NotNull Bytes<?> acquireBytesForWrite(net.openhft.chronicle.core.io.ReferenceOwner owner, long position) throws IOException, net.openhft.chronicle.core.io.ClosedIllegalStateException, IllegalArgumentException, BufferOverflowException, net.openhft.chronicle.core.io.ThreadingIllegalStateException
owner - The owner of the bytes.position - The position at which the bytes should be acquired for write.IOException - If an I/O error occurs.IllegalArgumentException - If an illegal argument is provided.BufferOverflowException - If there is too much 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 waypublic void acquireBytesForWrite(net.openhft.chronicle.core.io.ReferenceOwner owner,
long position,
@NotNull
@NotNull VanillaBytes<?> bytes)
throws IOException,
net.openhft.chronicle.core.io.ClosedIllegalStateException,
IllegalArgumentException,
BufferUnderflowException,
BufferOverflowException,
net.openhft.chronicle.core.io.ThreadingIllegalStateException
owner - The owner of the bytes.position - The position at which the bytes should be acquired for write.bytes - The VanillaBytes object to store the acquired bytes.IOException - If an I/O error occurs.IllegalArgumentException - If an illegal argument is provided.BufferUnderflowException - If there is not enough data available.BufferOverflowException - If there is too much 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 wayprotected boolean canReleaseInBackground()
canReleaseInBackground in class net.openhft.chronicle.core.io.AbstractReferenceCounted@NotNull public abstract @NotNull String referenceCounts()
public abstract long capacity()
public abstract long chunkSize()
public abstract long overlapSize()
public NewChunkListener getNewChunkListener()
public void setNewChunkListener(NewChunkListener listener)
listener - The listener to be set.public abstract long actualSize()
@NotNull public abstract @NotNull RandomAccessFile raf()
protected void finalize()
throws Throwable
protected boolean threadSafetyCheck(boolean isUsed)
threadSafetyCheck in class net.openhft.chronicle.core.io.AbstractReferenceCountedisUsed - Flag to indicate whether the component is used.protected String internalizedToken()
The canonical path is pre-pended with static and random data to reduce the probability of unrelated synchronization on internalized Strings.
public abstract FileLock lock(long position, long size, boolean shared) throws IOException
position - The byte position at which the locked region begins.size - The size of the region to lock, in bytes.shared - If true, the lock will be shared. Otherwise, it will be exclusive.IOException - If an I/O error occurs.public abstract FileLock tryLock(long position, long size, boolean shared) throws IOException
position - The byte position at which the locked region begins.size - The size of the region to lock, in bytes.shared - If true, the lock will be shared. Otherwise, it will be exclusive.null if the lock could not be acquired.IOException - If an I/O error occurs.public abstract long chunkCount()
public abstract void chunkCount(long[] chunkCount)
chunkCount - The array to be populated with detailed chunk count information.public abstract MappedBytes createBytesFor() throws net.openhft.chronicle.core.io.ClosedIllegalStateException
net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.IllegalArgumentException - If the write limit is negative.public abstract void syncMode(SyncMode syncMode)
Performs this sync on any open store as well
syncMode - of sync to perform.Copyright © 2024. All rights reserved.