1 19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage; 20 21 import java.io.*; 22 23 import org.netbeans.mdr.persistence.*; 24 25 28 public class CachedPage extends IntrusiveList.Member { 29 30 31 PageID key; 32 33 private int pinCount; 34 35 boolean isDirty; 36 37 boolean heldForLog; 38 39 40 public byte contents[]; 41 42 43 private FileCache owner; 44 45 48 CachedPage(int size) { 49 key = null; 50 pinCount = 0; 51 isDirty = false; 52 heldForLog = false; 53 owner = null; 54 contents = new byte[size]; 55 } 56 57 public FileCache getOwner() { 58 return owner; 59 } 60 61 67 public synchronized void setWritable() throws StorageException{ 68 owner.setWritable(this); 69 } 70 71 74 void reInit(FileCache owner, PageID id) { 75 this.owner = owner; 76 key = id; 77 pinCount = 0; 78 isDirty = false; 79 heldForLog = false; 80 } 81 82 public int pin(FileCache owner) { 83 assert pinCount == 0 || this.owner == owner; 84 this.owner = owner; 85 return pinCount++; 86 } 87 88 public int getPinCount() { 89 return pinCount; 90 } 91 92 public int innerUnpin() { 93 pinCount--; 94 return pinCount; 95 } 96 97 98 public void unpin() throws StorageException { 99 owner.unpin(this); 100 } 101 102 103 public String toString() { 104 StringBuffer debug = new StringBuffer ("" + key); 105 if (pinCount > 0) 106 debug.append(" pin count: " + pinCount); 107 if (isDirty) 108 debug.append(" dirty"); 109 if (heldForLog) 110 debug.append(" held"); 111 debug.append("\n"); 112 113 int j = 0; 114 for (int i = 0; i < contents.length; i++, j++) { 115 if (j >= 16) { 116 debug.append("\n"); 117 j = 0; 118 } 119 int data = (int)(contents[i]) & 0xFF; 120 debug.append(Integer.toHexString(data)); 121 debug.append(" "); 122 } 123 debug.append("\n"); 124 125 return debug.toString(); 126 } 127 128 129 } 130 | Popular Tags |