KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > admin > GlobalAdminPortlet


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.portal.portlets.admin;
18
19 //Element Construction Set
20
import org.apache.ecs.html.B;
21 import org.apache.ecs.html.BR;
22 import org.apache.ecs.html.HR;
23 import org.apache.ecs.ConcreteElement;
24 import org.apache.ecs.ElementContainer;
25
26 //Jetspeed stuff
27
import org.apache.jetspeed.portal.PortletException;
28 import org.apache.jetspeed.portal.portlets.AbstractPortlet;
29 import org.apache.jetspeed.services.portletcache.GlobalCache;
30 import org.apache.jetspeed.services.Registry;
31 import org.apache.jetspeed.services.threadpool.ThreadPoolService;
32 import org.apache.jetspeed.services.threadpool.JetspeedThreadPoolService;
33 import org.apache.jetspeed.services.urlmanager.URLManager;
34 import org.apache.jetspeed.services.urlmanager.URLManagerService;
35 import org.apache.jetspeed.services.urlmanager.URLFetcher;
36
37
38 //turbine
39
import org.apache.turbine.util.RunData;
40 import org.apache.turbine.services.TurbineServices;
41
42 /**
43 Returns global information about Jetspeed.
44
45 @author <a HREF="mailto:burton@apache.org">Kevin A. Burton</a>
46 @version $Id: GlobalAdminPortlet.java,v 1.18 2004/02/23 03:26:19 jford Exp $
47 */

48 public class GlobalAdminPortlet extends AbstractPortlet {
49
50     
51     /**
52      * Return general runtime information. This include memory,
53      * thread, Registry, Resource, and caching data.
54      *
55      * @param rundata RunData object for the current request
56      * @return ConcreteElement
57      */

58     public ConcreteElement getContent( RunData rundata ) {
59
60         
61         ElementContainer ec = new ElementContainer();
62
63         this.createCategory( ec, "Memory" );
64
65         ec.addElement( this.getEntry( "Free Memory (K)",
66                                       Long.toString( Runtime.getRuntime().freeMemory()/1024 ) ) );
67         ec.addElement( this.getEntry( "Total Memory (K)",
68                                       Long.toString( Runtime.getRuntime().totalMemory()/1024 ) ) );
69         
70         JetspeedThreadPoolService service =
71             ( JetspeedThreadPoolService ) TurbineServices
72             .getInstance()
73             .getService( ThreadPoolService.SERVICE_NAME );
74         
75         this.createCategory( ec, "Thread Pool" );
76
77         ec.addElement( this.getEntry( "Available threads: ",
78                             service.getAvailableThreadCount() ) );
79         
80         ec.addElement( this.getEntry( "Total threads: ",
81                             service.getThreadCount() ) );
82
83         ec.addElement( this.getEntry( "Runnable queue length: ",
84                             service.getQueueLength() ) );
85
86         ec.addElement( this.getEntry( "Processed thread count: ",
87                             service.getThreadProcessedCount() ) );
88
89         this.createCategory( ec, "PortletRegistry" );
90
91         ec.addElement( this.getEntry( "Number of entries: ",
92                             Registry.get(Registry.PORTLET).getEntryCount() ) );
93
94         this.createCategory( ec, "Resource Manager" );
95
96         ec.addElement( this.getEntry( "Entries in Manager",
97                                       URLManager.list( URLManagerService.STATUS_ANY ).size() ) );
98         ec.addElement( this.getEntry( "Bad Entries",
99                                       URLManager.list( URLManagerService.STATUS_BAD ).size() ) );
100         ec.addElement( this.getEntry( "URLs Loading/Refreshing",
101                                       URLFetcher.getRealtimeURLs().size() ) );
102
103         this.createCategory( ec, "Global Memory Cache" );
104         ec.addElement( this.getEntry( "Objects in Cache",
105           GlobalCache.getNumberOfObjects()));
106
107         return ec;
108         
109     }
110
111     /**
112     Create a category within this portlet
113     */

114     private void createCategory( ElementContainer ec,
115                                  String JavaDoc title ) {
116
117
118         ec.addElement( new HR() );
119         ec.addElement( new B().addElement( title + ":" ) );
120         ec.addElement( new BR() );
121                                      
122     }
123
124     private ConcreteElement getEntry( String JavaDoc title,
125                                       int value ) {
126         return getEntry( title, Integer.toString( value ) );
127     }
128     
129     private ConcreteElement getEntry( String JavaDoc title,
130                                       String JavaDoc value ) {
131         
132         ElementContainer ec = new ElementContainer();
133         
134         ec.addElement( title );
135         ec.addElement( " -> " );
136         ec.addElement( value );
137         ec.addElement( new BR() );
138         
139         return ec;
140     }
141     
142     //requried info
143
/**
144      * @see AbstractPortlet#init
145      */

146     
147     public void init() throws PortletException {
148
149         this.setTitle( "Global" );
150         this.setDescription( "Global information..." );
151
152     }
153
154     /**
155      * @see AbstractPortlet#getAllowEdit
156      */

157     public boolean getAllowEdit(RunData rundata) {
158         return false;
159     }
160
161     /**
162      * @see AbstractPortlet#getAllowMaximize
163      */

164     public boolean getAllowMaximize(RunData rundata) {
165         return false;
166     }
167
168 }
169
Popular Tags