1 5 package com.tc.object.msg; 6 7 import com.tc.async.api.EventContext; 8 import com.tc.bytes.TCByteBuffer; 9 import com.tc.io.TCByteBufferOutput; 10 import com.tc.net.protocol.tcm.MessageChannel; 11 import com.tc.net.protocol.tcm.MessageMonitor; 12 import com.tc.net.protocol.tcm.TCMessageHeader; 13 import com.tc.net.protocol.tcm.TCMessageType; 14 import com.tc.object.ObjectID; 15 import com.tc.object.ObjectRequestContext; 16 import com.tc.object.ObjectRequestID; 17 import com.tc.object.session.SessionID; 18 19 import java.io.IOException ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 27 public class RequestManagedObjectMessageImpl extends DSOMessageBase implements EventContext, 28 RequestManagedObjectMessage { 29 private final static byte MANAGED_OBJECT_ID = 1; 30 private final static byte MANAGED_OBJECTS_REMOVED_ID = 2; 31 private final static byte REQUEST_ID = 4; 32 private final static byte REQUEST_DEPTH_ID = 5; 33 34 private Set objectIDs = new HashSet (); 35 private Set removed = new HashSet (); 36 private ObjectRequestID requestID; 37 private int requestDepth; 38 39 public RequestManagedObjectMessageImpl(MessageMonitor monitor, TCByteBufferOutput out, MessageChannel channel, 40 TCMessageType type) { 41 super(monitor, out, channel, type); 42 } 43 44 public RequestManagedObjectMessageImpl(SessionID sessionID, MessageMonitor monitor, MessageChannel channel, 45 TCMessageHeader header, TCByteBuffer[] data) { 46 super(sessionID, monitor, channel, header, data); 47 } 48 49 protected void dehydrateValues() { 50 for (Iterator i = objectIDs.iterator(); i.hasNext();) { 51 ObjectID id = (ObjectID) i.next(); 52 putNVPair(MANAGED_OBJECT_ID, id.toLong()); 53 } 54 55 for (Iterator i = removed.iterator(); i.hasNext();) { 56 ObjectID id = (ObjectID) i.next(); 57 putNVPair(MANAGED_OBJECTS_REMOVED_ID, id.toLong()); 58 } 59 putNVPair(REQUEST_ID, requestID.toLong()); 60 putNVPair(REQUEST_DEPTH_ID, requestDepth); 61 } 62 63 protected boolean hydrateValue(byte name) throws IOException { 64 switch (name) { 65 case MANAGED_OBJECT_ID: 66 this.objectIDs.add(new ObjectID(getLongValue())); 67 return true; 68 case MANAGED_OBJECTS_REMOVED_ID: 69 this.removed.add(new ObjectID(getLongValue())); 70 return true; 71 case REQUEST_ID: 72 this.requestID = new ObjectRequestID(getLongValue()); 73 return true; 74 case REQUEST_DEPTH_ID: 75 this.requestDepth = getIntValue(); 76 return true; 77 default: 78 return false; 79 } 80 } 81 82 public ObjectRequestID getRequestID() { 83 return requestID; 84 } 85 86 public Set getObjectIDs() { 87 return objectIDs; 88 } 89 90 public Set getRemoved() { 91 return removed; 92 } 93 94 public void initialize(ObjectRequestContext ctxt, Set oids, Set removedIDs) { 95 this.requestID = ctxt.getRequestID(); 96 this.objectIDs.addAll(oids); 97 this.removed = removedIDs; 98 this.requestDepth = ctxt.getRequestDepth(); 99 } 100 101 public int getRequestDepth() { 102 return requestDepth; 103 } 104 } | Popular Tags |