001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.msg;
006:
007: import com.tc.async.api.EventContext;
008: import com.tc.bytes.TCByteBuffer;
009: import com.tc.io.TCByteBufferOutput;
010: import com.tc.net.protocol.tcm.MessageChannel;
011: import com.tc.net.protocol.tcm.MessageMonitor;
012: import com.tc.net.protocol.tcm.TCMessageHeader;
013: import com.tc.net.protocol.tcm.TCMessageType;
014: import com.tc.object.ObjectID;
015: import com.tc.object.ObjectRequestContext;
016: import com.tc.object.ObjectRequestID;
017: import com.tc.object.session.SessionID;
018:
019: import java.io.IOException;
020: import java.util.HashSet;
021: import java.util.Iterator;
022: import java.util.Set;
023:
024: public class RequestManagedObjectMessageImpl extends DSOMessageBase
025: implements EventContext, RequestManagedObjectMessage {
026: private final static byte MANAGED_OBJECT_ID = 1;
027: private final static byte MANAGED_OBJECTS_REMOVED_ID = 2;
028: private final static byte REQUEST_ID = 4;
029: private final static byte REQUEST_DEPTH_ID = 5;
030: private final static byte REQUESTING_THREAD_NAME = 6;
031:
032: private Set objectIDs = new HashSet();
033: private Set removed = new HashSet();
034: private ObjectRequestID requestID;
035: private int requestDepth;
036: private String threadName;
037:
038: public RequestManagedObjectMessageImpl(SessionID sessionID,
039: MessageMonitor monitor, TCByteBufferOutput out,
040: MessageChannel channel, TCMessageType type) {
041: super (sessionID, monitor, out, channel, type);
042: }
043:
044: public RequestManagedObjectMessageImpl(SessionID sessionID,
045: MessageMonitor monitor, MessageChannel channel,
046: TCMessageHeader header, TCByteBuffer[] data) {
047: super (sessionID, monitor, channel, header, data);
048: }
049:
050: protected void dehydrateValues() {
051: for (Iterator i = objectIDs.iterator(); i.hasNext();) {
052: ObjectID id = (ObjectID) i.next();
053: putNVPair(MANAGED_OBJECT_ID, id.toLong());
054: }
055:
056: for (Iterator i = removed.iterator(); i.hasNext();) {
057: ObjectID id = (ObjectID) i.next();
058: putNVPair(MANAGED_OBJECTS_REMOVED_ID, id.toLong());
059: }
060: putNVPair(REQUEST_ID, requestID.toLong());
061: putNVPair(REQUEST_DEPTH_ID, requestDepth);
062: putNVPair(REQUESTING_THREAD_NAME, threadName);
063: }
064:
065: protected boolean hydrateValue(byte name) throws IOException {
066: switch (name) {
067: case MANAGED_OBJECT_ID:
068: this .objectIDs.add(new ObjectID(getLongValue()));
069: return true;
070: case MANAGED_OBJECTS_REMOVED_ID:
071: this .removed.add(new ObjectID(getLongValue()));
072: return true;
073: case REQUEST_ID:
074: this .requestID = new ObjectRequestID(getLongValue());
075: return true;
076: case REQUEST_DEPTH_ID:
077: this .requestDepth = getIntValue();
078: return true;
079: case REQUESTING_THREAD_NAME:
080: this .threadName = getStringValue();
081: return true;
082: default:
083: return false;
084: }
085: }
086:
087: public ObjectRequestID getRequestID() {
088: return requestID;
089: }
090:
091: public Set getObjectIDs() {
092: return objectIDs;
093: }
094:
095: public Set getRemoved() {
096: return removed;
097: }
098:
099: public void initialize(ObjectRequestContext ctxt, Set oids,
100: Set removedIDs) {
101: this .requestID = ctxt.getRequestID();
102: this .objectIDs.addAll(oids);
103: this .removed = removedIDs;
104: this .requestDepth = ctxt.getRequestDepth();
105: this .threadName = Thread.currentThread().getName();
106: }
107:
108: public int getRequestDepth() {
109: return requestDepth;
110: }
111:
112: public String getRequestingThreadName() {
113: return threadName;
114: }
115: }
|