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.monitoring;
006:
007: import com.sun.portal.log.common.PortalLogger;
008: import com.sun.portal.monitoring.MonitoringException;
009: import com.sun.portal.monitoring.Subsystem;
010: import com.sun.portal.monitoring.statistics.OpenStatistic;
011: import com.sun.portal.monitoring.statistics.OpenStatisticMBeanRegistration;
012: import com.sun.portal.monitoring.statistics.RollingAvgTimeStatisticImpl;
013: import com.sun.portal.monitoring.statistics.RollingAvgTimeStatisticWrapper;
014: import com.sun.portal.monitoring.utilities.ActivityTime;
015:
016: import javax.management.MalformedObjectNameException;
017: import javax.management.ObjectName;
018: import javax.management.openmbean.CompositeType;
019: import javax.management.openmbean.OpenDataException;
020: import java.util.Map;
021: import java.util.logging.Level;
022: import java.util.logging.LogRecord;
023: import java.util.logging.Logger;
024:
025: public class ChannelCacheHitsStatisticImpl implements
026: ChannelCacheHitsStatistic {
027: private static final Logger logger = PortalLogger
028: .getLogger(ChannelCacheHitsStatisticImpl.class);
029:
030: private static LogRecord getLogRecord(Level level, String message,
031: Object[] parameters, Throwable t) {
032: LogRecord result = new LogRecord(level, message);
033: result.setLoggerName(logger.getName());
034: result.setParameters(parameters);
035: result.setThrown(t);
036: return result;
037: }
038:
039: private Subsystem subsystem;
040: private Map registry;
041:
042: public ChannelCacheHitsStatisticImpl(Subsystem subsystem) {
043: this .subsystem = subsystem;
044: this .registry = subsystem.getRegistry();
045: }
046:
047: private OpenStatisticMBeanRegistration getOpenStatisticMBeanRegistration() {
048: RollingAvgTimeStatisticWrapper rollingAvgTimeStatisticWrapper = new RollingAvgTimeStatisticWrapper();
049: rollingAvgTimeStatisticWrapper.setCompositeTypeName(getClass()
050: .getName());
051: rollingAvgTimeStatisticWrapper
052: .setResourceBundleBaseName(MonitoringSubsystem.DESKTOP_MONITORING_RESOURCE_BUNDLE_BASE_NAME);
053:
054: RollingAvgTimeStatisticImpl rollingAvgTimeStatistic = (RollingAvgTimeStatisticImpl) rollingAvgTimeStatisticWrapper
055: .getStatisticImpl();
056: try {
057: CompositeType compositeType = rollingAvgTimeStatisticWrapper
058: .getCompositeType();
059: rollingAvgTimeStatistic.setDescription(compositeType
060: .getDescription("Description"));
061: rollingAvgTimeStatistic.setName(compositeType
062: .getDescription("Name"));
063: rollingAvgTimeStatistic.setUnit(compositeType
064: .getDescription("Unit"));
065: } catch (OpenDataException e) {
066: if (logger.isLoggable(Level.SEVERE)) {
067: logger.log(getLogRecord(Level.SEVERE, "PSDT_CSPDM0001",
068: new Object[] { e.getLocalizedMessage() }, e));
069: }
070: }
071: rollingAvgTimeStatistic.setLowerBound(100);
072: rollingAvgTimeStatistic.setUpperBound(1000);
073:
074: return new OpenStatisticMBeanRegistration(registry,
075: rollingAvgTimeStatisticWrapper);
076: }
077:
078: private ObjectName getObjectName(String namingDomain,
079: String plainFQCN) throws MalformedObjectNameException {
080: return new ObjectName(namingDomain
081: + ":type=ChannelCacheHitsStatistic," + plainFQCN);
082: }
083:
084: public void mark(ActivityTime activityTime) {
085: if (!subsystem.isDisabled().booleanValue()) {
086: activityTime.mark();
087: }
088: }
089:
090: public void measure(ActivityTime activityTime, String plainFQCN) {
091: if (!subsystem.isDisabled().booleanValue()) {
092: try {
093: ObjectName objectName = getObjectName(subsystem
094: .getNamingDomain(), plainFQCN);
095: OpenStatistic openStatistic = (OpenStatistic) registry
096: .get(objectName);
097: if (openStatistic == null) {
098: openStatistic = getOpenStatisticMBeanRegistration();
099: try {
100: subsystem.registerMBean(openStatistic,
101: objectName.toString());
102: } catch (MonitoringException e) {
103: if (logger.isLoggable(Level.SEVERE)) {
104: logger
105: .log(getLogRecord(
106: Level.SEVERE,
107: "PSDT_CSPDM0001",
108: new Object[] { e
109: .getLocalizedMessage() },
110: e));
111: }
112: }
113: }
114:
115: RollingAvgTimeStatisticWrapper rollingAvgTimeStatisticWrapper = (RollingAvgTimeStatisticWrapper) openStatistic
116: .getStatisticWrapper();
117: RollingAvgTimeStatisticImpl rollingAvgTimeStatistic = (RollingAvgTimeStatisticImpl) rollingAvgTimeStatisticWrapper
118: .getStatisticImpl();
119: rollingAvgTimeStatistic.setTime(activityTime.measure());
120: } catch (MalformedObjectNameException e) {
121: if (logger.isLoggable(Level.SEVERE)) {
122: logger.log(getLogRecord(Level.SEVERE,
123: "PSDT_CSPDM0001", new Object[] { e
124: .getLocalizedMessage() }, e));
125: }
126: }
127: }
128: }
129: }
|