Package com.mckoi.store
Class LoggingBufferManager.BMPage
- java.lang.Object
-
- com.mckoi.store.LoggingBufferManager.BMPage
-
- Enclosing class:
- LoggingBufferManager
private static final class LoggingBufferManager.BMPage extends java.lang.ObjectA page from a store that is currently being cached in memory. This is also an element in the cache.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intaccess_countThe number of times this page has been accessed since it was created.private byte[]bufferThe buffer that contains the data for this page.private JournalledResourcedataThe StoreDataAccessor that the page content is part of.private intfirst_write_positionThe first position in the buffer that was last written.(package private) LoggingBufferManager.BMPagehash_nextA reference to the next page with this hash key.private booleaninitializedTrue if this page is initialized.private intlast_write_positionThe last position in the buffer that was last written.private longpageThe page number.private intpage_sizeThe size of the page.private intreference_countThe number of references on this page.(package private) longtThe time this page was last accessed.
-
Constructor Summary
Constructors Constructor Description BMPage(JournalledResource data, long page, int page_size)Constructs the page.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voiddispose()Disposes of the page buffer if it can be disposed (there are no references to the page and the page is initialized).booleanequals(java.lang.Object ob)(package private) voidflush()Flushes this page out to disk, but does not remove from memory.(package private) longgetID()Returns the id of the JournalledResource that is being buffered.(package private) voidinitialize()Initializes the page buffer.(package private) booleanisPage(long in_id, long in_page)Returns true if this page matches the given id/page_number.(package private) booleannotInUse()Returns true if this PageBuffer is not in use (has 0 reference count and is not inialized.(package private) byteread(int pos)Reads a single byte from the cached page from memory.(package private) voidread(int pos, byte[] buf, int off, int len)Reads a part of this page into the cached page from memory.private voidreadPageContent(long page_number, byte[] buf, int pos)Reads the current page content into memory.(package private) voidreferenceAdd()Adds 1 to the reference counter on this page.private voidreferenceRemove()Removes 1 from the reference counter on this page.(package private) voidreset()Resets this object.(package private) voidwrite(int pos, byte v)Writes a single byte to the page in memory.(package private) voidwrite(int pos, byte[] buf, int off, int len)Writes to the given part of the page in memory.
-
-
-
Field Detail
-
data
private final JournalledResource data
The StoreDataAccessor that the page content is part of.
-
page
private final long page
The page number.
-
page_size
private final int page_size
The size of the page.
-
buffer
private byte[] buffer
The buffer that contains the data for this page.
-
initialized
private boolean initialized
True if this page is initialized.
-
hash_next
LoggingBufferManager.BMPage hash_next
A reference to the next page with this hash key.
-
t
long t
The time this page was last accessed. This value is reset each time the page is requested.
-
access_count
int access_count
The number of times this page has been accessed since it was created.
-
first_write_position
private int first_write_position
The first position in the buffer that was last written.
-
last_write_position
private int last_write_position
The last position in the buffer that was last written.
-
reference_count
private int reference_count
The number of references on this page.
-
-
Constructor Detail
-
BMPage
BMPage(JournalledResource data, long page, int page_size)
Constructs the page.
-
-
Method Detail
-
reset
void reset()
Resets this object.
-
getID
long getID()
Returns the id of the JournalledResource that is being buffered.
-
referenceAdd
void referenceAdd()
Adds 1 to the reference counter on this page.
-
referenceRemove
private void referenceRemove()
Removes 1 from the reference counter on this page.
-
notInUse
boolean notInUse()
Returns true if this PageBuffer is not in use (has 0 reference count and is not inialized.
-
isPage
boolean isPage(long in_id, long in_page)Returns true if this page matches the given id/page_number.
-
readPageContent
private void readPageContent(long page_number, byte[] buf, int pos) throws java.io.IOExceptionReads the current page content into memory. This may read from the data files or from a log.- Throws:
java.io.IOException
-
flush
void flush() throws java.io.IOExceptionFlushes this page out to disk, but does not remove from memory. In a logging system this will flush the changes out to a log.- Throws:
java.io.IOException
-
initialize
void initialize() throws java.io.IOExceptionInitializes the page buffer. If the buffer is already initialized then we just return. If it's not initialized we set up any internal structures that are required to be set up for access to this page.- Throws:
java.io.IOException
-
dispose
void dispose() throws java.io.IOExceptionDisposes of the page buffer if it can be disposed (there are no references to the page and the page is initialized). When disposed the memory used by the page is reclaimed and the content is written out to disk.- Throws:
java.io.IOException
-
read
byte read(int pos)
Reads a single byte from the cached page from memory.
-
read
void read(int pos, byte[] buf, int off, int len)Reads a part of this page into the cached page from memory.
-
write
void write(int pos, byte v)Writes a single byte to the page in memory.
-
write
void write(int pos, byte[] buf, int off, int len)Writes to the given part of the page in memory.
-
equals
public boolean equals(java.lang.Object ob)
- Overrides:
equalsin classjava.lang.Object
-
-