public class DefaultMmapFile extends ReferenceResource implements MmapFile
| Modifier and Type | Field and Description |
|---|---|
protected File |
file |
protected static org.slf4j.Logger |
logger |
static int |
OS_PAGE_SIZE |
available, cleanupOver, refCount| Constructor and Description |
|---|
DefaultMmapFile(String fileName,
int fileSize) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
appendMessage(byte[] data)
Appends a raw message data represents by a byte array to the current
MappedFile. |
boolean |
appendMessage(byte[] data,
int offset,
int length)
Content of data from offset to offset + length will be written to file.
|
static void |
clean(ByteBuffer buffer) |
boolean |
cleanup(long currentRef) |
int |
commit(int commitLeastPages)
Flushes the data in the secondary cache to page cache or disk immediately.
|
boolean |
destroy(long intervalForcibly)
Destroys the file and delete it from the file system.
|
static void |
ensureDirOK(String dirName) |
int |
flush(int flushLeastPages)
Flushes the data in cache to disk immediately.
|
boolean |
getData(int pos,
int size,
ByteBuffer byteBuffer)
get the data from file channel
|
FileChannel |
getFileChannel()
Returns the
FileChannel behind the MappedFile. |
long |
getFileFromOffset()
Returns the global offset of the current {code MappedFile}, it's a long value of the file name.
|
String |
getFileName()
Returns the file name of the
MappedFile. |
int |
getFileSize()
Returns the file size of the
MappedFile. |
int |
getFlushedPosition()
Returns the flushed position of this mapped file.
|
long |
getLastModifiedTimestamp()
Returns the last modified timestamp of the file.
|
MappedByteBuffer |
getMappedByteBuffer()
Returns the mapped byte buffer behind the mapped file.
|
int |
getReadPosition()
Returns the current max readable position of this mapped file.
|
int |
getStartPosition()
Returns the start position of this mapped file, before which the data is truncated
|
static int |
getTotalMappedFiles() |
static long |
getTotalMappedVirtualMemory() |
int |
getWrotePosition()
Returns the wrote position of this mapped file.
|
boolean |
isFirstCreateInQueue()
Returns true if the current file is first mapped file of some consume queue.
|
boolean |
isFull()
Returns true if this
MappedFile is full and no new messages can be added. |
SelectMmapBufferResult |
selectMappedBuffer(int pos)
Selects a slice of the mapped byte buffer's sub-region behind the mapped file,
starting at the given position.
|
SelectMmapBufferResult |
selectMappedBuffer(int pos,
int size)
Selects a slice of the mapped byte buffer's sub-region behind the mapped file,
starting at the given position.
|
void |
setCommittedPosition(int pos)
Sets the committed position of this mapped file.
|
void |
setFirstCreateInQueue(boolean firstCreateInQueue)
Sets the flag whether the current file is first mapped file of some consume queue.
|
void |
setFlushedPosition(int pos)
Sets the flushed position of this mapped file.
|
void |
setStartPosition(int startPosition)
Sets the start position of this mapped file.
|
void |
setWrotePosition(int pos)
Sets the wrote position of this mapped file.
|
ByteBuffer |
sliceByteBuffer()
Returns a slice of the mapped byte buffer behind the mapped file.
|
String |
toString() |
getRefCount, hold, isAvailable, isCleanupOver, release, shutdownclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waithold, isAvailable, release, shutdownpublic static final int OS_PAGE_SIZE
protected static org.slf4j.Logger logger
protected File file
public DefaultMmapFile(String fileName, int fileSize) throws IOException
IOExceptionpublic static int getTotalMappedFiles()
public static long getTotalMappedVirtualMemory()
public static void ensureDirOK(String dirName)
public static void clean(ByteBuffer buffer)
public long getLastModifiedTimestamp()
MmapFilegetLastModifiedTimestamp in interface MmapFilepublic int getFileSize()
MmapFileMappedFile.getFileSize in interface MmapFilepublic FileChannel getFileChannel()
MmapFileFileChannel behind the MappedFile.getFileChannel in interface MmapFilepublic long getFileFromOffset()
MmapFilegetFileFromOffset in interface MmapFilepublic boolean appendMessage(byte[] data)
MmapFileMappedFile.appendMessage in interface MmapFiledata - the byte array to appendpublic boolean appendMessage(byte[] data,
int offset,
int length)
appendMessage in interface MmapFileoffset - The offset of the subarray to be used.length - The length of the subarray to be used.data - the byte array to appendpublic int flush(int flushLeastPages)
MmapFilepublic int commit(int commitLeastPages)
MmapFilepublic int getFlushedPosition()
MmapFilegetFlushedPosition in interface MmapFilepublic void setFlushedPosition(int pos)
MmapFilesetFlushedPosition in interface MmapFilepos - the specific flushed positionpublic int getStartPosition()
MmapFilegetStartPosition in interface MmapFilepublic void setStartPosition(int startPosition)
MmapFilesetStartPosition in interface MmapFilestartPosition - the specific start positionpublic boolean isFull()
MmapFileMappedFile is full and no new messages can be added.public SelectMmapBufferResult selectMappedBuffer(int pos, int size)
MmapFileselectMappedBuffer in interface MmapFilepos - the given positionsize - the size of the returned sub-regionSelectMappedBufferResult instance contains the selected slicepublic SelectMmapBufferResult selectMappedBuffer(int pos)
MmapFileselectMappedBuffer in interface MmapFilepos - the given positionSelectMappedBufferResult instance contains the selected slicepublic boolean getData(int pos,
int size,
ByteBuffer byteBuffer)
MmapFilepublic boolean cleanup(long currentRef)
cleanup in class ReferenceResourcepublic boolean destroy(long intervalForcibly)
MmapFilepublic int getWrotePosition()
MmapFilegetWrotePosition in interface MmapFilepublic void setWrotePosition(int pos)
MmapFilesetWrotePosition in interface MmapFilepos - the specific wrote positionpublic int getReadPosition()
MmapFilegetReadPosition in interface MmapFilepublic void setCommittedPosition(int pos)
MmapFilesetCommittedPosition in interface MmapFilepos - the specific committed positionpublic String getFileName()
MmapFileMappedFile.getFileName in interface MmapFilepublic MappedByteBuffer getMappedByteBuffer()
MmapFilegetMappedByteBuffer in interface MmapFilepublic ByteBuffer sliceByteBuffer()
MmapFilesliceByteBuffer in interface MmapFilepublic boolean isFirstCreateInQueue()
MmapFileisFirstCreateInQueue in interface MmapFilepublic void setFirstCreateInQueue(boolean firstCreateInQueue)
MmapFilesetFirstCreateInQueue in interface MmapFilefirstCreateInQueue - true or falseCopyright © 2023. All rights reserved.