Hadoop源码学习_DatanodeID
来源:互联网 发布:虚拟社交网络定义 编辑:程序博客网 时间:2024/05/18 09:16
DatanodeInfo extends DatanodeID implements Node,那么DatanodeID是干什么的呢?它封装了node name、storage ID、infoserverPort、ipcPort。
package org.apache.hadoop.hdfs.protocol;import java.io.DataInput;import java.io.DataOutput;import java.io.IOException;import org.apache.hadoop.io.UTF8;import org.apache.hadoop.io.WritableComparable;/** * DatanodeID is composed of the data node * name (hostname:portNumber) and the data storage ID, * which it currently represents. * */public class DatanodeID implements WritableComparable<DatanodeID> { public static final DatanodeID[] EMPTY_ARRAY = {}; public String name; /// hostname:portNumber public String storageID; /// unique per cluster storageID protected int infoPort; /// the port where the infoserver is running public int ipcPort; /// the port where the ipc server is running /** Equivalent to DatanodeID(""). */ public DatanodeID() {this("");} /** Equivalent to DatanodeID(nodeName, "", -1, -1). */ public DatanodeID(String nodeName) {this(nodeName, "", -1, -1);} /** * DatanodeID copy constructor * * @param from */ public DatanodeID(DatanodeID from) { this(from.getName(), from.getStorageID(), from.getInfoPort(), from.getIpcPort()); } /** * Create DatanodeID * @param nodeName (hostname:portNumber) * @param storageID data storage ID * @param infoPort info server port * @param ipcPort ipc server port */ public DatanodeID(String nodeName, String storageID, int infoPort, int ipcPort) { this.name = nodeName; this.storageID = storageID; this.infoPort = infoPort; this.ipcPort = ipcPort; } /** * @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; } /** * @return ipcPort (the port at which the IPC server bound to) */ public int getIpcPort() { return ipcPort; } /** * sets the data storage ID. */ public 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 int getPort() { int colon = name.indexOf(":"); if (colon < 0) { return 50010; // default port. } return Integer.parseInt(name.substring(colon+1)); } public boolean equals(Object to) { if (this == to) { return true; } if (!(to instanceof DatanodeID)) { return false; } 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. */ public void updateRegInfo(DatanodeID nodeReg) { name = nodeReg.getName(); infoPort = nodeReg.getInfoPort(); ipcPort = nodeReg.getIpcPort(); // update any more fields added in future. } /** Comparable. * Basis of compare is the String name (host:portNumber) only. * @param that * @return as specified by Comparable. */ public int compareTo(DatanodeID that) { return name.compareTo(that.getName()); } ///////////////////////////////////////////////// // Writable ///////////////////////////////////////////////// /** {@inheritDoc} */ public void write(DataOutput out) throws IOException { UTF8.writeString(out, name); UTF8.writeString(out, storageID); out.writeShort(infoPort); } /** {@inheritDoc} */ 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; }}
- Hadoop源码学习_DatanodeID
- 学习Hadoop的源码
- Hadoop源码学习_Host2NodesMap
- Hadoop源码学习:RPC
- Hadoop源码学习
- hadoop学习之查看hadoop源码
- 【Hadoop学习笔记】编译源码
- hadoop学习(五)------源码编译
- Hadoop源码学习(一)
- Hadoop源码学习积累2
- hadoop源码学习积累1
- Hadoop源码学习-编译源码
- Hadoop学习笔记-搭建源码学习环境
- Hadoop HDFS源码学习笔记(一)
- Hadoop HDFS源码学习笔记(二)
- Hadoop HDFS源码学习笔记(三)
- Hadoop HDFS源码学习笔记(四)
- Hadoop HDFS源码学习笔记(五)
- Hadoop源码学习_Host2NodesMap
- 传谷歌10月31日发布Nexus 5及Android 4.4
- 第一篇
- 百度收购大众点评可能只是百度的一厢情愿
- MFC 以系统默认的NotePad方式打开txt文本文件
- Hadoop源码学习_DatanodeID
- 双语阅读笔记 - 操作系统 - Process Control Block
- Android Developers:支持不同的屏幕大小
- 天猫宣布启动快递“当日达”
- [设计模式笔记]三. 行为型模式--25. Visitor模式(访问者)对象行为型模式(一)
- zoj 3686 (a simple tree problem)
- C#中Split用法
- 寻找发贴水王
- [设计模式笔记]三. 行为型模式--25. Visitor模式(访问者)对象行为型模式(二)