1 package org.jgroups.mux; 2 3 import org.jgroups.Global; 4 import org.jgroups.Header; 5 import org.jgroups.util.Streamable; 6 import org.jgroups.util.Util; 7 8 import java.io.*; 9 10 15 public class MuxHeader extends Header implements Streamable { 16 String id=null; 17 18 19 ServiceInfo info; 20 21 public MuxHeader() { 22 } 23 24 public MuxHeader(String id) { 25 this.id=id; 26 } 27 28 public MuxHeader(ServiceInfo info) { 29 this.info=info; 30 } 31 32 public String getId() { 33 return id; 34 } 35 36 public void writeExternal(ObjectOutput out) throws IOException { 37 out.writeUTF(id); 38 out.writeObject(info); 39 } 40 41 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 42 id=in.readUTF(); 43 info=(ServiceInfo)in.readObject(); 44 } 45 46 47 public int size() { 48 int retval=Global.BYTE_SIZE; if(id != null) 50 retval+=id.length() +2; retval+=Global.BYTE_SIZE; if(info != null) 53 retval+=info.size(); 54 return retval; 55 } 56 57 public void writeTo(DataOutputStream out) throws IOException { 58 Util.writeString(id, out); 59 if(info != null) { 60 out.writeBoolean(true); 61 info.writeTo(out); 62 } 63 else { 64 out.writeBoolean(false); 65 } 66 } 67 68 public void readFrom(DataInputStream in) throws IOException, IllegalAccessException , InstantiationException { 69 id=Util.readString(in); 70 if(in.readBoolean()) { 71 info=new ServiceInfo(); 72 info.readFrom(in); 73 } 74 } 75 76 public String toString() { 77 if(id != null) 78 return id; 79 if(info != null) 80 return info.toString(); 81 return ""; 82 } 83 } 84 | Popular Tags |