1 18 package org.apache.activemq.kaha.impl.index; 19 20 import java.io.DataInput ; 21 import java.io.DataOutput ; 22 import java.io.IOException ; 23 24 import org.apache.activemq.kaha.StoreEntry; 25 import org.apache.activemq.kaha.StoreLocation; 26 import org.apache.activemq.kaha.impl.data.DataItem; 27 import org.apache.activemq.kaha.impl.data.Item; 28 33 public class IndexItem implements Item, StoreEntry{ 34 35 public static final int INDEX_SIZE=51; 36 public static final int INDEXES_ONLY_SIZE=19; 37 IndexItem next; 39 IndexItem prev; 40 41 protected long offset=POSITION_NOT_SET; 42 private long previousItem=POSITION_NOT_SET; 43 private long nextItem=POSITION_NOT_SET; 44 private boolean active=true; 45 46 private long keyOffset=POSITION_NOT_SET; 48 private int keyFile=(int) POSITION_NOT_SET; 49 private int keySize=0; 50 51 private long valueOffset=POSITION_NOT_SET; 52 private int valueFile=(int) POSITION_NOT_SET; 53 private int valueSize=0; 54 55 58 public IndexItem(){} 59 60 void reset(){ 61 previousItem=POSITION_NOT_SET; 62 nextItem=POSITION_NOT_SET; 63 keyOffset=POSITION_NOT_SET; 64 keyFile=(int) POSITION_NOT_SET; 65 keySize=0; 66 valueOffset=POSITION_NOT_SET; 67 valueFile=(int) POSITION_NOT_SET; 68 valueSize=0; 69 active=true; 70 } 71 72 76 public StoreLocation getKeyDataItem(){ 77 DataItem result=new DataItem(); 78 result.setOffset(keyOffset); 79 result.setFile(keyFile); 80 result.setSize(keySize); 81 return result; 82 } 83 84 88 public StoreLocation getValueDataItem(){ 89 DataItem result=new DataItem(); 90 result.setOffset(valueOffset); 91 result.setFile(valueFile); 92 result.setSize(valueSize); 93 return result; 94 } 95 96 public void setValueData(StoreLocation item){ 97 valueOffset=item.getOffset(); 98 valueFile=item.getFile(); 99 valueSize=item.getSize(); 100 } 101 102 public void setKeyData(StoreLocation item){ 103 keyOffset=item.getOffset(); 104 keyFile=item.getFile(); 105 keySize=item.getSize(); 106 } 107 108 112 public void write(DataOutput dataOut) throws IOException { 113 dataOut.writeShort(MAGIC); 114 dataOut.writeBoolean(active); 115 dataOut.writeLong(previousItem); 116 dataOut.writeLong(nextItem); 117 dataOut.writeInt(keyFile); 118 dataOut.writeLong(keyOffset); 119 dataOut.writeInt(keySize); 120 dataOut.writeInt(valueFile); 121 dataOut.writeLong(valueOffset); 122 dataOut.writeInt(valueSize); 123 } 124 125 void updateIndexes(DataOutput dataOut) throws IOException { 126 dataOut.writeShort(MAGIC); 127 dataOut.writeBoolean(active); 128 dataOut.writeLong(previousItem); 129 dataOut.writeLong(nextItem); 130 } 131 132 136 public void read(DataInput dataIn) throws IOException { 137 if(dataIn.readShort()!=MAGIC){ 138 throw new BadMagicException(); 139 } 140 active=dataIn.readBoolean(); 141 previousItem=dataIn.readLong(); 142 nextItem=dataIn.readLong(); 143 keyFile=dataIn.readInt(); 144 keyOffset=dataIn.readLong(); 145 keySize=dataIn.readInt(); 146 valueFile=dataIn.readInt(); 147 valueOffset=dataIn.readLong(); 148 valueSize=dataIn.readInt(); 149 } 150 151 void readIndexes(DataInput dataIn) throws IOException { 152 if(dataIn.readShort()!=MAGIC){ 153 throw new BadMagicException(); 154 } 155 active=dataIn.readBoolean(); 156 previousItem=dataIn.readLong(); 157 nextItem=dataIn.readLong(); 158 } 159 160 163 public void setPreviousItem(long newPrevEntry){ 164 previousItem=newPrevEntry; 165 } 166 167 170 long getPreviousItem(){ 171 return previousItem; 172 } 173 174 177 public void setNextItem(long newNextEntry){ 178 nextItem=newNextEntry; 179 } 180 181 185 public long getNextItem(){ 186 return nextItem; 187 } 188 189 192 void setKeyOffset(long newObjectOffset){ 193 keyOffset=newObjectOffset; 194 } 195 196 199 long getKeyOffset(){ 200 return keyOffset; 201 } 202 203 207 public int getKeyFile(){ 208 return keyFile; 209 } 210 211 214 void setKeyFile(int keyFile){ 215 this.keyFile=keyFile; 216 } 217 218 222 public int getValueFile(){ 223 return valueFile; 224 } 225 226 229 void setValueFile(int valueFile){ 230 this.valueFile=valueFile; 231 } 232 233 237 public long getValueOffset(){ 238 return valueOffset; 239 } 240 241 244 public void setValueOffset(long valueOffset){ 245 this.valueOffset=valueOffset; 246 } 247 248 251 boolean isActive(){ 252 return active; 253 } 254 255 258 void setActive(boolean active){ 259 this.active=active; 260 } 261 262 266 public long getOffset(){ 267 return offset; 268 } 269 270 273 public void setOffset(long offset){ 274 this.offset=offset; 275 } 276 277 281 public int getKeySize() { 282 return keySize; 283 } 284 285 public void setKeySize(int keySize) { 286 this.keySize = keySize; 287 } 288 289 293 public int getValueSize() { 294 return valueSize; 295 } 296 297 public void setValueSize(int valueSize) { 298 this.valueSize = valueSize; 299 } 300 301 304 public String toString(){ 305 String result="offset="+offset+ 306 ", key=("+keyFile+", "+keyOffset+", "+keySize+")"+ 307 ", value=("+valueFile+", "+valueOffset+", "+valueSize+")"+ 308 ", previousItem="+previousItem+", nextItem="+nextItem 309 ; 310 return result; 311 } 312 313 public boolean equals(Object obj){ 314 boolean result = obj == this; 315 if (!result && obj != null && obj instanceof IndexItem){ 316 IndexItem other = (IndexItem)obj; 317 result = other.offset == this.offset; 318 } 319 return result; 320 } 321 322 public int hashCode(){ 323 return (int)offset; 324 } 325 } 326 | Popular Tags |