KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > management > exposed > SessionsProduct


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.management.exposed;
5
6 import com.tc.management.AbstractTerracottaMBean;
7 import com.tc.management.beans.sessions.SessionMonitorMBean;
8 import com.tc.management.beans.tx.ClientTxMonitorMBean;
9 import com.tc.management.opentypes.adapters.ClassCreationCount;
10 import com.tc.management.stats.TopN;
11
12 import java.util.Iterator JavaDoc;
13
14 import javax.management.NotCompliantMBeanException JavaDoc;
15 import javax.management.openmbean.CompositeData JavaDoc;
16 import javax.management.openmbean.OpenDataException JavaDoc;
17 import javax.management.openmbean.TabularData JavaDoc;
18
19 public class SessionsProduct extends AbstractTerracottaMBean implements SessionsProductMBean {
20
21   private final SessionMonitorMBean sessionsMonitor;
22   private final ClientTxMonitorMBean clientTxMonitor;
23
24   public SessionsProduct(final SessionMonitorMBean sessionsMonitor, final ClientTxMonitorMBean clientTxMonitor)
25       throws NotCompliantMBeanException JavaDoc {
26     super(SessionsProductMBean.class, false);
27     this.sessionsMonitor = sessionsMonitor;
28     this.clientTxMonitor = clientTxMonitor;
29   }
30   
31   public void reset() {
32     // nothing to reset
33
}
34
35   public int getRequestCount() {
36     return sessionsMonitor.getRequestCount();
37   }
38
39   public int getRequestCountPerSecond() {
40     return sessionsMonitor.getRequestRatePerSecond();
41   }
42
43   public int getSessionsCreatedPerMinute() {
44     return sessionsMonitor.getSessionCreationRatePerMinute();
45   }
46
47   public int getSessionsExpiredPerMinute() {
48     return sessionsMonitor.getSessionDestructionRatePerMinute();
49   }
50
51   public int getSessionWritePercentage() {
52     int percentage = -1;
53     int reads = clientTxMonitor.getReadTransactionCount();
54     int writes = clientTxMonitor.getWriteTransactionCount();
55     percentage = (int) (((double) writes / (reads + writes)) * 100);
56     return percentage;
57   }
58
59   public TabularData JavaDoc getTop10ClassesByObjectCreationCount() throws OpenDataException JavaDoc {
60     TabularData JavaDoc tData = clientTxMonitor.getObjectCreationCountByClass();
61     if (tData == null || tData.isEmpty()) { return null; }
62
63     TopN topTen = new TopN(10);
64     for (Iterator JavaDoc iter = tData.values().iterator(); iter.hasNext();) {
65       topTen.evaluate(new ClassCreationCount((CompositeData JavaDoc) iter.next()));
66     }
67
68     TabularData JavaDoc tabularData = ClassCreationCount.newTabularDataInstance();
69     for (Iterator JavaDoc iter = topTen.iterator(); iter.hasNext();) {
70       tabularData.put(((ClassCreationCount) iter.next()).toCompositeData());
71     }
72     return tabularData;
73   }
74
75   public void expireSession(String JavaDoc sessionId) {
76     sessionsMonitor.expireSession(sessionId);
77   }
78
79 }
80
Popular Tags