1 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 ; 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 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 { 26 super(SessionsProductMBean.class, false); 27 this.sessionsMonitor = sessionsMonitor; 28 this.clientTxMonitor = clientTxMonitor; 29 } 30 31 public void reset() { 32 } 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 getTop10ClassesByObjectCreationCount() throws OpenDataException { 60 TabularData tData = clientTxMonitor.getObjectCreationCountByClass(); 61 if (tData == null || tData.isEmpty()) { return null; } 62 63 TopN topTen = new TopN(10); 64 for (Iterator iter = tData.values().iterator(); iter.hasNext();) { 65 topTen.evaluate(new ClassCreationCount((CompositeData ) iter.next())); 66 } 67 68 TabularData tabularData = ClassCreationCount.newTabularDataInstance(); 69 for (Iterator iter = topTen.iterator(); iter.hasNext();) { 70 tabularData.put(((ClassCreationCount) iter.next()).toCompositeData()); 71 } 72 return tabularData; 73 } 74 75 public void expireSession(String sessionId) { 76 sessionsMonitor.expireSession(sessionId); 77 } 78 79 } 80 | Popular Tags |