01: package com.sun.portal.rproxy.monitoring;
02:
03: import com.sun.portal.monitoring.Subsystem;
04: import com.sun.portal.monitoring.statistics.*;
05: import com.sun.portal.util.GWThreadPool;
06: import com.sun.portal.util.SRAEvent;
07:
08: /**
09: * author: Noble Paul
10: * Date: Feb 9, 2005, 4:54:25 PM
11: */
12: public class ThreadPoolStatistic extends RProxyStatisticBase {
13: public static final String TASKS_IN_QUEUE = "TasksInQueue";
14: public static final String THREAD_POOL_SIZE = "Size";
15: public static final String ACTIVE_TASKS = "ActiveTasks";
16: private static CountStatisticSupport tasksInQueue = new CountStatisticSupport(
17: TASKS_IN_QUEUE);
18: private static CountStatisticSupport threadPoolSize = new CountStatisticSupport(
19: THREAD_POOL_SIZE);
20: private static CountStatisticSupport activeTasks = new CountStatisticSupport(
21: ACTIVE_TASKS);
22:
23: protected StatisticWrapper getStatistic(String name) {
24: return getCountStatistic(name);
25: }
26:
27: public ThreadPoolStatistic(Subsystem subsystem) {
28: super (subsystem);
29: }
30:
31: protected String getMbeanType() {
32: return "ThreadPool";
33: }
34:
35: protected String[] getMBeanNames() {
36: return new String[] { TASKS_IN_QUEUE, ACTIVE_TASKS,
37: THREAD_POOL_SIZE };
38: }
39:
40: protected StatisticImpl[] getStatistics() {
41: return new StatisticImpl[] { tasksInQueue, activeTasks,
42: threadPoolSize };
43: }
44:
45: public void handleEvent(SRAEvent event, Object obj) {
46: //Do nothing
47: }
48:
49: public SRAEvent[] getInterestedEvents() {
50: return new SRAEvent[] { SRAEvent.DUMMY_EVENT };
51: }
52:
53: private static class CountStatisticSupport extends
54: CountStatisticImpl {
55: String type;
56:
57: public CountStatisticSupport(String type) {
58: this .type = type;
59: }
60:
61: public long getCount() {
62: if (TASKS_IN_QUEUE == type) {
63: return GWThreadPool.getRequestsInQue();
64: }
65: if (ACTIVE_TASKS == type) {
66: return GWThreadPool.getActiveThreads();
67: }
68: if (THREAD_POOL_SIZE == type) {
69: return GWThreadPool.getSize();
70: }
71: throw new IllegalArgumentException(
72: "Not supported attribute : " + type);
73: }
74:
75: }
76: }
|