001: package com.sun.portal.rproxy.monitoring;
002:
003: import com.sun.portal.monitoring.statistics.*;
004: import com.sun.portal.monitoring.MonitoringException;
005: import com.sun.portal.monitoring.Subsystem;
006: import com.sun.portal.util.SRAEventListener;
007:
008: import javax.management.*;
009: import java.util.Arrays;
010: import java.util.Map;
011: import java.util.HashMap;
012:
013: import javax.management.openmbean.OpenDataException;
014: import javax.management.openmbean.CompositeType;
015:
016: /**
017: * author: Noble Paul
018: * Date: Feb 9, 2005, 10:35:25 AM
019: */
020: public abstract class RProxyStatisticBase implements SRAEventListener {
021: protected Subsystem subsystem;
022: protected Map objNameVsStatistic = new HashMap();
023: static ThreadLocal threadLocal = new ThreadLocal();
024:
025: protected RollingAvgTimeStatisticWrapper getRAStatistic(
026: String attributeName) {
027: RollingAvgTimeStatisticWrapper ratsw = new RollingAvgTimeStatisticWrapper();
028: ratsw
029: .setCompositeTypeName(getClass().getName()
030: + attributeName);
031: ratsw.setResourceBundleBaseName(getMbeanType() + "Statistic");
032: return ratsw;
033: }
034:
035: protected RProxyStatisticBase(Subsystem subsystem) {
036: this .subsystem = subsystem;
037: }
038:
039: protected ObjectName getObjectName(String attributeName)
040: throws MalformedObjectNameException {
041: return new ObjectName(subsystem.getNamingDomain() + ":type="
042: + getMbeanType() + attributeName);
043: }
044:
045: protected abstract String getMbeanType();
046:
047: protected CountStatisticWrapper getCountStatistic(
048: String attributeName) {
049: CountStatisticWrapper csw = new CountStatisticWrapper();
050: csw.setCompositeTypeName(getClass().getName() + attributeName);
051: csw.setResourceBundleBaseName(getMbeanType());
052: return csw;
053: }
054:
055: protected RangeStatisticWrapper getRangeStatistic(
056: String attributeName) {
057: RangeStatisticWrapper rsw = new RangeStatisticWrapper();
058: rsw.setCompositeTypeName(getClass().getName() + attributeName);
059: rsw.setResourceBundleBaseName(getMbeanType());
060: return rsw;
061: }
062:
063: protected void createMBean(String name, StatisticImpl statistic)
064: throws InstanceAlreadyExistsException,
065: MBeanRegistrationException, NotCompliantMBeanException,
066: MonitoringException, MalformedObjectNameException {
067: StatisticWrapper statisticWrapper = getStatistic(name);
068: statisticWrapper.setStatisticImpl(statistic);
069: try {
070: CompositeType compositeType = statisticWrapper
071: .getCompositeType();
072: statisticWrapper.getStatisticImpl().setDescription(
073: compositeType.getDescription("Description"));
074: statisticWrapper.getStatisticImpl().setName(
075: compositeType.getDescription("Name"));
076: statisticWrapper.getStatisticImpl().setUnit(
077: compositeType.getDescription("Unit"));
078: } catch (OpenDataException e) {
079: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
080: }
081: statistic.reset();
082: ObjectName objName = getObjectName(name);
083: subsystem.registerMBean(new OpenStatistic(statisticWrapper),
084: objName.toString());
085: subsystem.setImmortalMBeanObjectNames(Arrays
086: .asList(new ObjectName[] { objName }));
087: }
088:
089: protected abstract String[] getMBeanNames();
090:
091: protected abstract StatisticImpl[] getStatistics();
092:
093: protected abstract StatisticWrapper getStatistic(String name);
094:
095: public RProxyStatisticBase initMBeans() throws MonitoringException,
096: MalformedObjectNameException, NotCompliantMBeanException,
097: MBeanRegistrationException, InstanceAlreadyExistsException {
098: String[] mbeanNames = getMBeanNames();
099: StatisticImpl[] statistics = getStatistics();
100: for (int i = 0; i < mbeanNames.length; i++) {
101: createMBean(mbeanNames[i], statistics[i]);
102: }
103: return this ;
104: }
105:
106: public static class RProxyResponseInfo {
107: public static final int IS_NOTIFICATION_TYPE = 1;
108: public long responseFetchStartTime = -1;
109: public long responseFetchEndTime = -1;
110: public long taskCreationTime = -1;
111: public int requestType = 0;
112: }
113:
114: public static boolean isMonitoringDisabled() {
115: return MonitoringSubsystem.isMonitoringDisabled();
116: }
117: }
|