1 18 package org.apache.activemq.kaha.impl.async; 19 20 import java.io.DataInput ; 21 import java.io.DataOutput ; 22 import java.io.IOException ; 23 import java.util.concurrent.CountDownLatch ; 24 25 30 public final class Location implements Comparable <Location> { 31 32 public static final byte MARK_TYPE=-1; 33 public static final byte USER_TYPE=1; 34 public static final byte NOT_SET_TYPE=0; 35 public static final int NOT_SET=-1; 36 37 private int dataFileId=NOT_SET; 38 private int offset=NOT_SET; 39 private int size=NOT_SET; 40 private byte type=NOT_SET_TYPE; 41 private CountDownLatch latch; 42 43 public Location(){} 44 45 Location(Location item) { 46 this.dataFileId = item.dataFileId; 47 this.offset = item.offset; 48 this.size = item.size; 49 this.type = item.type; 50 } 51 52 boolean isValid(){ 53 return dataFileId != NOT_SET; 54 } 55 56 59 public int getSize(){ 60 return size; 61 } 62 63 66 public void setSize(int size){ 67 this.size=size; 68 } 69 70 73 public int getPaylodSize() { 74 return size-AsyncDataManager.ITEM_HEAD_FOOT_SPACE; 75 } 76 77 public int getOffset(){ 78 return offset; 79 } 80 public void setOffset(int offset){ 81 this.offset=offset; 82 } 83 84 public int getDataFileId(){ 85 return dataFileId; 86 } 87 88 public void setDataFileId(int file){ 89 this.dataFileId=file; 90 } 91 92 public byte getType() { 93 return type; 94 } 95 96 public void setType(byte type) { 97 this.type = type; 98 } 99 100 public String toString(){ 101 String result="offset = "+offset+", file = " + dataFileId + ", size = "+size + ", type = "+type; 102 return result; 103 } 104 105 public void writeExternal(DataOutput dos) throws IOException { 106 dos.writeInt(dataFileId); 107 dos.writeInt(offset); 108 dos.writeInt(size); 109 dos.writeByte(type); 110 } 111 112 public void readExternal(DataInput dis) throws IOException { 113 dataFileId = dis.readInt(); 114 offset = dis.readInt(); 115 size = dis.readInt(); 116 type = dis.readByte(); 117 } 118 119 public CountDownLatch getLatch() { 120 return latch; 121 } 122 public void setLatch(CountDownLatch latch) { 123 this.latch = latch; 124 } 125 126 public int compareTo(Location o) { 127 Location l = (Location)o; 128 if( dataFileId == l.dataFileId ) { 129 int rc = offset-l.offset; 130 return rc; 131 } 132 return dataFileId - l.dataFileId; 133 } 134 135 } 136 | Popular Tags |