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.management.beans.sessions;
005:
006: import java.util.Iterator;
007: import java.util.LinkedList;
008:
009: import javax.management.NotCompliantMBeanException;
010:
011: import com.tc.management.AbstractTerracottaMBean;
012: import com.tc.management.stats.AggregateInteger;
013:
014: public final class SessionMonitor extends AbstractTerracottaMBean
015: implements SessionMonitorMBean {
016:
017: final AggregateInteger requestsProcessed;
018: final AggregateInteger sessionsCreated;
019: final AggregateInteger sessionsDestroyed;
020: private final LinkedList sessionsControllers;
021:
022: public SessionMonitor() throws NotCompliantMBeanException {
023: super (SessionMonitorMBean.class, false);
024: requestsProcessed = new AggregateInteger("RequestsProcessed",
025: 100);
026: sessionsCreated = new AggregateInteger("CreatedSessionCount",
027: 100);
028: sessionsDestroyed = new AggregateInteger(
029: "DestroyedSessionCount", 100);
030: sessionsControllers = new LinkedList();
031: }
032:
033: public int getRequestCount() {
034: return requestsProcessed.getN();
035: }
036:
037: public int getRequestRatePerSecond() {
038: return requestsProcessed.getSampleRate(1000);
039: }
040:
041: public int getCreatedSessionCount() {
042: return sessionsCreated.getN();
043: }
044:
045: public int getSessionCreationRatePerMinute() {
046: return sessionsCreated.getSampleRate(1000 * 60);
047: }
048:
049: public int getDestroyedSessionCount() {
050: return sessionsDestroyed.getN();
051: }
052:
053: public int getSessionDestructionRatePerMinute() {
054: return sessionsDestroyed.getSampleRate(1000 * 60);
055: }
056:
057: public synchronized void reset() {
058: requestsProcessed.reset();
059: sessionsCreated.reset();
060: sessionsDestroyed.reset();
061: synchronized (sessionsControllers) {
062: sessionsControllers.clear();
063: }
064: }
065:
066: public boolean expireSession(String sessionId) {
067: boolean sessionExpired = false;
068: synchronized (sessionsControllers) {
069: for (Iterator iter = sessionsControllers.iterator(); iter
070: .hasNext();) {
071: SessionsComptroller controller = (SessionsComptroller) iter
072: .next();
073: sessionExpired = sessionExpired
074: || controller.killSession(sessionId);
075: }
076: }
077: return sessionExpired;
078: }
079:
080: public synchronized void sessionCreated() {
081: if (isEnabled())
082: sessionsCreated.addSample(1);
083: }
084:
085: public synchronized void sessionDestroyed() {
086: if (isEnabled())
087: sessionsDestroyed.addSample(1);
088: }
089:
090: public synchronized void requestProcessed() {
091: if (isEnabled())
092: requestsProcessed.addSample(1);
093: }
094:
095: public synchronized void registerSessionsController(
096: SessionsComptroller controller) {
097: if (isEnabled()) {
098: synchronized (sessionsControllers) {
099: sessionsControllers.add(controller);
100: }
101: }
102: }
103:
104: }
|