1 17 package org.apache.geronimo.console.threads; 18 19 import java.io.IOException ; 20 import java.io.Serializable ; 21 import java.net.URI ; 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 39 public class MonitorScreenHandler extends AbstractThreadHandler { 40 public MonitorScreenHandler() { 41 super(MONITOR_MODE, "/WEB-INF/view/threads/monitor.jsp"); 42 } 43 44 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 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 { 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 [] 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 actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 64 return getMode(); 65 } 66 67 public static class ClientStats implements Serializable , Comparable { 68 private final String name; 69 private final int threadCount; 70 71 public ClientStats(String name, int threadCount) { 72 this.name = name; 73 this.threadCount = threadCount; 74 } 75 76 public String getName() { 77 return name; 78 } 79 80 public int getThreadCount() { 81 return threadCount; 82 } 83 84 public int compareTo(Object o) { 85 ClientStats other = (ClientStats) o; 86 return name.compareTo(other.name); 87 } 88 } 89 } 90 | Popular Tags |