01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.console.threads;
17:
18: import java.io.IOException;
19: import java.io.Serializable;
20: import java.net.URI;
21: import javax.portlet.ActionRequest;
22: import javax.portlet.ActionResponse;
23: import javax.portlet.PortletException;
24: import javax.portlet.RenderRequest;
25: import javax.portlet.RenderResponse;
26: import org.apache.geronimo.console.MultiPageModel;
27: import org.apache.geronimo.console.util.PortletManager;
28: import org.apache.geronimo.gbean.AbstractName;
29: import org.apache.geronimo.management.StatisticsProvider;
30: import org.apache.geronimo.management.geronimo.stats.ThreadPoolStats;
31: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
32:
33: /**
34: * A handles for the page that gives statistics about a particular thread pool.
35: *
36: * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
37: */
38: public class MonitorScreenHandler extends AbstractThreadHandler {
39: public MonitorScreenHandler() {
40: super (MONITOR_MODE, "/WEB-INF/view/threads/monitor.jsp");
41: }
42:
43: public String actionBeforeView(ActionRequest request,
44: ActionResponse response, MultiPageModel model)
45: throws PortletException, IOException {
46: response.setRenderParameter(ABSTRACT_NAME_PARAMETER, request
47: .getParameter(ABSTRACT_NAME_PARAMETER));
48: return getMode();
49: }
50:
51: public void renderView(RenderRequest request,
52: RenderResponse response, MultiPageModel model)
53: throws PortletException, IOException {
54: AbstractName name = new AbstractName(URI.create(request
55: .getParameter(ABSTRACT_NAME_PARAMETER)));
56: StatisticsProvider pool = (StatisticsProvider) PortletManager
57: .getManagedBean(request, name);
58: ThreadPoolStats stats = (ThreadPoolStats) pool.getStats();
59: String[] consumers = stats.getThreadConsumers();
60: ClientStats[] result = new ClientStats[consumers.length];
61: for (int i = 0; i < result.length; i++) {
62: result[i] = new ClientStats(consumers[i], (int) stats
63: .getCountForConsumer(consumers[i]).getCount());
64: }
65: request.setAttribute("poolName", name.getName().get(
66: NameFactory.J2EE_NAME));
67: request.setAttribute("stats", stats);
68: request.setAttribute("consumers", result);
69: }
70:
71: public String actionAfterView(ActionRequest request,
72: ActionResponse response, MultiPageModel model)
73: throws PortletException, IOException {
74: return getMode();
75: }
76:
77: public static class ClientStats implements Serializable, Comparable {
78: private final String name;
79: private final int threadCount;
80:
81: public ClientStats(String name, int threadCount) {
82: this .name = name;
83: this .threadCount = threadCount;
84: }
85:
86: public String getName() {
87: return name;
88: }
89:
90: public int getThreadCount() {
91: return threadCount;
92: }
93:
94: public int compareTo(Object o) {
95: ClientStats other = (ClientStats) o;
96: return name.compareTo(other.name);
97: }
98: }
99: }
|