001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.console.threads; 018 019 import java.io.IOException; 020 import java.io.Serializable; 021 import java.net.URI; 022 import javax.portlet.ActionRequest; 023 import javax.portlet.ActionResponse; 024 import javax.portlet.PortletException; 025 import javax.portlet.RenderRequest; 026 import javax.portlet.RenderResponse; 027 import org.apache.geronimo.console.MultiPageModel; 028 import org.apache.geronimo.console.util.PortletManager; 029 import org.apache.geronimo.gbean.AbstractName; 030 import org.apache.geronimo.management.StatisticsProvider; 031 import org.apache.geronimo.management.geronimo.stats.ThreadPoolStats; 032 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 033 034 /** 035 * A handles for the page that gives statistics about a particular thread pool. 036 * 037 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 038 */ 039 public class MonitorScreenHandler extends AbstractThreadHandler { 040 public MonitorScreenHandler() { 041 super(MONITOR_MODE, "/WEB-INF/view/threads/monitor.jsp"); 042 } 043 044 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 045 response.setRenderParameter(ABSTRACT_NAME_PARAMETER, request.getParameter(ABSTRACT_NAME_PARAMETER)); 046 return getMode(); 047 } 048 049 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 050 AbstractName name = new AbstractName(URI.create(request.getParameter(ABSTRACT_NAME_PARAMETER))); 051 StatisticsProvider pool = (StatisticsProvider) PortletManager.getManagedBean(request, name); 052 ThreadPoolStats stats = (ThreadPoolStats) pool.getStats(); 053 String[] consumers = stats.getThreadConsumers(); 054 ClientStats[] result = new ClientStats[consumers.length]; 055 for (int i = 0; i < result.length; i++) { 056 result[i] = new ClientStats(consumers[i], (int)stats.getCountForConsumer(consumers[i]).getCount()); 057 } 058 request.setAttribute("poolName", name.getName().get(NameFactory.J2EE_NAME)); 059 request.setAttribute("stats", stats); 060 request.setAttribute("consumers", result); 061 } 062 063 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 064 return getMode(); 065 } 066 067 public static class ClientStats implements Serializable, Comparable { 068 private final String name; 069 private final int threadCount; 070 071 public ClientStats(String name, int threadCount) { 072 this.name = name; 073 this.threadCount = threadCount; 074 } 075 076 public String getName() { 077 return name; 078 } 079 080 public int getThreadCount() { 081 return threadCount; 082 } 083 084 public int compareTo(Object o) { 085 ClientStats other = (ClientStats) o; 086 return name.compareTo(other.name); 087 } 088 } 089 }