| 1 |
<%-- |
| 2 |
Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
or more contributor license agreements. See the NOTICE file |
| 4 |
distributed with this work for additional information |
| 5 |
regarding copyright ownership. The ASF licenses this file |
| 6 |
to you under the Apache License, Version 2.0 (the |
| 7 |
"License"); you may not use this file except in compliance |
| 8 |
with the License. You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, |
| 13 |
software distributed under the License is distributed on an |
| 14 |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
KIND, either express or implied. See the License for the |
| 16 |
specific language governing permissions and limitations |
| 17 |
under the License. |
| 18 |
--%> |
| 19 |
<!DOCTYPE html> |
| 20 |
<%@page import="java.util.List"%> |
| 21 |
<%@page import="org.apache.commons.jcs3.JCS"%> |
| 22 |
<%@page import="org.apache.commons.jcs3.access.CacheAccess" %> |
| 23 |
<%@page import="org.apache.commons.jcs3.admin.CacheElementInfo" %> |
| 24 |
<%@page import="org.apache.commons.jcs3.admin.CacheRegionInfo" %> |
| 25 |
<%@page import="org.apache.commons.jcs3.engine.behavior.ICacheElement" %> |
| 26 |
|
| 27 |
<jsp:useBean id="jcsBean" scope="request" class="org.apache.commons.jcs3.admin.JCSAdminBean" /> |
| 28 |
|
| 29 |
<html lang="en"> |
| 30 |
<head> |
| 31 |
<script> |
| 32 |
function decision(message, url) |
| 33 |
{ |
| 34 |
if(confirm(message)) |
| 35 |
{ |
| 36 |
location.href = url; |
| 37 |
} |
| 38 |
} |
| 39 |
</script> |
| 40 |
<style> |
| 41 |
body { |
| 42 |
font-family: Arial, Helvetica, sans-serif; |
| 43 |
font-size: small; |
| 44 |
} |
| 45 |
|
| 46 |
h1 { |
| 47 |
font-size: large; |
| 48 |
color: navy; |
| 49 |
} |
| 50 |
|
| 51 |
h2 { |
| 52 |
font-size: medium; |
| 53 |
color: navy; |
| 54 |
} |
| 55 |
|
| 56 |
a { |
| 57 |
color: navy; |
| 58 |
font-weight: 700; |
| 59 |
text-decoration: none; |
| 60 |
} |
| 61 |
|
| 62 |
/* Change color on hover */ |
| 63 |
a:hover { |
| 64 |
background-color: navy; |
| 65 |
color: white; |
| 66 |
} |
| 67 |
|
| 68 |
pre { |
| 69 |
font-size: medium; |
| 70 |
} |
| 71 |
|
| 72 |
table, th, td { |
| 73 |
border: thin solid #a0a0a0; |
| 74 |
font-size: small; |
| 75 |
} |
| 76 |
|
| 77 |
table { |
| 78 |
border-collapse: collapse; |
| 79 |
} |
| 80 |
|
| 81 |
tr:nth-child(odd) { |
| 82 |
background: #EEE; |
| 83 |
} |
| 84 |
|
| 85 |
th, td { |
| 86 |
padding: 4pt; |
| 87 |
} |
| 88 |
|
| 89 |
th { |
| 90 |
background-color: navy; |
| 91 |
color: white; |
| 92 |
font-weight: 700; |
| 93 |
text-align: left; |
| 94 |
} |
| 95 |
</style> |
| 96 |
<title>JCS Administration</title> |
| 97 |
</head> |
| 98 |
<body> |
| 99 |
<% |
| 100 |
final String CACHE_NAME_PARAM = "cacheName"; |
| 101 |
final String ACTION_PARAM = "action"; |
| 102 |
final String CLEAR_ALL_REGIONS_ACTION = "clearAllRegions"; |
| 103 |
final String CLEAR_REGION_ACTION = "clearRegion"; |
| 104 |
final String REMOVE_ACTION = "remove"; |
| 105 |
final String DETAIL_ACTION = "detail"; |
| 106 |
final String REGION_SUMMARY_ACTION = "regionSummary"; |
| 107 |
final String ITEM_ACTION = "item"; |
| 108 |
final String KEY_PARAM = "key"; |
| 109 |
|
| 110 |
final String DEFAULT_TEMPLATE_NAME = "DEFAULT"; |
| 111 |
final String REGION_DETAIL_TEMPLATE_NAME = "DETAIL"; |
| 112 |
final String ITEM_TEMPLATE_NAME = "ITEM"; |
| 113 |
final String REGION_SUMMARY_TEMPLATE_NAME = "SUMMARY"; |
| 114 |
|
| 115 |
String templateName = DEFAULT_TEMPLATE_NAME; |
| 116 |
|
| 117 |
// Get cacheName for actions from request (might be null) |
| 118 |
String cacheName = request.getParameter(CACHE_NAME_PARAM); |
| 119 |
|
| 120 |
if (cacheName != null) |
| 121 |
{ |
| 122 |
cacheName = cacheName.trim(); |
| 123 |
} |
| 124 |
|
| 125 |
// If an action was provided, handle it |
| 126 |
String action = request.getParameter(ACTION_PARAM); |
| 127 |
|
| 128 |
if (action == null) |
| 129 |
{ |
| 130 |
// do nothing |
| 131 |
} |
| 132 |
else if (action.equals(CLEAR_ALL_REGIONS_ACTION)) |
| 133 |
{ |
| 134 |
jcsBean.clearAllRegions(); |
| 135 |
} |
| 136 |
else if (action.equals(CLEAR_REGION_ACTION) && cacheName != null) |
| 137 |
{ |
| 138 |
jcsBean.clearRegion(cacheName); |
| 139 |
} |
| 140 |
else if (action.equals(REMOVE_ACTION)) |
| 141 |
{ |
| 142 |
for (String key : request.getParameterValues(KEY_PARAM)) |
| 143 |
{ |
| 144 |
jcsBean.removeItem(cacheName, key); |
| 145 |
} |
| 146 |
|
| 147 |
templateName = REGION_DETAIL_TEMPLATE_NAME; |
| 148 |
} |
| 149 |
else if (action.equals(DETAIL_ACTION)) |
| 150 |
{ |
| 151 |
templateName = REGION_DETAIL_TEMPLATE_NAME; |
| 152 |
} |
| 153 |
else if (action.equals(ITEM_ACTION)) |
| 154 |
{ |
| 155 |
templateName = ITEM_TEMPLATE_NAME; |
| 156 |
} |
| 157 |
else if (action.equals(REGION_SUMMARY_ACTION)) |
| 158 |
{ |
| 159 |
templateName = REGION_SUMMARY_TEMPLATE_NAME; |
| 160 |
} |
| 161 |
|
| 162 |
/////////////////////////////////////////////////////////////////////////////////// |
| 163 |
//handle display |
| 164 |
|
| 165 |
if (templateName == ITEM_TEMPLATE_NAME) |
| 166 |
{ |
| 167 |
String key = request.getParameter(KEY_PARAM); |
| 168 |
|
| 169 |
if (key != null) |
| 170 |
{ |
| 171 |
key = key.trim(); |
| 172 |
} |
| 173 |
|
| 174 |
CacheAccess<Object, Object> cache = JCS.getInstance(cacheName); |
| 175 |
ICacheElement<?, ?> element = cache.getCacheElement(key); |
| 176 |
%> |
| 177 |
<h1>Item for key [<%=key%>] in region [<%=cacheName%>]</h1> |
| 178 |
<p><a href="?action=detail&cacheName=<%=cacheName%>">Region Detail</a> |
| 179 |
| <a href="?">All Regions</a></p> |
| 180 |
<pre> |
| 181 |
<%=element%> |
| 182 |
</pre> |
| 183 |
<% |
| 184 |
} |
| 185 |
else if (templateName == REGION_SUMMARY_TEMPLATE_NAME) |
| 186 |
{ |
| 187 |
%> |
| 188 |
<h1>Summary for region [<%=cacheName%>]</h1> |
| 189 |
<p><a href="?">All Regions</a></p> |
| 190 |
<% |
| 191 |
CacheAccess<?, ?> cache = JCS.getInstance(cacheName); |
| 192 |
String stats = cache.getStats(); |
| 193 |
%> |
| 194 |
<h2>Statistics for region [<%=cacheName%>]</h2> |
| 195 |
<pre> |
| 196 |
<%=stats%> |
| 197 |
</pre> |
| 198 |
<% |
| 199 |
} |
| 200 |
else if (templateName == REGION_DETAIL_TEMPLATE_NAME) |
| 201 |
{ |
| 202 |
%> |
| 203 |
<h1>Detail for region [<%=cacheName%>]</h1> |
| 204 |
<p><a href="?">All Regions</a></p> |
| 205 |
<table> |
| 206 |
<tr> |
| 207 |
<th>Key</th> |
| 208 |
<th>Eternal?</th> |
| 209 |
<th>Create time</th> |
| 210 |
<th>Max Life (s)</th> |
| 211 |
<th>Till Expiration (s)</th> |
| 212 |
</tr> |
| 213 |
<% |
| 214 |
for (CacheElementInfo element : jcsBean.buildElementInfo(cacheName)) |
| 215 |
{ |
| 216 |
%> |
| 217 |
<tr> |
| 218 |
<td><%=element.getKey()%></td> |
| 219 |
<td><%=element.isEternal()%></td> |
| 220 |
<td><%=element.getCreateTime()%></td> |
| 221 |
<td><%=element.getMaxLifeSeconds()%></td> |
| 222 |
<td><%=element.getExpiresInSeconds()%></td> |
| 223 |
<td> |
| 224 |
<a href="?action=item&cacheName=<%=cacheName%>&key=<%=element.getKey()%>"> View </a> |
| 225 |
| <a href="?action=remove&cacheName=<%=cacheName%>&key=<%=element.getKey()%>"> Remove </a> |
| 226 |
</td> |
| 227 |
</tr> |
| 228 |
<% |
| 229 |
} |
| 230 |
|
| 231 |
CacheAccess<?, ?> cache = JCS.getInstance(cacheName); |
| 232 |
String stats = cache.getStats(); |
| 233 |
%> |
| 234 |
</table> |
| 235 |
<h2>Statistics for region [<%=cacheName%>]</h2> |
| 236 |
<pre> |
| 237 |
<%=stats%> |
| 238 |
</pre> |
| 239 |
<% |
| 240 |
} |
| 241 |
else |
| 242 |
{ |
| 243 |
%> |
| 244 |
<h1>Cache Regions</h1> |
| 245 |
<p> |
| 246 |
These are the regions which are currently defined in the cache. 'Items' and |
| 247 |
'Bytes' refer to the elements currently in memory (not spooled). You can clear |
| 248 |
all items for a region by selecting 'Clear' next to the desired region |
| 249 |
below. You can also <a href="javascript:decision('Clicking OK will clear all the data from all regions!','?action=clearAllRegions')">Clear all regions</a> |
| 250 |
which empties the entire cache. |
| 251 |
</p> |
| 252 |
<form action="?"><p> |
| 253 |
<input type="hidden" name="action" value="item" /> |
| 254 |
Retrieve <input type="text" name="key" autofocus="autofocus" placeholder="(key)" /> |
| 255 |
from region <select name="cacheName"> |
| 256 |
<% |
| 257 |
List<CacheRegionInfo> records = jcsBean.buildCacheInfo(); |
| 258 |
|
| 259 |
for (CacheRegionInfo record : records) |
| 260 |
{ |
| 261 |
%> |
| 262 |
<option value="<%=record.getCacheName()%>"><%=record.getCacheName()%></option> |
| 263 |
<% |
| 264 |
} |
| 265 |
%> |
| 266 |
</select> |
| 267 |
<input type="submit" value="Retrieve" /> |
| 268 |
</p></form> |
| 269 |
<table> |
| 270 |
<tr> |
| 271 |
<th>Cache Name</th> |
| 272 |
<th>Items</th> |
| 273 |
<th>Bytes</th> |
| 274 |
<th>Status</th> |
| 275 |
<th>Memory Hits</th> |
| 276 |
<th>Aux Hits</th> |
| 277 |
<th>Not Found Misses</th> |
| 278 |
<th>Expired Misses</th> |
| 279 |
<th>Actions</th> |
| 280 |
</tr> |
| 281 |
<% |
| 282 |
for (CacheRegionInfo record : records) |
| 283 |
{ |
| 284 |
%> |
| 285 |
<tr> |
| 286 |
<td><%=record.getCacheName()%></td> |
| 287 |
<td><%=record.getCacheSize()%></td> |
| 288 |
<td><%=record.getByteCount()%></td> |
| 289 |
<td><%=record.getCacheStatus()%></td> |
| 290 |
<td><%=record.getHitCountRam()%></td> |
| 291 |
<td><%=record.getHitCountAux()%></td> |
| 292 |
<td><%=record.getMissCountNotFound()%></td> |
| 293 |
<td><%=record.getMissCountExpired()%></td> |
| 294 |
<td> |
| 295 |
<a href="?action=regionSummary&cacheName=<%=record.getCacheName()%>">Summary</a> |
| 296 |
| <a href="?action=detail&cacheName=<%=record.getCacheName()%>">Detail</a> |
| 297 |
| <a href="javascript:decision('Clicking OK will remove all the data from the region [<%=record.getCacheName()%>]!','?action=clearRegion&cacheName=<%=record.getCacheName()%>')">Clear</a> |
| 298 |
</td> |
| 299 |
</tr> |
| 300 |
<% |
| 301 |
} |
| 302 |
%> |
| 303 |
</table> |
| 304 |
<% |
| 305 |
} |
| 306 |
%> |
| 307 |
</body> |
| 308 |
</html> |