001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.dso;
005:
006: import java.util.Date;
007:
008: import javax.swing.Icon;
009:
010: import com.tc.admin.ConnectionContext;
011: import com.tc.admin.common.XTreeNode;
012:
013: import com.tc.objectserver.lockmanager.api.LockMBean;
014: import com.tc.objectserver.lockmanager.api.LockHolder;
015: import com.tc.objectserver.lockmanager.api.ServerLockRequest;
016: import com.tc.objectserver.lockmanager.api.Waiter;
017:
018: public class LockTreeNode extends XTreeNode {
019: private XTreeNode m_holders;
020: private XTreeNode m_pendingRequests;
021: private XTreeNode m_waiters;
022:
023: public LockTreeNode(ConnectionContext cc, LockMBean lock) {
024: super (lock);
025:
026: LockHolder[] holders = lock.getHolders();
027: if (holders != null && holders.length > 0) {
028: add(m_holders = new XTreeNode("Holders"));
029: addHolders(holders);
030: }
031:
032: ServerLockRequest[] pendingRequests = lock.getPendingRequests();
033: if (pendingRequests != null && pendingRequests.length > 0) {
034: add(m_pendingRequests = new XTreeNode("Pending Requests"));
035: addPendingRequests(pendingRequests);
036: }
037:
038: Waiter[] waiters = lock.getWaiters();
039: if (waiters != null && waiters.length > 0) {
040: add(m_waiters = new XTreeNode("Waiters"));
041: addWaiters(waiters);
042: }
043: }
044:
045: public LockMBean getLock() {
046: return (LockMBean) getUserObject();
047: }
048:
049: public Icon getIcon() {
050: return LocksHelper.getHelper().getLockIcon();
051: }
052:
053: public String toString() {
054: return getLock().getLockName();
055: }
056:
057: public void addHolders(LockHolder[] holders) {
058: for (int i = 0; i < holders.length; i++) {
059: m_holders.add(new HolderNode(holders[i]));
060: }
061: }
062:
063: class HolderNode extends XTreeNode {
064: private Date acquiredDate;
065:
066: HolderNode(LockHolder holder) {
067: super (holder);
068: acquiredDate = new Date(holder.getTimeAcquired());
069: }
070:
071: public LockHolder getHolder() {
072: return (LockHolder) getUserObject();
073: }
074:
075: public String toString() {
076: LockHolder holder = getHolder();
077: return holder.getNodeID() + "," + holder.getThreadID()
078: + ",level=" + holder.getLockLevel() + ",acquired="
079: + acquiredDate;
080: }
081: }
082:
083: public void addPendingRequests(ServerLockRequest[] requests) {
084: for (int i = 0; i < requests.length; i++) {
085: m_pendingRequests.add(new RequestNode(requests[i]));
086: }
087: }
088:
089: class RequestNode extends XTreeNode {
090: private Date requestDate;
091:
092: RequestNode(ServerLockRequest request) {
093: super (request);
094: requestDate = new Date(request.getRequestTime());
095: }
096:
097: public ServerLockRequest getRequest() {
098: return (ServerLockRequest) getUserObject();
099: }
100:
101: public String toString() {
102: ServerLockRequest request = getRequest();
103: return request.getNodeID() + "," + request.getThreadID()
104: + ",level=" + request.getLockLevel()
105: + ",requested=" + requestDate;
106: }
107: }
108:
109: public void addWaiters(Waiter[] waiters) {
110: for (int i = 0; i < waiters.length; i++) {
111: m_waiters.add(new WaiterNode(waiters[i]));
112: }
113: }
114:
115: class WaiterNode extends XTreeNode {
116: private Date startDate;
117:
118: WaiterNode(Waiter waiter) {
119: super (waiter);
120: startDate = new Date(waiter.getStartTime());
121: }
122:
123: public Waiter getWaiter() {
124: return (Waiter) getUserObject();
125: }
126:
127: public String toString() {
128: Waiter waiter = getWaiter();
129: return waiter.getNodeID() + "," + waiter.getThreadID()
130: + ",invocation=" + waiter.getWaitInvocation()
131: + ",startTime=" + startDate;
132: }
133: }
134: }
|