001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package org.apache.hadoop.hdfs.server.protocol;
020    
021    import org.apache.hadoop.hdfs.protocol.Block;
022    
023    /**
024     * A data structure to store the blocks in an incremental block report. 
025     */
026    public class ReceivedDeletedBlockInfo {
027      Block block;
028      BlockStatus status;
029      String delHints;
030    
031      public static enum BlockStatus {
032        RECEIVING_BLOCK(1),
033        RECEIVED_BLOCK(2),
034        DELETED_BLOCK(3);
035        
036        private final int code;
037        BlockStatus(int code) {
038          this.code = code;
039        }
040        
041        public int getCode() {
042          return code;
043        }
044        
045        public static BlockStatus fromCode(int code) {
046          for (BlockStatus bs : BlockStatus.values()) {
047            if (bs.code == code) {
048              return bs;
049            }
050          }
051          return null;
052        }
053      }
054    
055      public ReceivedDeletedBlockInfo() {
056      }
057    
058      public ReceivedDeletedBlockInfo(
059          Block blk, BlockStatus status, String delHints) {
060        this.block = blk;
061        this.status = status;
062        this.delHints = delHints;
063      }
064    
065      public Block getBlock() {
066        return this.block;
067      }
068    
069      public void setBlock(Block blk) {
070        this.block = blk;
071      }
072    
073      public String getDelHints() {
074        return this.delHints;
075      }
076    
077      public void setDelHints(String hints) {
078        this.delHints = hints;
079      }
080    
081      public BlockStatus getStatus() {
082        return status;
083      }
084    
085      @Override
086      public boolean equals(Object o) {
087        if (!(o instanceof ReceivedDeletedBlockInfo)) {
088          return false;
089        }
090        ReceivedDeletedBlockInfo other = (ReceivedDeletedBlockInfo) o;
091        return this.block.equals(other.getBlock())
092            && this.status == other.status
093            && this.delHints != null
094            && this.delHints.equals(other.delHints);
095      }
096    
097      @Override
098      public int hashCode() {
099        assert false : "hashCode not designed";
100        return 0; 
101      }
102    
103      public boolean blockEquals(Block b) {
104        return this.block.equals(b);
105      }
106    
107      public boolean isDeletedBlock() {
108        return status == BlockStatus.DELETED_BLOCK;
109      }
110    
111      @Override
112      public String toString() {
113        return block.toString() + ", status: " + status +
114          ", delHint: " + delHints;
115      }
116    }