KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > async > Location


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.kaha.impl.async;
19
20 import java.io.DataInput JavaDoc;
21 import java.io.DataOutput JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.concurrent.CountDownLatch JavaDoc;
24
25 /**
26  * Used as a location in the data store.
27  *
28  * @version $Revision: 1.2 $
29  */

30 public final class Location implements Comparable JavaDoc<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 JavaDoc 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     /**
57      * @return the size of the data record including the header.
58      */

59     public int getSize(){
60         return size;
61     }
62
63     /**
64      * @param size the size of the data record including the header.
65      */

66     public void setSize(int size){
67         this.size=size;
68     }
69
70     /**
71      * @return the size of the payload of the record.
72      */

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 JavaDoc toString(){
101         String JavaDoc result="offset = "+offset+", file = " + dataFileId + ", size = "+size + ", type = "+type;
102         return result;
103     }
104
105     public void writeExternal(DataOutput JavaDoc dos) throws IOException JavaDoc {
106         dos.writeInt(dataFileId);
107         dos.writeInt(offset);
108         dos.writeInt(size);
109         dos.writeByte(type);
110     }
111
112     public void readExternal(DataInput JavaDoc dis) throws IOException JavaDoc {
113         dataFileId = dis.readInt();
114         offset = dis.readInt();
115         size = dis.readInt();
116         type = dis.readByte();
117     }
118
119     public CountDownLatch JavaDoc getLatch() {
120         return latch;
121     }
122     public void setLatch(CountDownLatch JavaDoc 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