1 package org.jgroups.tests.perf; 2 3 import java.io.Externalizable ; 4 import java.io.IOException ; 5 import java.io.ObjectInput ; 6 import java.io.ObjectOutput ; 7 import java.util.HashMap ; 8 9 15 public class Data implements Externalizable { 16 final static int DISCOVERY_REQ = 1; 17 final static int DISCOVERY_RSP = 2; 18 final static int DATA = 3; 19 final static int DONE = 4; final static int RESULTS = 5; 22 public Data() { 23 ; 24 } 25 26 public Data(int type) { 27 this.type=type; 28 } 29 30 int type=0; 31 byte[] payload=null; boolean sender=false; long num_msgs=0; HashMap results=null; 36 public int getType() { 37 return type; 38 } 39 40 public void writeExternal(ObjectOutput out) throws IOException { 41 out.writeInt(type); 42 if(payload != null) { 43 out.writeInt(payload.length); 44 out.write(payload, 0, payload.length); 45 } 46 else { 47 out.writeInt(0); 48 } 49 out.writeBoolean(sender); 50 out.writeLong(num_msgs); 51 if(results != null) { 52 out.writeBoolean(true); 53 out.writeObject(results); 54 } 55 else 56 out.writeBoolean(false); 57 } 58 59 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 60 type=in.readInt(); 61 int len=in.readInt(); 62 if(len > 0) { 63 payload=new byte[len]; 64 in.readFully(payload, 0, payload.length); 65 } 66 sender=in.readBoolean(); 67 num_msgs=in.readLong(); 68 boolean results_available=in.readBoolean(); 69 if(results_available) 70 results=(HashMap )in.readObject(); 71 } 72 73 108 public String toString() { 109 StringBuffer sb=new StringBuffer (); 110 sb.append('['); 111 switch(type) { 112 case DISCOVERY_REQ: sb.append("DISCOVERY_REQ"); break; 113 case DISCOVERY_RSP: sb.append("DISCOVERY_RSP"); break; 114 case DATA: sb.append("DATA"); break; 115 case DONE: sb.append("DONE"); break; 116 case RESULTS: sb.append("RESULTS"); break; 117 default: sb.append("<unknown>"); break; 118 } 119 sb.append("] "); 120 return sb.toString(); 121 } 122 } 123 | Popular Tags |