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.util.Arrays; 022 import javax.portlet.ActionRequest; 023 import javax.portlet.ActionResponse; 024 import javax.portlet.PortletException; 025 import javax.portlet.PortletRequest; 026 import javax.portlet.RenderRequest; 027 import javax.portlet.RenderResponse; 028 import org.apache.geronimo.console.MultiPageModel; 029 import org.apache.geronimo.console.util.PortletManager; 030 import org.apache.geronimo.gbean.AbstractName; 031 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 032 import org.apache.geronimo.system.threads.ThreadPool; 033 034 /** 035 * A handles for the front page that lists available thread pools. 036 * 037 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 038 */ 039 public class ListScreenHandler extends AbstractThreadHandler { 040 public ListScreenHandler() { 041 super(LIST_MODE, "/WEB-INF/view/threads/list.jsp"); 042 } 043 044 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 045 return getMode(); 046 } 047 048 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 049 populateExistingList(request); 050 } 051 052 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 053 return getMode(); 054 } 055 056 private void populateExistingList(PortletRequest renderRequest) { 057 ThreadPool[] pools = PortletManager.getCurrentServer(renderRequest).getThreadPools(); 058 ThreadPoolSummary[] result = new ThreadPoolSummary[pools.length]; 059 for (int i = 0; i < pools.length; i++) { 060 result[i] = new ThreadPoolSummary(PortletManager.getNameFor(renderRequest, pools[i]), pools[i].getPoolSize()); 061 } 062 Arrays.sort(result); 063 renderRequest.setAttribute("pools", result); 064 } 065 066 public static class ThreadPoolSummary implements Serializable, Comparable { 067 private static final long serialVersionUID = -7515061254194067140L; 068 private final String abstractName; 069 private final int maxSize; 070 private final String name; 071 072 public ThreadPoolSummary(AbstractName abstractName, int maxSize) { 073 this.abstractName = abstractName.toString(); 074 name = (String) abstractName.getName().get(NameFactory.J2EE_NAME); 075 this.maxSize = maxSize; 076 } 077 078 public String getAbstractName() { 079 return abstractName; 080 } 081 082 public int getPoolSize() { 083 return maxSize; 084 } 085 086 public String getName() { 087 return name; 088 } 089 090 public int compareTo(Object o) { 091 ThreadPoolSummary other = (ThreadPoolSummary) o; 092 return name.compareTo(other.name); 093 } 094 } 095 }