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