1 4 package com.tc.object.msg; 5 6 import com.tc.bytes.TCByteBuffer; 7 import com.tc.io.TCByteBufferOutput; 8 import com.tc.net.protocol.tcm.MessageChannel; 9 import com.tc.net.protocol.tcm.MessageMonitor; 10 import com.tc.net.protocol.tcm.TCMessageHeader; 11 import com.tc.net.protocol.tcm.TCMessageType; 12 import com.tc.object.lockmanager.api.LockID; 13 import com.tc.object.lockmanager.api.LockLevel; 14 import com.tc.object.lockmanager.api.ThreadID; 15 import com.tc.object.lockmanager.impl.GlobalLockInfo; 16 import com.tc.object.session.SessionID; 17 18 import java.io.IOException ; 19 20 public class LockResponseMessage extends DSOMessageBase { 21 private static final byte TYPE = 1; 22 private static final byte THREAD_ID = 2; 23 private static final byte LOCK_ID = 3; 24 private static final byte LOCK_LEVEL = 7; 25 private static final byte GLOBAL_LOCK_INFO = 8; 26 27 public static final int LOCK_AWARD = 1; 28 public static final int LOCK_RECALL = 2; 29 public static final int LOCK_WAIT_TIMEOUT = 3; 30 public static final int LOCK_INFO = 4; 31 public static final int LOCK_NOT_AWARDED = 5; 32 33 private int type; 34 private ThreadID threadID; 35 private LockID lockID; 36 private int lockLevel; 37 private GlobalLockInfo globalLockInfo; 38 39 public LockResponseMessage(MessageMonitor monitor, TCByteBufferOutput out, MessageChannel channel, TCMessageType type) { 40 super(monitor, out, channel, type); 41 } 42 43 public LockResponseMessage(SessionID sessionID, MessageMonitor monitor, MessageChannel channel, 44 TCMessageHeader header, TCByteBuffer[] data) { 45 super(sessionID, monitor, channel, header, data); 46 } 47 48 protected void dehydrateValues() { 49 putNVPair(TYPE, this.type); 50 putNVPair(LOCK_ID, this.lockID.asString()); 51 putNVPair(THREAD_ID, this.threadID.toLong()); 52 putNVPair(LOCK_LEVEL, this.lockLevel); 53 if (globalLockInfo != null) { 54 putNVPair(GLOBAL_LOCK_INFO, globalLockInfo); 55 } 56 } 57 58 protected String describePayload() { 59 StringBuffer rv = new StringBuffer (); 60 rv.append("Type : "); 61 62 if (isLockAward()) { 63 rv.append("LOCK AWARD \n"); 64 } else if (isLockRecall()) { 65 rv.append("LOCK RECALL \n"); 66 } else if (isLockWaitTimeout()) { 67 rv.append("LOCK WAIT TIMEOUT \n"); 68 } else if (isLockInfo()) { 69 rv.append("LOCK INFO"); 70 } else if (isLockNotAwarded()) { 71 rv.append("LOCK NOT AWARDED"); 72 } else { 73 rv.append("UNKNOWN \n"); 74 } 75 76 rv.append(lockID).append(' ').append(threadID).append(' ').append("Lock Type: ").append( 77 LockLevel 78 .toString(lockLevel)) 79 .append('\n'); 80 81 return rv.toString(); 82 } 83 84 protected boolean hydrateValue(byte name) throws IOException { 85 switch (name) { 86 case TYPE: 87 this.type = getIntValue(); 88 return true; 89 case THREAD_ID: 90 this.threadID = new ThreadID(getLongValue()); 92 return true; 93 case LOCK_ID: 94 lockID = new LockID(getStringValue()); 96 return true; 97 case LOCK_LEVEL: 98 this.lockLevel = getIntValue(); 99 return true; 100 case GLOBAL_LOCK_INFO: 101 globalLockInfo = new GlobalLockInfo(); 102 getObject(globalLockInfo); 103 return true; 104 default: 105 return false; 106 } 107 } 108 109 public boolean isLockAward() { 110 return (this.type == LOCK_AWARD); 111 } 112 113 public boolean isLockRecall() { 114 return (this.type == LOCK_RECALL); 115 } 116 117 public boolean isLockWaitTimeout() { 118 return (this.type == LOCK_WAIT_TIMEOUT); 119 } 120 121 public boolean isLockInfo() { 122 return (this.type == LOCK_INFO); 123 } 124 125 public boolean isLockNotAwarded() { 126 return (this.type == LOCK_NOT_AWARDED); 127 } 128 129 public LockID getLockID() { 130 return this.lockID; 131 } 132 133 public ThreadID getThreadID() { 134 return this.threadID; 135 } 136 137 public int getLockLevel() { 138 return this.lockLevel; 139 } 140 141 public GlobalLockInfo getGlobalLockInfo() { 142 return globalLockInfo; 143 } 144 145 public void initializeLockAward(LockID lid, ThreadID sid, int level) { 146 this.type = LOCK_AWARD; 147 initialize(lid, sid, level); 148 } 149 150 public void initializeLockNotAwarded(LockID lid, ThreadID sid, int level) { 151 this.type = LOCK_NOT_AWARDED; 152 initialize(lid, sid, level); 153 } 154 155 public void initializeLockRecall(LockID lid, ThreadID sid, int level) { 156 this.type = LOCK_RECALL; 157 initialize(lid, sid, level); 158 } 159 160 public void initializeLockWaitTimeout(LockID lid, ThreadID sid, int level) { 161 this.type = LOCK_WAIT_TIMEOUT; 162 initialize(lid, sid, level); 163 } 164 165 public void initializeLockInfo(LockID lid, ThreadID sid, int level, GlobalLockInfo info) { 166 this.type = LOCK_INFO; 167 initialize(lid, sid, level, info); 168 } 169 170 private void initialize(LockID lid, ThreadID sid, int level) { 171 initialize(lid, sid, level, null); 172 } 173 174 private void initialize(LockID lid, ThreadID sid, int level, GlobalLockInfo info) { 175 this.threadID = sid; 176 this.lockID = lid; 177 this.lockLevel = level; 178 this.globalLockInfo = info; 179 } 180 181 } | Popular Tags |