1 4 package com.tc.object.lockmanager.impl; 5 6 import com.tc.io.TCByteBufferInputStream; 7 import com.tc.io.TCByteBufferOutput; 8 import com.tc.io.TCSerializable; 9 import com.tc.object.lockmanager.api.LockID; 10 11 import java.io.IOException ; 12 import java.util.ArrayList ; 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 16 20 public class GlobalLockInfo implements TCSerializable { 21 private LockID lockID; 22 private int level; 23 private int lockRequestQueueLength; 24 private int lockUpgradeQueueLength; 25 private Collection greedyHoldersInfo; 26 private Collection holdersInfo; 27 private Collection waitersInfo; 28 29 public GlobalLockInfo() { 30 super(); 31 } 32 33 public GlobalLockInfo(LockID lockID, int level, int lockRequestQueueLength, int lockUpgradeQueueLength, Collection greedyHolders, Collection holders, Collection waiters) { 34 this.lockID = lockID; 35 this.level = level; 36 this.lockRequestQueueLength = lockRequestQueueLength; 37 this.lockUpgradeQueueLength = lockUpgradeQueueLength; 38 this.greedyHoldersInfo = greedyHolders; 39 this.holdersInfo = holders; 40 this.waitersInfo = waiters; 41 } 42 43 public int getLockRequestQueueLength() { 44 return lockRequestQueueLength; 45 } 46 47 public int getLockUpgradeQueueLength() { 48 return lockUpgradeQueueLength; 49 } 50 51 public boolean isLocked() { 52 return (holdersInfo != null && holdersInfo.size() > 0) || 53 (greedyHoldersInfo != null && greedyHoldersInfo.size() > 0); 54 } 55 56 public Collection getGreedyHoldersInfo() { 57 return greedyHoldersInfo; 58 } 59 60 public Collection getHoldersInfo() { 61 return holdersInfo; 62 } 63 64 public Collection getWaitersInfo() { 65 return waitersInfo; 66 } 67 68 public void serializeTo(TCByteBufferOutput serialOutput) { 69 serialOutput.writeString(lockID.asString()); 70 serialOutput.writeInt(level); 71 serialOutput.writeInt(lockRequestQueueLength); 72 serialOutput.writeInt(lockUpgradeQueueLength); 73 serialOutput.writeInt(holdersInfo.size()); 74 for (Iterator i = holdersInfo.iterator(); i.hasNext();) { 75 GlobalLockStateInfo holderInfo = (GlobalLockStateInfo) i.next(); 76 holderInfo.serializeTo(serialOutput); 77 } 78 serialOutput.writeInt(greedyHoldersInfo.size()); 79 for (Iterator i=greedyHoldersInfo.iterator(); i.hasNext(); ) { 80 GlobalLockStateInfo holderInfo = (GlobalLockStateInfo) i.next(); 81 holderInfo.serializeTo(serialOutput); 82 } 83 serialOutput.writeInt(waitersInfo.size()); 84 for (Iterator i=waitersInfo.iterator(); i.hasNext(); ) { 85 GlobalLockStateInfo holderInfo = (GlobalLockStateInfo) i.next(); 86 holderInfo.serializeTo(serialOutput); 87 } 88 } 89 90 public Object deserializeFrom(TCByteBufferInputStream serialInput) throws IOException { 91 this.lockID = new LockID(serialInput.readString()); 92 this.level = serialInput.readInt(); 93 this.lockRequestQueueLength = serialInput.readInt(); 94 this.lockUpgradeQueueLength = serialInput.readInt(); 95 int size = serialInput.readInt(); 96 holdersInfo = new ArrayList (size); 97 for (int i = 0; i < size; i++) { 98 GlobalLockStateInfo holderInfo = new GlobalLockStateInfo(); 99 holderInfo.deserializeFrom(serialInput); 100 holdersInfo.add(holderInfo); 101 } 102 size = serialInput.readInt(); 103 greedyHoldersInfo = new ArrayList (size); 104 for (int i = 0; i < size; i++) { 105 GlobalLockStateInfo holderInfo = new GlobalLockStateInfo(); 106 holderInfo.deserializeFrom(serialInput); 107 greedyHoldersInfo.add(holderInfo); 108 } 109 size = serialInput.readInt(); 110 waitersInfo = new ArrayList (size); 111 for (int i = 0; i < size; i++) { 112 GlobalLockStateInfo holderInfo = new GlobalLockStateInfo(); 113 holderInfo.deserializeFrom(serialInput); 114 waitersInfo.add(holderInfo); 115 } 116 return this; 117 } 118 119 } | Popular Tags |