KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > threads > MonitorScreenHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17 package org.apache.geronimo.console.threads;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Serializable JavaDoc;
21 import java.net.URI JavaDoc;
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletException;
25 import javax.portlet.RenderRequest;
26 import javax.portlet.RenderResponse;
27 import org.apache.geronimo.console.MultiPageModel;
28 import org.apache.geronimo.console.util.PortletManager;
29 import org.apache.geronimo.gbean.AbstractName;
30 import org.apache.geronimo.management.StatisticsProvider;
31 import org.apache.geronimo.management.geronimo.stats.ThreadPoolStats;
32 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
33
34 /**
35  * A handles for the page that gives statistics about a particular thread pool.
36  *
37  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
38  */

39 public class MonitorScreenHandler extends AbstractThreadHandler {
40     public MonitorScreenHandler() {
41         super(MONITOR_MODE, "/WEB-INF/view/threads/monitor.jsp");
42     }
43
44     public String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
45         response.setRenderParameter(ABSTRACT_NAME_PARAMETER, request.getParameter(ABSTRACT_NAME_PARAMETER));
46         return getMode();
47     }
48
49     public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
50         AbstractName name = new AbstractName(URI.create(request.getParameter(ABSTRACT_NAME_PARAMETER)));
51         StatisticsProvider pool = (StatisticsProvider) PortletManager.getManagedBean(request, name);
52         ThreadPoolStats stats = (ThreadPoolStats) pool.getStats();
53         String JavaDoc[] consumers = stats.getThreadConsumers();
54         ClientStats[] result = new ClientStats[consumers.length];
55         for (int i = 0; i < result.length; i++) {
56             result[i] = new ClientStats(consumers[i], (int)stats.getCountForConsumer(consumers[i]).getCount());
57         }
58         request.setAttribute("poolName", name.getName().get(NameFactory.J2EE_NAME));
59         request.setAttribute("stats", stats);
60         request.setAttribute("consumers", result);
61     }
62
63     public String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc {
64         return getMode();
65     }
66
67     public static class ClientStats implements Serializable JavaDoc, Comparable JavaDoc {
68         private final String JavaDoc name;
69         private final int threadCount;
70
71         public ClientStats(String JavaDoc name, int threadCount) {
72             this.name = name;
73             this.threadCount = threadCount;
74         }
75
76         public String JavaDoc getName() {
77             return name;
78         }
79
80         public int getThreadCount() {
81             return threadCount;
82         }
83
84         public int compareTo(Object JavaDoc o) {
85             ClientStats other = (ClientStats) o;
86             return name.compareTo(other.name);
87         }
88     }
89 }
90
Popular Tags