hadoop(0.1.1.2)源码学习-org.apache.hadoop.dfs DatanodeID

 * DatanodeID is composed of the data node 
 * name (hostname:portNumber) and the data storage ID, 
 * which it currently represents.

(DataNodeId 由 主机名+端口号和数据存储ID来代表)

 

// 实现了org.apache.hadoop.io.WritableComparable接口,该接口是个空接口,表明该类有可写可比较的能力

public class DatanodeID implements WritableComparable

 

protected String name;      /// hostname:portNumber
  protected String storageID; /// unique per cluster storageID
  protected int infoPort;     /// the port where the infoserver is running

 

// 三类构造器

/**
   * DatanodeID default constructor
   */
  public DatanodeID() {
    this( new String(), new String(), -1 );
  }

  /**
   * DatanodeID copy constructor
   * 
   * @param from
   */
  public DatanodeID( DatanodeID from ) {
    this( from.getName(), from.getStorageID(), from.getInfoPort() );
  }

  
  /**
   * Create DatanodeID
   * 
   * @param nodeName (hostname:portNumber) 
   * @param storageID data storage ID
   */
  public DatanodeID( String nodeName, String storageID, int infoPort ) {
    this.name = nodeName;
    this.storageID = storageID;
    this.infoPort = infoPort;
  }

 

// Get, Set , toSting方法

  /**
   * @return hostname:portNumber.
   */
  public String getName() {
    return name;
  }
  
  /**
   * @return data storage ID.
   */
  public String getStorageID() {
    return this.storageID;
  }

  /**
   * @return infoPort (the port at which the HTTP server bound to)
   */
  public int getInfoPort() {
    return infoPort;
  }

  /**
   * @sets data storage ID.
   */
  void setStorageID(String storageID) {
    this.storageID = storageID;
  }

  /**
   * @return hostname and no :portNumber.
   */
  public String getHost() {
    int colon = name.indexOf(":");
    if (colon < 0) {
      return name;
    } else {
      return name.substring(0, colon);
    }
  }
  
  public boolean equals( Object to ) {
    return (name.equals(((DatanodeID)to).getName()) &&
        storageID.equals(((DatanodeID)to).getStorageID()));
  }
  
  public int hashCode() {
    return name.hashCode()^ storageID.hashCode();
  }
  
  public String toString() {
    return name;
  }

 

/**
   * Update fields when a new registration request comes in.
   * Note that this does not update storageID.
   */
  void updateRegInfo( DatanodeID nodeReg ) {
      name = nodeReg.getName();
      infoPort = nodeReg.getInfoPort();
      // update any more fields added in future.
  }

 

/** Comparable.
   * Basis of compare is the String name (host:portNumber) only.
   * @param o
   * @return as specified by Comparable.
   */
  public int compareTo(Object o) {
    return name.compareTo(((DatanodeID)o).getName());
  }

 

/
  // Writable
  /
  /**
   */
  public void write(DataOutput out) throws IOException {
    UTF8.writeString(out, name);
    UTF8.writeString(out, storageID);
    out.writeShort(infoPort);
  }

  /**
   */
  public void readFields(DataInput in) throws IOException {
    name = UTF8.readString(in);
    storageID = UTF8.readString(in);
    // the infoPort read could be negative, if the port is a large number (more
    // than 15 bits in storage size (but less than 16 bits).
    // So chop off the first two bytes (and hence the signed bits) before 
    // setting the field.
    this.infoPort = in.readShort() & 0x0000ffff;
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值