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
019package org.apache.hadoop.hdfs.server.protocol;
020
021import java.io.DataInput;
022import java.io.DataOutput;
023import java.io.IOException;
024
025import org.apache.hadoop.hdfs.protocol.Block;
026import org.apache.hadoop.io.Text;
027import org.apache.hadoop.io.Writable;
028
029/**
030 * A data structure to store Block and delHints together, used to send
031 * received/deleted ACKs.
032 */
033public class ReceivedDeletedBlockInfo implements Writable {
034  Block block;
035  String delHints;
036
037  public final static String TODELETE_HINT = "-";
038
039  public ReceivedDeletedBlockInfo() {
040  }
041
042  public ReceivedDeletedBlockInfo(Block blk, String delHints) {
043    this.block = blk;
044    this.delHints = delHints;
045  }
046
047  public Block getBlock() {
048    return this.block;
049  }
050
051  public void setBlock(Block blk) {
052    this.block = blk;
053  }
054
055  public String getDelHints() {
056    return this.delHints;
057  }
058
059  public void setDelHints(String hints) {
060    this.delHints = hints;
061  }
062
063  public boolean equals(Object o) {
064    if (!(o instanceof ReceivedDeletedBlockInfo)) {
065      return false;
066    }
067    ReceivedDeletedBlockInfo other = (ReceivedDeletedBlockInfo) o;
068    return this.block.equals(other.getBlock())
069        && this.delHints.equals(other.delHints);
070  }
071
072  public int hashCode() {
073    assert false : "hashCode not designed";
074    return 0; 
075  }
076
077  public boolean blockEquals(Block b) {
078    return this.block.equals(b);
079  }
080
081  public boolean isDeletedBlock() {
082    return delHints.equals(TODELETE_HINT);
083  }
084
085  @Override
086  public void write(DataOutput out) throws IOException {
087    this.block.write(out);
088    Text.writeString(out, this.delHints);
089  }
090
091  @Override
092  public void readFields(DataInput in) throws IOException {
093    this.block = new Block();
094    this.block.readFields(in);
095    this.delHints = Text.readString(in);
096  }
097
098  public String toString() {
099    return block.toString() + ", delHint: " + delHints;
100  }
101}