private Page readPage(Page page) throws IOException { // Read the page data pageFile.readPage(page.getPageId(), chunk.getData()); chunk.setOffset(0); chunk.setLength(pageFile.getPageSize()); DataByteArrayInputStream in = new DataByteArrayInputStream(chunk); page.read(in); chunk.setOffset(Page.PAGE_HEADER_SIZE); if (page.getType() == Page.PAGE_END_TYPE) { chunk.setLength((int)(page.getNext())); } if (page.getType() == Page.PAGE_FREE_TYPE) { throw new EOFException("Chunk stream does not exist, page: " + page.getPageId() + " is marked free"); } return page; }
@Override public void close() throws IOException { super.close(); // We need to free up the rest of the page chain.. if (current.getType() == Page.PAGE_PART_TYPE) { free(current.getNext()); } current.makePageEnd(pos, getWriteTransactionId()); // make visible as end page pageFile.addToCache(current); // Write the header.. pos = 0; current.write(this); Transaction.this.write(current, buf); } };
@SuppressWarnings("rawtypes") public ListIndex(PageFile pageFile, Page page) { this(pageFile, page.getPageId()); }
synchronized MessageStoreStatistics get(Transaction tx) throws IOException { load(tx); return page.get(); }
private boolean atEOF() throws IOException { if (chunk.offset < chunk.length) { return false; } if (page.getType() == Page.PAGE_END_TYPE) { return true; } fill(); return chunk.offset >= chunk.length; }
/** * Loads a page from disk. * * @param pageId * the id of the page to load * @param marshaller * the marshaler to use to load the data portion of the Page, may be null if you do not wish to load the data. * @return The page with the given id * @throws IOException * If an disk error occurred. * @throws IllegalStateException * if the PageFile is not loaded */ public <T> Page<T> load(long pageId, Marshaller<T> marshaller) throws IOException { pageFile.assertLoaded(); Page<T> page = new Page<T>(pageId); load(page, marshaller); return page; }
synchronized void load(Transaction tx) throws IOException { if (loaded.compareAndSet(false, true)) { page = tx.load(pageId, null); if (page.getType() == Page.PAGE_FREE_TYPE) { page.set(null); tx.store(page, messageStoreStatisticsMarshaller, true); } } page = tx.load(pageId, messageStoreStatisticsMarshaller); }
final Page copy = page.copy(); pageFile.addToCache(copy);
private Page readPage(Page page) throws IOException { // Read the page data pageFile.readPage(page.getPageId(), chunk.getData()); chunk.setOffset(0); chunk.setLength(pageFile.getPageSize()); DataByteArrayInputStream in = new DataByteArrayInputStream(chunk); page.read(in); chunk.setOffset(Page.PAGE_HEADER_SIZE); if (page.getType() == Page.PAGE_END_TYPE) { chunk.setLength((int)(page.getNext())); } if (page.getType() == Page.PAGE_FREE_TYPE) { throw new EOFException("Chunk stream does not exist, page: " + page.getPageId() + " is marked free"); } return page; }
@Override public void close() throws IOException { super.close(); // We need to free up the rest of the page chain.. if (current.getType() == Page.PAGE_PART_TYPE) { free(current.getNext()); } current.makePageEnd(pos, getWriteTransactionId()); // make visible as end page pageFile.addToCache(current); // Write the header.. pos = 0; current.write(this); Transaction.this.write(current, buf); } };