Package net.sf.joafip.file.entity

Examples of net.sf.joafip.file.entity.PageNode


  private void writeModified() throws FileIOException {
    final Iterator<PageNode> iterator = cacheMap.toWriteIterator();
    long previousPagePositionInfile = Long.MIN_VALUE;
    while (iterator.hasNext()) {
      final PageNode pageNode = iterator.next();
      final long pagePositionInfile = pageNode.positionInFile;
      if (previousPagePositionInfile + pageSize != pagePositionInfile) {
        randomAccessFileDelegate.seek(pagePositionInfile);
      }
      randomAccessFileDelegate.write(pageNode.data);
View Full Code Here


   * @throws FileIOException
   */
  private byte[] getPage(final boolean forWrite) throws FileIOException {
    final long pagePositionInFile = positionInFile & pagePositionMask;
    byte[] pageData;
    PageNode pageNode = cacheMap.get(pagePositionInFile);
    if (pageNode == null) {
      randomAccessFileDelegate.seek(pagePositionInFile);
      final int readLength = randomAccessFileDelegate.read(readBuffer);
      if (readLength == -1) {
        if (forWrite) {
View Full Code Here

    }
    return pageData;
  }

  private void moveDown(final PageNode pageNode) {
    final PageNode next = pageNode.next;
    if (next != null) {
      final PageNode previousOfTheTwo = pageNode.previous;
      final PageNode nextOfTheTwo = next.next;
      // next goes up and page down goes down
      pageNode.next = next.next;
      next.next = pageNode;
      next.previous = pageNode.previous;
      pageNode.previous = next;
View Full Code Here

      }
    }
  }

  private PageNode getFreePage() throws FileIOException {
    final PageNode result;
    if (freePageRootNode == null) {
      result = adjustCache();
    } else {
      result = freePageRootNode;
      freePageRootNode = result.next;
View Full Code Here

  private PageNode adjustCache() throws FileIOException {
    /*
     * remove the first read
     */
    final long removedPosition = usedPageFirstNode.positionInFile;
    final PageNode pageNode = cacheMap.remove(removedPosition);
    if (pageNode == null) {
      final File file = randomAccessFileDelegate.getFile();
      throw FileIOException.create("page " + removedPosition
          + " must be in cache for " + file, file, null);
    } else {
View Full Code Here

    }
    return pageNode;
  }

  private void freePage(final PageNode pageNode) {
    final PageNode previous = pageNode.previous;
    final PageNode next = pageNode.next;
    if (previous == null) {
      usedPageFirstNode = next;
    } else {
      previous.next = next;
    }
View Full Code Here

  }

  private void initializeCache() {
    cacheMap.initialize(maxPage);
    readBuffer = new byte[pageSize];
    PageNode previous = null;
    for (int page = 0; page < maxPage; page++) {
      final PageNode pageNode = new PageNode(new byte[pageSize]);// NOPMD
      pageNode.positionInFile = -1;
      pageNode.toWrite = false;
      if (previous == null) {
        freePageRootNode = pageNode;
      } else {
View Full Code Here

  }

  @Fortest
  public List<Long> getPageSet() {
    final List<Long> pageSet = new LinkedList<Long>();
    PageNode current = usedPageFirstNode;
    while (current != null) {
      assert current.positionInFile != -1;
      assert cacheMap.contains(current);
      // if (current.toWrite) {
      pageSet.add(current.positionInFile);
View Full Code Here

        writeCacheMapSize = writeCacheMap.size();

        field = RandomAccessFileReadWriteCache.class
            .getDeclaredField("freePageRootNode");
        field.setAccessible(true);
        PageNode pageNode = (PageNode) field.get(fileCache);
        freePageRootNodeSize = pageNodeListSize(pageNode);

        field = RandomAccessFileReadWriteCache.class
            .getDeclaredField("usedPageRootNode");
        field.setAccessible(true);
View Full Code Here

    writer.close();
  }

  private int pageNodeListSize(final PageNode pageNode) {
    int size = 0;
    PageNode current = pageNode;
    while (current != null) {
      size++;
      current = current.next;
    }
    return size;
View Full Code Here

TOP

Related Classes of net.sf.joafip.file.entity.PageNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.