1 5 package com.tc.l2.msg; 6 7 import com.tc.net.groups.AbstractGroupMessage; 8 import com.tc.net.groups.MessageID; 9 import com.tc.object.ObjectID; 10 import com.tc.util.Assert; 11 import com.tc.util.ObjectIDSet2; 12 13 import java.io.IOException ; 14 import java.io.ObjectInput ; 15 import java.io.ObjectOutput ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 public class ObjectListSyncMessage extends AbstractGroupMessage { 20 21 public static final int REQUEST = 0; 22 public static final int RESPONSE = 1; 23 24 private Set oids; 25 26 public ObjectListSyncMessage() { 28 super(-1); 29 } 30 31 public ObjectListSyncMessage(int type) { 32 super(type); 33 } 34 35 public ObjectListSyncMessage(MessageID messageID, int type, Set oids) { 36 super(type, messageID); 37 this.oids = oids; 38 } 39 40 protected void basicReadExternal(int msgType, ObjectInput in) throws IOException { 41 switch (msgType) { 42 case REQUEST: 43 break; 45 case RESPONSE: 46 oids = new ObjectIDSet2(); 47 int size = in.readInt(); 48 for (int i = 0; i < size; i++) { 49 oids.add(new ObjectID(in.readLong())); 50 } 51 break; 52 default: 53 throw new AssertionError ("Unknown Message Type : " + msgType); 54 } 55 } 56 57 protected void basicWriteExternal(int msgType, ObjectOutput out) throws IOException { 58 switch (msgType) { 59 case REQUEST: 60 break; 62 case RESPONSE: 63 Assert.assertNotNull(oids); 64 out.writeInt(oids.size()); 65 for (Iterator i = oids.iterator(); i.hasNext();) { 66 ObjectID oid = (ObjectID) i.next(); 67 out.writeLong(oid.toLong()); 68 } 69 break; 70 default: 71 throw new AssertionError ("Unknown Message Type : " + msgType); 72 } 73 } 74 75 public Set getObjectIDs() { 76 Assert.assertNotNull(oids); 77 return oids; 78 } 79 80 public String toString() { 81 return "ObjectListSyncMessage [ " + messageFrom() + ", type = " + getTypeString() + ", " + oids + "]"; 82 } 83 84 private String getTypeString() { 85 switch (getType()) { 86 case REQUEST: 87 return "REQUEST"; 88 case RESPONSE: 89 return "RESPONSE"; 90 default: 91 throw new AssertionError ("Unknow Type ! : " + getType()); 92 } 93 } 94 95 } 96 | Popular Tags |