001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.admin.dso;
006:
007: import com.tc.admin.common.LockElementWrapper;
008: import com.tc.management.L2LockStatsManagerImpl.LockStat;
009:
010: import java.util.HashMap;
011:
012: public class LockStatWrapper implements LockElementWrapper {
013: private LockStat lockStat;
014: private String lockId;
015:
016: private static HashMap<String, TraceHolder> traceCache = new HashMap<String, TraceHolder>();
017:
018: static class TraceHolder {
019: private String stackTrace;
020: private String allStackTraces;
021:
022: TraceHolder(String stackTrace, String allStackTraces) {
023: this .stackTrace = stackTrace;
024: this .allStackTraces = allStackTraces;
025: }
026: }
027:
028: public LockStatWrapper(LockStat lockStat) {
029: this .lockStat = lockStat;
030: this .lockId = lockStat.getLockID().asString();
031: if (this .lockId.charAt(0) != '@'
032: && this .lockId.charAt(0) != '^') {
033: this .lockId = "^" + this .lockId;
034: }
035: }
036:
037: public String getLockID() {
038: return lockId;
039: }
040:
041: public long getNumOfLockRequested() {
042: return lockStat.getNumOfLockRequested();
043: }
044:
045: public long getNumOfLockReleased() {
046: return lockStat.getNumOfLockReleased();
047: }
048:
049: public long getNumOfPendingRequests() {
050: return lockStat.getNumOfPendingRequests();
051: }
052:
053: public long getNumOfPendingWaiters() {
054: return lockStat.getNumOfPendingWaiters();
055: }
056:
057: public long getNumOfLockHopRequests() {
058: return lockStat.getNumOfLockHopRequests();
059: }
060:
061: public long getAvgWaitTimeInMillis() {
062: return lockStat.getAvgWaitTimeInMillis();
063: }
064:
065: public long getAvgHeldTimeInMillis() {
066: return lockStat.getAvgHeldTimeInMillis();
067: }
068:
069: public void setStackTrace(String stackTrace) {
070: if (stackTrace != null) {
071: TraceHolder holder = traceCache.get(lockId);
072: if (holder == null) {
073: traceCache.put(lockId,
074: new TraceHolder(stackTrace, null));
075: }
076: } else {
077: traceCache.remove(lockId);
078: }
079: }
080:
081: public String getStackTrace() {
082: TraceHolder holder = traceCache.get(lockId);
083: return holder != null ? holder.stackTrace : null;
084: }
085:
086: public void setAllStackTraces(String allStackTraces) {
087: if (allStackTraces != null) {
088: TraceHolder holder = traceCache.get(lockId);
089: if (holder == null) {
090: traceCache.put(lockId, new TraceHolder(null,
091: allStackTraces));
092: }
093: } else {
094: traceCache.remove(lockId);
095: }
096: }
097:
098: public String getAllStackTraces() {
099: TraceHolder holder = traceCache.get(lockId);
100: return holder != null ? holder.allStackTraces : null;
101: }
102: }
|