Package com.mckoi.store
Class JournalledSystem.Resource
- java.lang.Object
-
- com.mckoi.store.JournalledSystem.AbstractResource
-
- com.mckoi.store.JournalledSystem.Resource
-
- All Implemented Interfaces:
JournalledResource
- Enclosing class:
- JournalledSystem
private final class JournalledSystem.Resource extends JournalledSystem.AbstractResource
Represents a resource in this system. A resource is backed by a StoreDataAccessor and may have one or more modifications to it in the journal.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
data_deleted
True if the data resource was deleted.private boolean
data_exists
True if the data store exists.private boolean
data_open
True if the data resource is open.private JournalledSystem.JournalEntry[]
journal_map
The hash of all journal entries on this resource (JournalEntry).private byte[]
page_buffer
A temporary buffer the size of a page.private boolean
really_open
True if the underlying resource is really open.private long
size
The size of the resource.private boolean
there_is_backing_data
True if there is actually data to be read in the above object.-
Fields inherited from class com.mckoi.store.JournalledSystem.AbstractResource
data, id, name, read_only
-
-
Constructor Summary
Constructors Constructor Description Resource(java.lang.String name, long id, StoreDataAccessor data)
Constructs the resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the resource.void
delete()
Deletes the resource.boolean
exists()
Returns true if the resource currently exists.long
getSize()
Returns the size of this resource.void
notifyPostRecover()
void
open(boolean read_only)
Opens the resource.(package private) void
persistClose()
void
persistDelete()
private void
persistOpen(boolean read_only)
void
persistPageChange(long page, int off, int len, java.io.DataInputStream din)
void
persistSetSize(long new_size)
void
read(long page_number, byte[] buf, int off)
Reads a page from the resource.void
setSize(long size)
Sets the size of the resource.void
synch()
void
write(long page_number, byte[] buf, int off, int len)
Writes a page of some previously specified size to the top log.-
Methods inherited from class com.mckoi.store.JournalledSystem.AbstractResource
getID, getPageSize, toString
-
-
-
-
Field Detail
-
size
private long size
The size of the resource.
-
there_is_backing_data
private boolean there_is_backing_data
True if there is actually data to be read in the above object.
-
really_open
private boolean really_open
True if the underlying resource is really open.
-
data_exists
private boolean data_exists
True if the data store exists.
-
data_open
private boolean data_open
True if the data resource is open.
-
data_deleted
private boolean data_deleted
True if the data resource was deleted.
-
journal_map
private final JournalledSystem.JournalEntry[] journal_map
The hash of all journal entries on this resource (JournalEntry).
-
page_buffer
private final byte[] page_buffer
A temporary buffer the size of a page.
-
-
Constructor Detail
-
Resource
Resource(java.lang.String name, long id, StoreDataAccessor data)
Constructs the resource.
-
-
Method Detail
-
persistOpen
private void persistOpen(boolean read_only) throws java.io.IOException
- Throws:
java.io.IOException
-
persistClose
void persistClose() throws java.io.IOException
- Specified by:
persistClose
in classJournalledSystem.AbstractResource
- Throws:
java.io.IOException
-
persistDelete
public void persistDelete() throws java.io.IOException
- Specified by:
persistDelete
in classJournalledSystem.AbstractResource
- Throws:
java.io.IOException
-
persistSetSize
public void persistSetSize(long new_size) throws java.io.IOException
- Specified by:
persistSetSize
in classJournalledSystem.AbstractResource
- Throws:
java.io.IOException
-
persistPageChange
public void persistPageChange(long page, int off, int len, java.io.DataInputStream din) throws java.io.IOException
- Specified by:
persistPageChange
in classJournalledSystem.AbstractResource
- Throws:
java.io.IOException
-
synch
public void synch() throws java.io.IOException
- Specified by:
synch
in classJournalledSystem.AbstractResource
- Throws:
java.io.IOException
-
notifyPostRecover
public void notifyPostRecover()
- Specified by:
notifyPostRecover
in classJournalledSystem.AbstractResource
-
open
public void open(boolean read_only) throws java.io.IOException
Opens the resource. This method will check if the resource exists. If it doesn't exist the 'read' method will return just the journal modifications of a page. If it does exist it opens the resource and uses that as the backing to any 'read' operations.- Throws:
java.io.IOException
-
read
public void read(long page_number, byte[] buf, int off) throws java.io.IOException
Reads a page from the resource. This method reconstructs the page from the underlying data, and from any journal entries. This should read the data to be put into a buffer in memory.- Throws:
java.io.IOException
-
write
public void write(long page_number, byte[] buf, int off, int len) throws java.io.IOException
Writes a page of some previously specified size to the top log. This will add a single entry to the log and any 'read' operations after will contain the written data.- Throws:
java.io.IOException
-
setSize
public void setSize(long size) throws java.io.IOException
Sets the size of the resource.- Throws:
java.io.IOException
-
getSize
public long getSize() throws java.io.IOException
Returns the size of this resource.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Closes the resource. This will actually simply log that the resource has been closed.- Throws:
java.io.IOException
-
delete
public void delete() throws java.io.IOException
Deletes the resource. This will actually simply log that the resource has been deleted.- Throws:
java.io.IOException
-
exists
public boolean exists()
Returns true if the resource currently exists.
-
-