KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > ndfs > DatanodeInfo


1 /* Copyright (c) 2004 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3 package net.nutch.ndfs;
4
5 import net.nutch.io.*;
6 import net.nutch.util.*;
7
8 import java.io.*;
9 import java.util.*;
10
11 /**************************************************
12  * DatanodeInfo tracks stats on a given node
13  *
14  * @author Mike Cafarella
15  **************************************************/

16 public class DatanodeInfo implements Writable, Comparable JavaDoc {
17     UTF8 name;
18     long capacity, remaining, lastUpdate, lastObsoleteCheck;
19     volatile TreeSet blocks;
20
21     /**
22      */

23     public DatanodeInfo() {
24         this(new UTF8(), 0, 0);
25     }
26
27     public DatanodeInfo(UTF8 name) {
28         this.name = name;
29         int colon = name.toString().indexOf(":");
30         this.blocks = new TreeSet();
31         this.lastObsoleteCheck = System.currentTimeMillis();
32         updateHeartbeat(0, 0);
33     }
34
35     /**
36      */

37     public DatanodeInfo(UTF8 name, long capacity, long remaining) {
38         this.name = name;
39         this.blocks = new TreeSet();
40         this.lastObsoleteCheck = System.currentTimeMillis();
41         updateHeartbeat(capacity, remaining);
42     }
43
44     /**
45      */

46     public void updateBlocks(Block newBlocks[]) {
47         blocks.clear();
48         for (int i = 0; i < newBlocks.length; i++) {
49             blocks.add(newBlocks[i]);
50         }
51     }
52
53     /**
54      */

55     public void addBlock(Block b) {
56         blocks.add(b);
57     }
58
59     /**
60      */

61     public void updateHeartbeat(long capacity, long remaining) {
62         this.capacity = capacity;
63         this.remaining = remaining;
64         this.lastUpdate = System.currentTimeMillis();
65     }
66     public UTF8 getName() {
67         return name;
68     }
69     public String JavaDoc toString() {
70         return name.toString();
71     }
72     public Block[] getBlocks() {
73         return (Block[]) blocks.toArray(new Block[blocks.size()]);
74     }
75     public Iterator getBlockIterator() {
76         return blocks.iterator();
77     }
78     public long getCapacity() {
79         return capacity;
80     }
81     public long getRemaining() {
82         return remaining;
83     }
84     public long lastUpdate() {
85         return lastUpdate;
86     }
87     public void updateObsoleteCheck() {
88         this.lastObsoleteCheck = System.currentTimeMillis();
89     }
90     public long lastObsoleteCheck() {
91         return lastObsoleteCheck;
92     }
93
94     /////////////////////////////////////////////////
95
// Comparable
96
/////////////////////////////////////////////////
97
public int compareTo(Object JavaDoc o) {
98         DatanodeInfo d = (DatanodeInfo) o;
99         return name.compareTo(d.getName());
100     }
101
102     /////////////////////////////////////////////////
103
// Writable
104
/////////////////////////////////////////////////
105
/**
106      */

107     public void write(DataOutput out) throws IOException {
108         name.write(out);
109         out.writeLong(capacity);
110         out.writeLong(remaining);
111         out.writeLong(lastUpdate);
112
113         /**
114         out.writeInt(blocks.length);
115         for (int i = 0; i < blocks.length; i++) {
116             blocks[i].write(out);
117         }
118         **/

119     }
120
121     /**
122      */

123     public void readFields(DataInput in) throws IOException {
124         this.name = new UTF8();
125         this.name.readFields(in);
126         this.capacity = in.readLong();
127         this.remaining = in.readLong();
128         this.lastUpdate = in.readLong();
129
130         /**
131         int numBlocks = in.readInt();
132         this.blocks = new Block[numBlocks];
133         for (int i = 0; i < blocks.length; i++) {
134             blocks[i] = new Block();
135             blocks[i].readFields(in);
136         }
137         **/

138     }
139 }
140
141
Popular Tags