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.Object
A 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) int
access_count
The number of times this page has been accessed since it was created.private byte[]
buffer
The buffer that contains the data for this page.private JournalledResource
data
The StoreDataAccessor that the page content is part of.private int
first_write_position
The first position in the buffer that was last written.(package private) LoggingBufferManager.BMPage
hash_next
A reference to the next page with this hash key.private boolean
initialized
True if this page is initialized.private int
last_write_position
The last position in the buffer that was last written.private long
page
The page number.private int
page_size
The size of the page.private int
reference_count
The number of references on this page.(package private) long
t
The 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) void
dispose()
Disposes of the page buffer if it can be disposed (there are no references to the page and the page is initialized).boolean
equals(java.lang.Object ob)
(package private) void
flush()
Flushes this page out to disk, but does not remove from memory.(package private) long
getID()
Returns the id of the JournalledResource that is being buffered.(package private) void
initialize()
Initializes the page buffer.(package private) boolean
isPage(long in_id, long in_page)
Returns true if this page matches the given id/page_number.(package private) boolean
notInUse()
Returns true if this PageBuffer is not in use (has 0 reference count and is not inialized.(package private) byte
read(int pos)
Reads a single byte from the cached page from memory.(package private) void
read(int pos, byte[] buf, int off, int len)
Reads a part of this page into the cached page from memory.private void
readPageContent(long page_number, byte[] buf, int pos)
Reads the current page content into memory.(package private) void
referenceAdd()
Adds 1 to the reference counter on this page.private void
referenceRemove()
Removes 1 from the reference counter on this page.(package private) void
reset()
Resets this object.(package private) void
write(int pos, byte v)
Writes a single byte to the page in memory.(package private) void
write(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.IOException
Reads 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.IOException
Flushes 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.IOException
Initializes 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.IOException
Disposes 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:
equals
in classjava.lang.Object
-
-