Skip to content

Commit 121b944

Browse files
author
James Taylor
committed
Added a Region Detail page (lists keys and allows removals) to the cache admin
servlet, and added a silent mode (if the silent parameter is present on the request, no output will be produced. git-svn-id: https://svn.apache.org/repos/asf/jakarta/jcs/trunk@223978 13f79535-47bb-0310-9956-ffa450edef68
1 parent 12f582d commit 121b944

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

src/java/org/apache/jcs/servlet/JCSAdminServlet.java

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,23 @@ public class JCSAdminServlet extends VelocityServlet
5454
private static final String DEFAULT_TEMPLATE_NAME =
5555
"/org/apache/jcs/servlet/JCSAdminServletDefault.vm";
5656

57+
private static final String REGION_DETAIL_TEMPLATE_NAME =
58+
"/org/apache/jcs/servlet/JCSAdminServletRegionDetail.vm";
59+
5760
// Keys for parameters
5861

5962
private static final String CACHE_NAME_PARAM = "cacheName";
6063

6164
private static final String ACTION_PARAM = "action";
6265
private static final String KEY_PARAM = "key";
66+
private static final String SILENT_PARAM = "silent";
6367

6468
// Possible values for 'action' parameter
6569

6670
private static final String CLEAR_ALL_REGIONS_ACTION = "clearAllRegions";
6771
private static final String CLEAR_REGION_ACTION = "clearRegion";
6872
private static final String REMOVE_ACTION = "remove";
73+
private static final String DETAIL_ACTION = "detail";
6974

7075
private CacheHub cacheHub = CacheHub.getInstance();
7176

@@ -75,6 +80,10 @@ protected Template handleRequest( HttpServletRequest request,
7580
Context context )
7681
throws Exception
7782
{
83+
String templateName = DEFAULT_TEMPLATE_NAME;
84+
85+
// Get cacheName for actions from request (might be null)
86+
7887
String cacheName = request.getParameter( CACHE_NAME_PARAM );
7988

8089
// If an action was provided, handle it
@@ -106,11 +115,52 @@ else if ( action.equals( REMOVE_ACTION ) )
106115
{
107116
removeItem( cacheName, keys[ i ] );
108117
}
118+
119+
templateName = REGION_DETAIL_TEMPLATE_NAME;
120+
}
121+
else if ( action.equals( DETAIL_ACTION ) )
122+
{
123+
templateName = REGION_DETAIL_TEMPLATE_NAME;
124+
}
125+
}
126+
127+
if ( request.getParameter( SILENT_PARAM ) != null )
128+
{
129+
// If silent parameter was passed, no output should be produced.
130+
131+
return null;
132+
}
133+
else
134+
{
135+
// Populate the context based on the template
136+
137+
if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
138+
{
139+
context.put( "cacheName", cacheName );
140+
context.put( "keys", getSortedKeys( cacheName ) );
141+
}
142+
else if ( templateName == DEFAULT_TEMPLATE_NAME )
143+
{
144+
context.put( "cacheInfoRecords", buildCacheInfo() );
109145
}
146+
147+
return getTemplate( templateName );
110148
}
149+
}
111150

112-
// Now populate the context
151+
private Object[] getSortedKeys( String cacheName )
152+
{
153+
Cache cache = ( Cache ) cacheHub.getCache( cacheName );
113154

155+
Object[] keys = cache.getMemoryCache().getKeyArray();
156+
157+
Arrays.sort( keys );
158+
159+
return keys;
160+
}
161+
162+
private LinkedList buildCacheInfo() throws Exception
163+
{
114164
String[] cacheNames = cacheHub.getCacheNames();
115165

116166
Arrays.sort( cacheNames );
@@ -134,9 +184,7 @@ else if ( action.equals( REMOVE_ACTION ) )
134184
cacheInfo.add( regionInfo );
135185
}
136186

137-
context.put( "cacheInfoRecords", cacheInfo );
138-
139-
return getTemplate( DEFAULT_TEMPLATE_NAME );
187+
return cacheInfo;
140188
}
141189

142190
public int getByteCount( Cache cache )

src/java/org/apache/jcs/servlet/JCSAdminServletDefault.vm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<html>
2+
3+
<head><title> JCS Admin Servlet </title></head>
4+
5+
<body>
6+
17
<h1> Cache Regions </h1>
28

39
<p>These are the regions which are currently defined in the cache. 'Items' and
@@ -20,8 +26,15 @@ which empties the entire cache.</p>
2026
<td> $record.ItemCount </td>
2127
<td> $record.ByteCount </td>
2228
<td> $record.Status </td>
23-
<td> <a href="?action=clearRegion&cacheName=${record.Name}"> Remove all </a> </td>
29+
<td>
30+
<a href="?action=detail&cacheName=${record.Name}"> Detail </a>
31+
| <a href="?action=clearRegion&cacheName=${record.Name}"> Remove all </a>
32+
</td>
2433
</tr>
2534
#end
2635

27-
</table>
36+
</table>
37+
38+
</body>
39+
40+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<html>
2+
3+
<head><title> JCS Admin Servlet Region Detail </title></head>
4+
5+
<body>
6+
7+
<h1> Keys for region: $cacheName </h1>
8+
9+
<table border="1" cellpadding="5" >
10+
<tr>
11+
<th> Key </th>
12+
</tr>
13+
14+
#foreach ( $key in $keys )
15+
<tr>
16+
<td> $key </td>
17+
<td> <a href="?action=remove&cacheName=${cacheName}&key=${key}"> Remove </a> </td>
18+
</tr>
19+
#end
20+
21+
</table>
22+
23+
</body>
24+
25+
</html>

0 commit comments

Comments
 (0)