01: package com.sun.portal.rproxy.monitoring;
02:
03: import com.sun.portal.monitoring.Subsystem;
04: import com.sun.portal.monitoring.utilities.ActivityTime;
05: import com.sun.portal.monitoring.statistics.*;
06: import com.sun.portal.rproxy.configservlet.client.UserProfileGatewayCache;
07: import com.sun.portal.rproxy.monitoring.util.RProxyEvent;
08: import com.sun.portal.util.SRAEvent;
09:
10: /**
11: * author: Noble Paul
12: * Date: Feb 14, 2005, 5:20:16 PM
13: */
14: public class UserProfileCacheStatistic extends RProxyStatisticBase {
15: public static final String CACHE_UTILIZATION = "CacheUtilization";
16: public static final String CACHE_HIT_RATE = "CacheHitRate";
17: public static final String CACHE_RESPONSE_TIME = "ResponseTime";
18: private static RangeStatisticImpl cacheUtilization = new RangeStatisticImpl() {
19: public long getLowWaterMark() {
20: return 0;
21: }
22:
23: public long getHighWaterMark() {
24: return UserProfileGatewayCache.getMaxCacheSize();
25: }
26:
27: public long getCurrent() {
28: return UserProfileGatewayCache.getNumCacheEntries();
29: }
30: };
31: private static HitRate hitrate = new HitRate();
32: private static RollingAvgTimeStatisticImpl respTime = new RollingAvgTimeStatisticImpl();
33: private static ActivityTime activityTime = new ActivityTime();
34:
35: public UserProfileCacheStatistic(Subsystem subsystem) {
36: super (subsystem);
37: }
38:
39: protected String getMbeanType() {
40: return "UserProfile";
41: }
42:
43: protected String[] getMBeanNames() {
44: return new String[] { CACHE_UTILIZATION, CACHE_HIT_RATE,
45: CACHE_RESPONSE_TIME };
46: }
47:
48: protected StatisticImpl[] getStatistics() {
49: return new StatisticImpl[] { cacheUtilization, hitrate,
50: respTime };
51: }
52:
53: protected StatisticWrapper getStatistic(String name) {
54: if (CACHE_UTILIZATION.equals(name)) {
55: return getRangeStatistic(name);
56: }
57: if (CACHE_HIT_RATE.equals(name)) {
58: return getCountStatistic(name);
59: }
60: if (CACHE_RESPONSE_TIME.equals(name)) {
61: return getRAStatistic(name);
62: } else
63: throw new RuntimeException("No statistic : " + name);
64: }
65:
66: public void markFetchStart() {
67: activityTime.mark();
68:
69: }
70:
71: public void markFetchEnd() {
72: respTime.setTime(activityTime.measure());
73: }
74:
75: public void handleEvent(SRAEvent event, Object obj) {
76: if (event == RProxyEvent.GET_USER_PROFILE_START) {
77: markFetchStart();
78: } else if (event == RProxyEvent.GET_USER_PROFILE_END) {
79: markFetchEnd();
80: }
81: }
82:
83: public SRAEvent[] getInterestedEvents() {
84: return new SRAEvent[] { RProxyEvent.GET_USER_PROFILE_START,
85: RProxyEvent.GET_USER_PROFILE_END, };
86: }
87:
88: private static class HitRate extends CountStatisticImpl {
89: public long getCount() {
90: return UserProfileGatewayCache.getCacheHitRate();
91: }
92: }
93: }
|