001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.mfwk;
006:
007: import com.sun.mfwk.CMM_MBean;
008: import com.sun.mfwk.instrum.MfMonitoredInstrumentationObject;
009: import com.sun.mfwk.instrum.me.MfManagedElementInstrumException;
010: import com.sun.mfwk.instrum.me.settings.CMM_PSServiceSettingInstrum;
011: import com.sun.mfwk.instrum.me.statistics.CMM_PSServiceStatsInstrum;
012: import javax.management.AttributeNotFoundException;
013: import javax.management.MBeanAttributeInfo;
014: import javax.management.MBeanException;
015: import javax.management.MBeanInfo;
016: import javax.management.ReflectionException;
017:
018: public class MfwkPSUtils {
019: private static void printCmmMbeanAttributes(CMM_MBean cmmMbean)
020: throws AttributeNotFoundException, MBeanException,
021: ReflectionException {
022: MBeanInfo mbi = cmmMbean.getMBeanInfo();
023: MBeanAttributeInfo[] mai = mbi.getAttributes();
024: if (mai != null) {
025: String[] names = new String[mai.length];
026: for (int i = 0; i < names.length; i++) {
027: names[i] = mai[i].getName();
028: }
029:
030: for (int i = 0; i < names.length; i++) {
031: System.out.print(names[i] + " = ");
032: System.out.println(cmmMbean.getAttribute(names[i]));
033: }
034: }
035: }
036:
037: private static long getAttributeValue(
038: CMM_MBean cmmMbeanPSServiceStatsInstrum,
039: String attributeName,
040: CMM_PSServiceStatsInstrum psServiceStatsInstrum)
041: throws AttributeNotFoundException, ReflectionException,
042: MfManagedElementInstrumException {
043: long result = 0;
044: Long attributeValue = null;
045:
046: try {
047: attributeValue = (Long) cmmMbeanPSServiceStatsInstrum
048: .getAttribute(attributeName);
049: } catch (MBeanException e) {
050: // As we understand, MonitoringEnabled flag has been toggled (disabled -> enabled)
051: // Hack ;-)
052: // We'll be setting this one correctly just after. psServiceStatsInstrum.setResidentTimeRollingAvg(0); // set to bad value, calculate appropriately
053: // We'll be setting this one correctly just after. psServiceStatsInstrum.setServiceTimeRollingAvg(0); // set to bad value, calculate appropriately
054: psServiceStatsInstrum.setInRequestsInBytes(0); // play safe, we really don't care about this attribute
055: psServiceStatsInstrum.setOutRequestsInBytes(0); // play safe, we really don't care about this attribute
056: psServiceStatsInstrum.setSampleInterval(0); // play safe, we really don't care about this attribute
057: }
058:
059: if (attributeValue != null) {
060: result = attributeValue.longValue();
061: }
062:
063: return result;
064: }
065:
066: public static void updateRollingAverageTimes(
067: CMM_PSServiceSettingInstrum psServiceSettingInstrum,
068: CMM_PSServiceStatsInstrum psServiceStatsInstrum)
069: throws AttributeNotFoundException, MBeanException,
070: MfManagedElementInstrumException, ReflectionException {
071: MfMonitoredInstrumentationObject mfmioPSServiceSettingInstrum = psServiceSettingInstrum
072: .getExporterMBean();
073: CMM_MBean cmmMbeanPSServiceSettingInstrum = (CMM_MBean) mfmioPSServiceSettingInstrum;
074: // printCmmMbeanAttributes(cmmMbeanPSServiceSettingInstrum);
075:
076: long residentTimeRollingAvgLowerBound;
077: long residentTimeRollingAvgUpperBound;
078: long serviceTimeRollingAvgLowerBound;
079: long serviceTimeRollingAvgUpperBound;
080: residentTimeRollingAvgLowerBound = ((Integer) cmmMbeanPSServiceSettingInstrum
081: .getAttribute("ResidentTimeRollingAvgLowerBound"))
082: .longValue();
083: residentTimeRollingAvgUpperBound = ((Integer) cmmMbeanPSServiceSettingInstrum
084: .getAttribute("ResidentTimeRollingAvgUpperBound"))
085: .longValue();
086: serviceTimeRollingAvgLowerBound = ((Integer) cmmMbeanPSServiceSettingInstrum
087: .getAttribute("ServiceTimeRollingAvgLowerBound"))
088: .longValue();
089: serviceTimeRollingAvgUpperBound = ((Integer) cmmMbeanPSServiceSettingInstrum
090: .getAttribute("ServiceTimeRollingAvgUpperBound"))
091: .longValue();
092:
093: MfMonitoredInstrumentationObject mfmioPSServiceStatsInstrum = psServiceStatsInstrum
094: .getExporterMBean();
095: CMM_MBean cmmMbeanPSServiceStatsInstrum = (CMM_MBean) mfmioPSServiceStatsInstrum;
096: // printCmmMbeanAttributes(cmmMbeanPSServiceStatsInstrum);
097:
098: long outRequests;
099: long residentTime;
100: long residentTimeRollingAvg = 0;
101: long serviceTime;
102: long serviceTimeRollingAvg = 0;
103: outRequests = ((Long) cmmMbeanPSServiceStatsInstrum
104: .getAttribute("OutRequests")).longValue();
105: residentTime = ((Long) cmmMbeanPSServiceStatsInstrum
106: .getAttribute("ResidentTime")).longValue();
107: residentTimeRollingAvg = getAttributeValue(
108: cmmMbeanPSServiceStatsInstrum,
109: "ResidentTimeRollingAvg", psServiceStatsInstrum);
110: serviceTime = ((Long) cmmMbeanPSServiceStatsInstrum
111: .getAttribute("ServiceTime")).longValue();
112: serviceTimeRollingAvg = getAttributeValue(
113: cmmMbeanPSServiceStatsInstrum, "ServiceTimeRollingAvg",
114: psServiceStatsInstrum);
115:
116: if (outRequests == 1) {
117: psServiceStatsInstrum
118: .setResidentTimeRollingAvg(residentTime);
119: } else {
120: long span;
121: span = (outRequests < residentTimeRollingAvgLowerBound) ? residentTimeRollingAvgLowerBound
122: : outRequests;
123: span = (outRequests > residentTimeRollingAvgUpperBound) ? residentTimeRollingAvgUpperBound
124: : outRequests;
125: residentTimeRollingAvg = (residentTimeRollingAvg * span + residentTime)
126: / (span + 1);
127: psServiceStatsInstrum
128: .setResidentTimeRollingAvg(residentTimeRollingAvg);
129: }
130:
131: if (outRequests == 1) {
132: psServiceStatsInstrum.setServiceTimeRollingAvg(serviceTime);
133: } else {
134: long span;
135: span = (outRequests < serviceTimeRollingAvgLowerBound) ? serviceTimeRollingAvgLowerBound
136: : outRequests;
137: span = (outRequests > serviceTimeRollingAvgUpperBound) ? serviceTimeRollingAvgUpperBound
138: : outRequests;
139: serviceTimeRollingAvg = (serviceTimeRollingAvg * span + serviceTime)
140: / (span + 1);
141: psServiceStatsInstrum
142: .setServiceTimeRollingAvg(serviceTimeRollingAvg);
143: }
144: }
145: }
|