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.bytes.TCByteBuffer;
008: import com.tc.io.TCByteBufferOutput;
009: import com.tc.net.protocol.tcm.MessageChannel;
010: import com.tc.net.protocol.tcm.MessageMonitor;
011: import com.tc.net.protocol.tcm.TCMessageHeader;
012: import com.tc.net.protocol.tcm.TCMessageType;
013: import com.tc.object.lockmanager.api.LockID;
014: import com.tc.object.lockmanager.impl.TCStackTraceElement;
015: import com.tc.object.session.SessionID;
016:
017: import java.io.IOException;
018: import java.util.Collection;
019: import java.util.Iterator;
020: import java.util.LinkedList;
021: import java.util.List;
022:
023: public class LockStatisticsResponseMessage extends DSOMessageBase {
024:
025: private final static byte TYPE = 1;
026: private final static byte LOCK_ID = 2;
027: private final static byte NUMBER_OF_STACK_TRACE = 3;
028: private final static byte STACK_TRACE = 4;
029:
030: // message types
031: private final static byte LOCK_STATISTICS_RESPONSE_MESSAGE_TYPE = 1;
032:
033: private int type;
034: private LockID lockID;
035: private List stackTraces;
036:
037: public LockStatisticsResponseMessage(SessionID sessionID,
038: MessageMonitor monitor, TCByteBufferOutput out,
039: MessageChannel channel, TCMessageType type) {
040: super (sessionID, monitor, out, channel, type);
041: }
042:
043: public LockStatisticsResponseMessage(SessionID sessionID,
044: MessageMonitor monitor, MessageChannel channel,
045: TCMessageHeader header, TCByteBuffer[] data) {
046: super (sessionID, monitor, channel, header, data);
047: }
048:
049: protected void dehydrateValues() {
050: putNVPair(TYPE, this .type);
051: putNVPair(LOCK_ID, lockID.asString());
052: put(stackTraces);
053: }
054:
055: private void put(Collection stackTraces) {
056: super .putNVPair(NUMBER_OF_STACK_TRACE, stackTraces.size());
057: for (Iterator i = stackTraces.iterator(); i.hasNext();) {
058: putNVPair(STACK_TRACE, (TCStackTraceElement) i.next());
059: }
060: }
061:
062: private boolean isLockStatisticsResponseMessage() {
063: return type == LOCK_STATISTICS_RESPONSE_MESSAGE_TYPE;
064: }
065:
066: protected String describePayload() {
067: StringBuffer rv = new StringBuffer();
068: rv.append("Type : ");
069:
070: if (isLockStatisticsResponseMessage()) {
071: rv.append("LOCK STATISTICS RESPONSE \n");
072: } else {
073: rv.append("UNKNOWN \n");
074: }
075:
076: rv.append(lockID).append(' ').append("Lock Type: ")
077: .append('\n');
078:
079: return rv.toString();
080: }
081:
082: protected boolean hydrateValue(byte name) throws IOException {
083: switch (name) {
084: case TYPE:
085: this .type = getIntValue();
086: return true;
087: case LOCK_ID:
088: this .lockID = new LockID(getStringValue());
089: return true;
090: case NUMBER_OF_STACK_TRACE:
091: int numOfStackTraces = getIntValue();
092: this .stackTraces = new LinkedList();
093: return true;
094: case STACK_TRACE:
095: TCStackTraceElement ste = new TCStackTraceElement();
096: getObject(ste);
097: this .stackTraces.add(ste);
098: return true;
099: default:
100: return false;
101: }
102: }
103:
104: public LockID getLockID() {
105: return this .lockID;
106: }
107:
108: public List getStackTraces() {
109: return this .stackTraces;
110: }
111:
112: public void initialize(LockID lid, List stackTraces) {
113: this.lockID = lid;
114: this.stackTraces = stackTraces;
115: this.type = LOCK_STATISTICS_RESPONSE_MESSAGE_TYPE;
116: }
117:
118: }
|