001: package com.sun.portal.rproxy.monitoring;
002:
003: import com.sun.portal.monitoring.MonitoringException;
004: import com.sun.portal.monitoring.Subsystem;
005: import com.sun.portal.util.ThreadMonitorContext;
006: import com.sun.portal.monitoring.statistics.*;
007: import com.sun.portal.util.TaskWrapper;
008: import com.sun.portal.util.ThreadMonitorContext;
009: import com.sun.portal.util.SRAEvent;
010: import com.sun.portal.rproxy.monitoring.util.RProxyEvent;
011:
012: import javax.management.InstanceAlreadyExistsException;
013: import javax.management.MBeanRegistrationException;
014: import javax.management.MalformedObjectNameException;
015: import javax.management.NotCompliantMBeanException;
016:
017: /**
018: * author: Noble Paul
019: * Date: Feb 8, 2005, 2:21:45 PM
020: */
021: public class RProxyResponseTimeStatistic extends RProxyStatisticBase {
022: public static final String RESP_TIME = "ResponseTime";
023: public static final String PREPROCESS_TIME = "PreProcessTime";
024: public static final String POST_PROCESS_TIME = "PostProcessTime";
025: public static final String QUEUE_WAIT_TIME = "queueWaitTime";
026: private RollingAvgTimeStatisticImpl responseTime = new RollingAvgTimeStatisticImpl();
027: private RollingAvgTimeStatisticImpl preProcessTime = new RollingAvgTimeStatisticImpl();
028: private RollingAvgTimeStatisticImpl postProcessTime = new RollingAvgTimeStatisticImpl();
029: private RollingAvgTimeStatisticImpl queueTime = new RollingAvgTimeStatisticImpl();
030:
031: public RProxyResponseTimeStatistic(Subsystem subsystem) {
032: super (subsystem);
033: }
034:
035: public void updatePreprocessTime() {
036: Object task = ThreadMonitorContext.getContext().getTask();
037: if (task instanceof TaskWrapper) {
038: TaskWrapper taskWrapper = (TaskWrapper) task;
039: long currTime = System.currentTimeMillis();
040: RProxyResponseInfo info = new RProxyResponseInfo();
041: info.taskCreationTime = taskWrapper.getTaskCreationTime();
042: info.responseFetchStartTime = currTime;
043: threadLocal.set(info);
044: preProcessTime.setTime(currTime - info.taskCreationTime
045: - taskWrapper.getQueueTime());
046: queueTime.setTime(taskWrapper.getQueueTime());
047: }
048: }
049:
050: public void updatePostprocessTime() {
051: RProxyResponseInfo info = (RProxyResponseInfo) threadLocal
052: .get();
053: if (info != null) {
054: long currTime = System.currentTimeMillis();
055: postProcessTime.setTime(System.currentTimeMillis()
056: - info.responseFetchEndTime);
057: if (info.requestType == RProxyResponseInfo.IS_NOTIFICATION_TYPE) {
058: ISNotificationsStatistic.getNotificationTime().setTime(
059: currTime - info.taskCreationTime);
060: } else {
061: responseTime.setTime(currTime - info.taskCreationTime);
062: }
063: }
064: }
065:
066: protected String getMbeanType() {
067: return "RProxy";
068: }
069:
070: protected String[] getMBeanNames() {
071: return new String[] { RESP_TIME, PREPROCESS_TIME,
072: POST_PROCESS_TIME, QUEUE_WAIT_TIME };
073: }
074:
075: protected StatisticImpl[] getStatistics() {
076: return new StatisticImpl[] { responseTime, preProcessTime,
077: postProcessTime, queueTime };
078: }
079:
080: protected StatisticWrapper getStatistic(String name) {
081: return getRAStatistic(name);
082: }
083:
084: public void responseRecevied() {
085: RProxyResponseInfo info = (RProxyResponseInfo) threadLocal
086: .get();
087: if (info != null) {
088: info.responseFetchEndTime = System.currentTimeMillis();
089: }
090: }
091:
092: public void handleEvent(SRAEvent event, Object obj) {
093: if (event == RProxyEvent.TASK_ENDS) {
094: updatePostprocessTime();
095: } else if (event == RProxyEvent.REQUEST_SENT) {
096: updatePreprocessTime();
097: } else if (event == RProxyEvent.RESPONSE_RECVD) {
098: responseRecevied();
099: }
100: }
101:
102: public SRAEvent[] getInterestedEvents() {
103: return new SRAEvent[] { RProxyEvent.TASK_ENDS,
104: RProxyEvent.REQUEST_SENT, RProxyEvent.RESPONSE_RECVD };
105: }
106: }
|