KickJava   Java API By Example, From Geeks To Geeks.

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


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.ipc.*;
7 import net.nutch.util.*;
8
9 import java.io.*;
10 import java.net.*;
11 import java.util.*;
12
13 /******************************************************
14  * IPC param
15  *
16  * @author Mike Cafarella
17  ******************************************************/

18 public class FSParam implements Writable, FSConstants {
19     public byte op;
20     public Writable first;
21     public Writable second;
22
23     public FSParam() {
24         this((byte) 0, NullWritable.get(), NullWritable.get());
25     }
26
27     /**
28      */

29     public FSParam(byte op) {
30         this(op, NullWritable.get(), NullWritable.get());
31     }
32
33     /**
34      */

35     FSParam(byte op, Writable first) {
36         this(op, first, NullWritable.get());
37     }
38
39     /**
40      */

41     FSParam(byte op, Writable first, Writable second) {
42         this.op = op;
43         this.first = first;
44         this.second = second;
45     }
46
47     /**
48      */

49     public void write(DataOutput out) throws IOException {
50         out.writeByte(op);
51         first.write(out);
52         second.write(out);
53     }
54
55     /**
56      * Deserialize the opcode and the args
57      */

58     public void readFields(DataInput in) throws IOException {
59         op = in.readByte();
60
61         switch (op) {
62             //
63
// Datanode calls
64
//
65
case OP_HEARTBEAT: {
66             first = new HeartbeatData();
67             break;
68         }
69         case OP_BLOCKREPORT: {
70             first = new ArrayWritable(Block.class);
71             second = new UTF8();
72             break;
73         }
74         case OP_BLOCKRECEIVED: {
75             first = new ArrayWritable(Block.class);
76             second = new UTF8();
77             break;
78         }
79         case OP_ERROR: {
80             first = new UTF8();
81             second = new UTF8();
82             break;
83         }
84
85             //
86
// Client calls
87
//
88
case OP_CLIENT_OPEN: {
89             first = new UTF8();
90             break;
91         }
92         case OP_CLIENT_STARTFILE: {
93             first = new ArrayWritable(UTF8.class);
94             second = new BooleanWritable();
95             break;
96         }
97         case OP_CLIENT_ADDBLOCK: {
98             first = new UTF8();
99             break;
100         }
101         case OP_CLIENT_COMPLETEFILE: {
102             first = new ArrayWritable(UTF8.class);
103             break;
104         }
105         case OP_CLIENT_RENAMETO: {
106             first = new UTF8();
107             second = new UTF8();
108             break;
109         }
110         case OP_CLIENT_DELETE: {
111             first = new UTF8();
112             break;
113         }
114         case OP_CLIENT_EXISTS: {
115             first = new UTF8();
116             break;
117         }
118         case OP_CLIENT_ISDIR: {
119             first = new UTF8();
120             break;
121         }
122         case OP_CLIENT_MKDIRS: {
123             first = new UTF8();
124             break;
125         }
126         case OP_CLIENT_RENEW_LEASE: {
127             first = new UTF8();
128             break;
129         }
130         case OP_CLIENT_OBTAINLOCK: {
131             first = new ArrayWritable(UTF8.class);
132             second = new BooleanWritable();
133             break;
134         }
135         case OP_CLIENT_RELEASELOCK: {
136             first = new ArrayWritable(UTF8.class);
137             break;
138         }
139         case OP_CLIENT_LISTING: {
140             first = new UTF8();
141             break;
142         }
143         case OP_CLIENT_ABANDONBLOCK: {
144             first = new Block();
145             second = new UTF8();
146             break;
147         }
148         case OP_CLIENT_RAWSTATS: {
149             break;
150         }
151         case OP_CLIENT_DATANODEREPORT: {
152             break;
153         }
154         default: {
155             throw new IOException("Unknown opcode: " + op);
156         }
157         }
158
159         first.readFields(in);
160         second.readFields(in);
161     }
162 }
163
Popular Tags