Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » kaha » impl » async » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.kaha.impl.async;
   18   
   19   import java.io.DataInput;
   20   import java.io.DataOutput;
   21   import java.io.IOException;
   22   import java.util.concurrent.CountDownLatch;
   23   
   24   /**
   25    * Used as a location in the data store.
   26    * 
   27    * @version $Revision: 1.2 $
   28    */
   29   public final class Location implements Comparable<Location> {
   30   
   31       public static final byte MARK_TYPE = -1;
   32       public static final byte USER_TYPE = 1;
   33       public static final byte NOT_SET_TYPE = 0;
   34       public static final int NOT_SET = -1;
   35   
   36       private int dataFileId = NOT_SET;
   37       private int offset = NOT_SET;
   38       private int size = NOT_SET;
   39       private byte type = NOT_SET_TYPE;
   40       private CountDownLatch latch;
   41   
   42       public Location() {
   43       }
   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   
   81       public void setOffset(int offset) {
   82           this.offset = offset;
   83       }
   84   
   85       public int getDataFileId() {
   86           return dataFileId;
   87       }
   88   
   89       public void setDataFileId(int file) {
   90           this.dataFileId = file;
   91       }
   92   
   93       public byte getType() {
   94           return type;
   95       }
   96   
   97       public void setType(byte type) {
   98           this.type = type;
   99       }
  100   
  101       public String toString() {
  102           String result = "offset = " + offset + ", file = " + dataFileId + ", size = " + size + ", type = "
  103                           + type;
  104           return result;
  105       }
  106   
  107       public void writeExternal(DataOutput dos) throws IOException {
  108           dos.writeInt(dataFileId);
  109           dos.writeInt(offset);
  110           dos.writeInt(size);
  111           dos.writeByte(type);
  112       }
  113   
  114       public void readExternal(DataInput dis) throws IOException {
  115           dataFileId = dis.readInt();
  116           offset = dis.readInt();
  117           size = dis.readInt();
  118           type = dis.readByte();
  119       }
  120   
  121       public CountDownLatch getLatch() {
  122           return latch;
  123       }
  124   
  125       public void setLatch(CountDownLatch latch) {
  126           this.latch = latch;
  127       }
  128   
  129       public int compareTo(Location o) {
  130           Location l = (Location)o;
  131           if (dataFileId == l.dataFileId) {
  132               int rc = offset - l.offset;
  133               return rc;
  134           }
  135           return dataFileId - l.dataFileId;
  136       }
  137   
  138       public boolean equals(Object o) {
  139           boolean result = false;
  140           if (o instanceof Location) {
  141               result = compareTo((Location)o) == 0;
  142           }
  143           return result;
  144       }
  145   
  146       public int hashCode() {
  147           return dataFileId ^ offset;
  148       }
  149   
  150   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » kaha » impl » async » [javadoc | source]