01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.management.exposed;
05:
06: import com.tc.management.AbstractTerracottaMBean;
07: import com.tc.management.beans.sessions.SessionMonitorMBean;
08: import com.tc.management.beans.tx.ClientTxMonitorMBean;
09: import com.tc.management.opentypes.adapters.ClassCreationCount;
10: import com.tc.management.stats.TopN;
11:
12: import java.util.Iterator;
13:
14: import javax.management.NotCompliantMBeanException;
15: import javax.management.openmbean.CompositeData;
16: import javax.management.openmbean.OpenDataException;
17: import javax.management.openmbean.TabularData;
18:
19: public class SessionsProduct extends AbstractTerracottaMBean implements
20: SessionsProductMBean {
21:
22: private final SessionMonitorMBean sessionsMonitor;
23: private final ClientTxMonitorMBean clientTxMonitor;
24:
25: public SessionsProduct(final SessionMonitorMBean sessionsMonitor,
26: final ClientTxMonitorMBean clientTxMonitor)
27: throws NotCompliantMBeanException {
28: super (SessionsProductMBean.class, false);
29: this .sessionsMonitor = sessionsMonitor;
30: this .clientTxMonitor = clientTxMonitor;
31: }
32:
33: public void reset() {
34: // nothing to reset
35: }
36:
37: public int getRequestCount() {
38: return sessionsMonitor.getRequestCount();
39: }
40:
41: public int getRequestCountPerSecond() {
42: return sessionsMonitor.getRequestRatePerSecond();
43: }
44:
45: public int getSessionsCreatedPerMinute() {
46: return sessionsMonitor.getSessionCreationRatePerMinute();
47: }
48:
49: public int getSessionsExpiredPerMinute() {
50: return sessionsMonitor.getSessionDestructionRatePerMinute();
51: }
52:
53: public int getSessionWritePercentage() {
54: int percentage = -1;
55: int reads = clientTxMonitor.getReadTransactionCount();
56: int writes = clientTxMonitor.getWriteTransactionCount();
57: percentage = (int) (((double) writes / (reads + writes)) * 100);
58: return percentage;
59: }
60:
61: public TabularData getTop10ClassesByObjectCreationCount()
62: throws OpenDataException {
63: TabularData tData = clientTxMonitor
64: .getObjectCreationCountByClass();
65: if (tData == null || tData.isEmpty()) {
66: return null;
67: }
68:
69: TopN topTen = new TopN(10);
70: for (Iterator iter = tData.values().iterator(); iter.hasNext();) {
71: topTen.evaluate(new ClassCreationCount((CompositeData) iter
72: .next()));
73: }
74:
75: TabularData tabularData = ClassCreationCount
76: .newTabularDataInstance();
77: for (Iterator iter = topTen.iterator(); iter.hasNext();) {
78: tabularData.put(((ClassCreationCount) iter.next())
79: .toCompositeData());
80: }
81: return tabularData;
82: }
83:
84: public void expireSession(String sessionId) {
85: sessionsMonitor.expireSession(sessionId);
86: }
87:
88: }
|