1 2 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 18 public class FSResults implements Writable, FSConstants { 19 public byte op; 20 public Writable first; 21 public Writable second; 22 boolean success = false; 23 boolean tryagain = false; 24 25 27 public FSResults() { 28 this((byte) 0, NullWritable.get(), NullWritable.get()); 29 } 30 public FSResults(byte op) { 31 this(op, NullWritable.get(), NullWritable.get()); 32 } 33 public FSResults(byte op, Writable first) { 34 this(op, first, NullWritable.get()); 35 } 36 37 39 public FSResults(byte op, Writable first, Writable second) { 40 this.op = op; 41 this.first = first; 42 this.second = second; 43 } 44 45 48 public boolean success() { 49 return success; 50 } 51 52 55 public boolean tryagain() { 56 return tryagain; 57 } 58 59 61 public void write(DataOutput out) throws IOException { 62 out.writeByte(op); 63 first.write(out); 64 second.write(out); 65 } 66 67 69 public void readFields(DataInput in) throws IOException { 70 op = in.readByte(); 71 72 switch (op) { 73 case OP_INVALIDATE_BLOCKS: { 77 success = true; 78 first = new ArrayWritable(Block.class); 79 break; 80 } 81 case OP_TRANSFERBLOCKS: { 82 success = true; 83 first = new ArrayWritable(Block.class); 84 second = new TwoDArrayWritable(DatanodeInfo.class); 85 break; 86 } 87 case OP_ACK: { 88 success = true; 89 break; 90 } 91 92 case OP_CLIENT_OPEN_ACK: { 96 success = true; 97 first = new ArrayWritable(Block.class); 98 second = new TwoDArrayWritable(DatanodeInfo.class); 99 break; 100 } 101 case OP_CLIENT_STARTFILE_ACK: 102 case OP_CLIENT_ADDBLOCK_ACK: { 103 success = true; 104 first = new Block(); 105 second = new ArrayWritable(DatanodeInfo.class); 106 break; 107 } 108 case OP_CLIENT_COMPLETEFILE_ACK: { 109 success = true; 110 break; 111 } 112 case OP_CLIENT_RENAMETO_ACK: 113 case OP_CLIENT_DELETE_ACK: { 114 success = true; 115 break; 116 } 117 case OP_CLIENT_LISTING_ACK: { 118 success = true; 119 first = new ArrayWritable(NDFSFileInfo.class); 120 break; 121 } 122 case OP_CLIENT_OBTAINLOCK_ACK: { 123 success = true; 124 break; 125 } 126 case OP_CLIENT_RELEASELOCK_ACK: { 127 success = true; 128 break; 129 } 130 case OP_CLIENT_EXISTS_ACK: 131 case OP_CLIENT_ISDIR_ACK: 132 case OP_CLIENT_MKDIRS_ACK: { 133 success = true; 134 break; 135 } 136 case OP_CLIENT_RENEW_LEASE_ACK: { 137 success = true; 138 break; 139 } 140 case OP_CLIENT_ABANDONBLOCK_ACK: { 141 success = true; 142 break; 143 } 144 case OP_CLIENT_RAWSTATS_ACK: { 145 success = true; 146 first = new ArrayWritable(LongWritable.class); 147 break; 148 } 149 case OP_CLIENT_DATANODEREPORT_ACK: { 150 success = true; 151 first = new ArrayWritable(DatanodeInfo.class); 152 break; 153 } 154 case OP_CLIENT_TRYAGAIN: { 155 success = true; 156 tryagain = true; 157 break; 158 } 159 case OP_FAILURE: { 160 success = false; 161 break; 162 } 163 default: { 164 throw new IOException("Unknown opcode: " + op); 165 } 166 } 167 168 first.readFields(in); 169 second.readFields(in); 170 } 171 } 172 173 | Popular Tags |