001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.l2.msg;
006:
007: import com.tc.net.groups.AbstractGroupMessage;
008: import com.tc.net.groups.MessageID;
009: import com.tc.util.Assert;
010:
011: import java.io.IOException;
012: import java.io.ObjectInput;
013: import java.io.ObjectOutput;
014: import java.util.Set;
015:
016: public class ObjectListSyncMessage extends AbstractGroupMessage {
017:
018: public static final int REQUEST = 0;
019: public static final int RESPONSE = 1;
020: public static final int FAILED_RESPONSE = 2;
021:
022: private Set oids;
023:
024: // To make serialization happy
025: public ObjectListSyncMessage() {
026: super (-1);
027: }
028:
029: public ObjectListSyncMessage(int type) {
030: super (type);
031: }
032:
033: public ObjectListSyncMessage(MessageID messageID, int type, Set oids) {
034: super (type, messageID);
035: this .oids = oids;
036: }
037:
038: public ObjectListSyncMessage(MessageID messageID, int type) {
039: super (type, messageID);
040: }
041:
042: protected void basicReadExternal(int msgType, ObjectInput in)
043: throws IOException, ClassNotFoundException {
044: switch (msgType) {
045: case REQUEST:
046: case FAILED_RESPONSE:
047: // Nothing to read
048: break;
049: case RESPONSE:
050: oids = (Set) in.readObject();
051: break;
052: default:
053: throw new AssertionError("Unknown Message Type : "
054: + msgType);
055: }
056: }
057:
058: protected void basicWriteExternal(int msgType, ObjectOutput out)
059: throws IOException {
060: switch (msgType) {
061: case REQUEST:
062: case FAILED_RESPONSE:
063: // Nothing to write
064: break;
065: case RESPONSE:
066: Assert.assertNotNull(oids);
067: // XXX::Directly serializing instead of using writeObjectIDs() to avoid HUGE messages. Since the (wrapped) set
068: // is ObjectIDSet2 and since it has optimized externalization methods, this should result in far less data
069: // written out.
070: out.writeObject(oids);
071: break;
072: default:
073: throw new AssertionError("Unknown Message Type : "
074: + msgType);
075: }
076: }
077:
078: public Set getObjectIDs() {
079: Assert.assertNotNull(oids);
080: return oids;
081: }
082:
083: public String toString() {
084: return "ObjectListSyncMessage [ " + messageFrom() + ", type = "
085: + getTypeString() + ", " + oids + "]";
086: }
087:
088: private String getTypeString() {
089: switch (getType()) {
090: case REQUEST:
091: return "REQUEST";
092: case FAILED_RESPONSE:
093: return "FAILED_RESPONSE";
094: case RESPONSE:
095: return "RESPONSE";
096: default:
097: throw new AssertionError("Unknow Type ! : " + getType());
098: }
099: }
100:
101: }
|