国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

org.apache.hadoop.fs-BlockLocation

2019-11-14 21:19:22
字體:
來源:轉載
供稿:網友
org.apache.hadoop.fs-BlockLocation

工具類吧


  1 package org.apache.hadoop.fs;  2   3 import org.apache.hadoop.io.*;  4 //IO包下的類還沒涉及到。遇到一個分析一個。  5 import java.io.*;  6   7 /*  8  * A BlockLocation lists hosts, offset and length  9  * of block.  10  *  11  */ 12 //記錄block的元數據信息,如所在host,長度和偏移量 13 public class BlockLocation implements Writable { 14 //針對集群塊位置的類 15   static {               // register a ctor 16     WritableFactories.setFactory 17       (BlockLocation.class, 18        new WritableFactory() { 19          public Writable newInstance() { return new BlockLocation(); } 20        }); 21   } 22 //注冊了一個Writable子類BlockLocation的工廠。內部類。詳細可看http://book.2cto.com/201305/21915.html 23   PRivate String[] hosts; //hostnames of datanodes 24   //節點的主機名數組 25   private String[] names; //hostname:portNumber of datanodes 26   //節點的名稱數組。名稱的格式。 27   private String[] topologyPaths; // full path name in network topology 28   //節點在網絡拓撲結構中的地址 29   private long offset;  //offset of the of the block in the file 30   //塊在文件中的偏移量 31   private long length; 32   //塊長度 33  34   /** 35    * Default Constructor 36    */ 37   public BlockLocation() { 38     this(new String[0], new String[0],  0L, 0L); 39   } 40 //默認構造方法 41   /** 42    * Constructor with host, name, offset and length 43    */ 44   public BlockLocation(String[] names, String[] hosts, long offset,  45                        long length) { 46     if (names == null) { 47       this.names = new String[0]; 48     } else { 49       this.names = names; 50     } 51     if (hosts == null) { 52       this.hosts = new String[0]; 53     } else { 54       this.hosts = hosts; 55     } 56     this.offset = offset; 57     this.length = length; 58     this.topologyPaths = new String[0]; 59   } 60 //根據名稱主機偏移量長度初始化一個塊對象 61   /** 62    * Constructor with host, name, network topology, offset and length 63    */ 64   public BlockLocation(String[] names, String[] hosts, String[] topologyPaths, 65                        long offset, long length) { 66     this(names, hosts, offset, length); 67     if (topologyPaths == null) { 68       this.topologyPaths = new String[0]; 69     } else { 70       this.topologyPaths = topologyPaths; 71     } 72   } 73 //根據......... 74   /** 75    * Get the list of hosts (hostname) hosting this block 76    */ 77   public String[] getHosts() throws IOException { 78     if ((hosts == null) || (hosts.length == 0)) { 79       return new String[0]; 80     } else { 81       return hosts; 82     } 83   } 84 //獲得塊的主機 85   /** 86    * Get the list of names (hostname:port) hosting this block 87    */ 88   public String[] getNames() throws IOException { 89     if ((names == null) || (names.length == 0)) { 90       return new String[0]; 91     } else { 92       return this.names; 93     } 94   } 95 //。。。。 96   /** 97    * Get the list of network topology paths for each of the hosts. 98    * The last component of the path is the host. 99    */100   public String[] getTopologyPaths() throws IOException {101     if ((topologyPaths == null) || (topologyPaths.length == 0)) {102       return new String[0];103     } else {104       return this.topologyPaths;105     }106   }107   //。。。。。108   /**109    * Get the start offset of file associated with this block110    */111   public long getOffset() {112     return offset;113   }114   //。。。。。115   /**116    * Get the length of the block117    */118   public long getLength() {119     return length;120   }121   //。。。。。122   /**123    * Set the start offset of file associated with this block124    */125   public void setOffset(long offset) {126     this.offset = offset;127   }128 //。。。。。129   /**130    * Set the length of block131    */132   public void setLength(long length) {133     this.length = length;134   }135 //。。。。。136   /**137    * Set the hosts hosting this block138    */139   public void setHosts(String[] hosts) throws IOException {140     if (hosts == null) {141       this.hosts = new String[0];142     } else {143       this.hosts = hosts;144     }145   }146 //。。。。。147   /**148    * Set the names (host:port) hosting this block149    */150   public void setNames(String[] names) throws IOException {151     if (names == null) {152       this.names = new String[0];153     } else {154       this.names = names;155     }156   }157 //。。。。。158   /**159    * Set the network topology paths of the hosts160    */161   public void setTopologyPaths(String[] topologyPaths) throws IOException {162     if (topologyPaths == null) {163       this.topologyPaths = new String[0];164     } else {165       this.topologyPaths = topologyPaths;166     }167   }168 //。。。。。169   /**170    * Implement write of Writable171    */172   public void write(DataOutput out) throws IOException {173     out.writeLong(offset);174     out.writeLong(length);175     out.writeInt(names.length);176     for (int i=0; i < names.length; i++) {177       Text name = new Text(names[i]);178       name.write(out);179     }180     out.writeInt(hosts.length);181     for (int i=0; i < hosts.length; i++) {182       Text host = new Text(hosts[i]);183       host.write(out);184     }185     out.writeInt(topologyPaths.length);186     for (int i=0; i < topologyPaths.length; i++) {187       Text host = new Text(topologyPaths[i]);188       host.write(out);189     }190   }191   //把塊信息寫到輸出流中。用到了Writable子類Long,Int,Text的Write方法。序列化192   /**193    * Implement readFields of Writable194    */195   public void readFields(DataInput in) throws IOException {196     this.offset = in.readLong();197     this.length = in.readLong();198     int numNames = in.readInt();199     this.names = new String[numNames];200     for (int i = 0; i < numNames; i++) {201       Text name = new Text();202       name.readFields(in);203       names[i] = name.toString();204     }205     int numHosts = in.readInt();206     for (int i = 0; i < numHosts; i++) {207       Text host = new Text();208       host.readFields(in);209       hosts[i] = host.toString();210     }211     int numTops = in.readInt();212     Text path = new Text();213     for (int i = 0; i < numTops; i++) {214       path.readFields(in);215       topologyPaths[i] = path.toString();216     }217   }218   //把塊信息從輸入流中讀出來。....。反序列化219   public String toString() {220     StringBuilder result = new StringBuilder();221     result.append(offset);222     result.append(',');223     result.append(length);224     for(String h: hosts) {225       result.append(',');226       result.append(h);227     }228     return result.toString();229   }230   //。。。。。。231 }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鲁甸县| 长武县| 洪湖市| 拉萨市| 祁阳县| 磴口县| 九寨沟县| 钦州市| 武陟县| 浪卡子县| 韩城市| 岚皋县| 黔西| 紫云| 白沙| 娄烦县| 左贡县| 水富县| 黄山市| 英德市| 巫山县| 凤山市| 麻栗坡县| 弋阳县| 广汉市| 达日县| 五莲县| 布尔津县| 清河县| 黄石市| 子洲县| 报价| 股票| 东丽区| 晋州市| 莱州市| 海晏县| 兴化市| 潜江市| 璧山县| 灵台县|