jtaylor 2002/07/24 08:48:01
Modified: src/java/org/apache/jcs/admin/servlet JCSAdminServlet.java
JCSAdminServletRegionDetail.vm
src/java/org/apache/jcs/auxiliary/disk PurgatoryElement.java
src/java/org/apache/jcs/engine CacheElement.java
src/java/org/apache/jcs/engine/behavior ICacheElement.java
src/java/org/apache/jcs/engine/control CompositeCache.java
Log:
- Removed creatTime from ICacheElement (not used, the one in
IElementAttributes is).
- Made CompositeCache#get actually return null when an element is not found
(duh =)
- Expanded the detail page of the cache admin servlet to include expiration
information.
Revision Changes Path
1.5 +79 -5
jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServlet.java
Index: JCSAdminServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServlet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JCSAdminServlet.java 22 Jul 2002 17:35:12 -0000 1.4
+++ JCSAdminServlet.java 24 Jul 2002 15:48:01 -0000 1.5
@@ -3,10 +3,13 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.Map;
+import java.util.Date;
+import java.text.DateFormat;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -14,6 +17,7 @@
import org.apache.jcs.engine.memory.MemoryCache;
import org.apache.jcs.engine.behavior.ICache;
import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.IElementAttributes;
import org.apache.jcs.engine.control.CompositeCacheManager;
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.velocity.Template;
@@ -137,7 +141,7 @@
if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
{
context.put( "cacheName", cacheName );
- context.put( "keys", getSortedKeys( cacheName ) );
+ context.put( "elementInfoRecords", buildElementInfo( cacheName ) );
}
else if ( templateName == DEFAULT_TEMPLATE_NAME )
{
@@ -148,15 +152,50 @@
}
}
- private Object[] getSortedKeys( String cacheName )
+ private LinkedList buildElementInfo( String cacheName ) throws Exception
{
- CompositeCache cache = ( CompositeCache ) cacheHub.getCache( cacheName );
+ CompositeCache cache =
+ ( CompositeCache ) cacheHub.getCache( cacheName );
Object[] keys = cache.getMemoryCache().getKeyArray();
Arrays.sort( keys );
- return keys;
+ LinkedList records = new LinkedList();
+
+ ICacheElement element;
+ IElementAttributes attributes;
+ CacheElementInfo elementInfo;
+
+ DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT,
+ DateFormat.SHORT );
+
+ long now = System.currentTimeMillis();
+
+ for ( int i = 0; i < keys.length; i++ )
+ {
+ element =
+ cache.getMemoryCache().getQuiet( (Serializable) keys[ i ] );
+
+ attributes = element.getElementAttributes();
+
+ elementInfo = new CacheElementInfo();
+
+ elementInfo.key = String.valueOf( keys[ i ] );
+ elementInfo.eternal = attributes.getIsEternal();
+ elementInfo.maxLifeSeconds = attributes.getMaxLifeSeconds();
+
+ elementInfo.createTime =
+ format.format( new Date( attributes.getCreateTime() ) );
+
+ elementInfo.expiresInSeconds =
+ ( now - attributes.getCreateTime()
+ - ( attributes.getMaxLifeSeconds() * 1000 ) ) / -1000;
+
+ records.add( elementInfo );
+ }
+
+ return records;
}
private LinkedList buildCacheInfo() throws Exception
@@ -252,6 +291,41 @@
: status == CacheConstants.STATUS_DISPOSED ? "DISPOSED"
: status == CacheConstants.STATUS_ERROR ? "ERROR"
: "UNKNOWN" );
+ }
+ }
+
+ /** Stores info on a cache element for the template */
+ public class CacheElementInfo
+ {
+ String key = null;
+ boolean eternal = false;
+ String createTime = null;
+ long maxLifeSeconds = -1;
+ long expiresInSeconds = -1;
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public boolean isEternal()
+ {
+ return eternal;
+ }
+
+ public String getCreateTime()
+ {
+ return createTime;
+ }
+
+ public long getMaxLifeSeconds()
+ {
+ return maxLifeSeconds;
+ }
+
+ public long getExpiresInSeconds()
+ {
+ return expiresInSeconds;
}
}
1.2 +11 -2
jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm
Index: JCSAdminServletRegionDetail.vm
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JCSAdminServletRegionDetail.vm 20 May 2002 17:05:23 -0000 1.1
+++ JCSAdminServletRegionDetail.vm 24 Jul 2002 15:48:01 -0000 1.2
@@ -9,11 +9,20 @@
<table border="1" cellpadding="5" >
<tr>
<th> Key </th>
+ <th> Eternal? </th>
+ <th> Create time </th>
+ <th> Max Life (s) </th>
+ <th> Till Expiration (s) </th>
</tr>
- #foreach ( $key in $keys )
+ #foreach ( $element in $elementInfoRecords )
+
<tr>
- <td> $key </td>
+ <td> $element.key </td>
+ <td> $element.eternal </td>
+ <td> $element.createTime </td>
+ <td> $element.maxLifeSeconds </td>
+ <td> $element.expiresInSeconds </td>
<td> <a href="?action=remove&cacheName=${cacheName}&key=${key}"> Remove
</a> </td>
</tr>
#end
1.3 +1 -9
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
Index: PurgatoryElement.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PurgatoryElement.java 10 Apr 2002 15:00:59 -0000 1.2
+++ PurgatoryElement.java 24 Jul 2002 15:48:01 -0000 1.3
@@ -159,12 +159,4 @@
{
cacheElement.setElementAttributes( attr );
}
-
- /**
- * @see ICacheElement#getCreateTime
- */
- public long getCreateTime()
- {
- return cacheElement.getCreateTime();
- }
}
1.2 +0 -14
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheElement.java
Index: CacheElement.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CacheElement.java 7 Apr 2002 16:55:26 -0000 1.1
+++ CacheElement.java 24 Jul 2002 15:48:01 -0000 1.2
@@ -22,8 +22,6 @@
public final Serializable key;
/** Description of the Field */
public final Serializable val;
- /** Description of the Field */
- public final long createTime;
/** Description of the Field */
public ElementAttributes attr;
@@ -44,7 +42,6 @@
this.cacheName = cacheName;
this.key = key;
this.val = val;
- createTime = System.currentTimeMillis();
}
@@ -113,17 +110,6 @@
public IElementAttributes getElementAttributes()
{
return this.attr;
- }
-
-
- /**
- * Gets the createTime attribute of the CacheElement object
- *
- * @return The createTime value
- */
- public long getCreateTime()
- {
- return this.createTime;
}
/** Description of the Method */
1.2 +0 -11
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheElement.java
Index: ICacheElement.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ICacheElement.java 7 Apr 2002 16:55:26 -0000 1.1
+++ ICacheElement.java 24 Jul 2002 15:48:01 -0000 1.2
@@ -53,15 +53,4 @@
* @param attr The new attributes value
*/
public void setElementAttributes( IElementAttributes attr );
-
-
- /**
- * Gets the createTime attribute of the ICacheElement object
- *
- * @return The createTime value
- */
- public long getCreateTime();
-
- // allow thread-safe operations.
- // public Object clone();
}
1.5 +12 -6
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java
Index: CompositeCache.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CompositeCache.java 22 Jul 2002 17:35:13 -0000 1.4
+++ CompositeCache.java 24 Jul 2002 15:48:01 -0000 1.5
@@ -449,6 +449,8 @@
{
ICacheElement element = null;
+ boolean found = false;
+
if ( log.isDebugEnabled() )
{
log.debug( "get: key = " + key + ", localOnly = " + localOnly );
@@ -475,6 +477,8 @@
missCountExpired++;
remove( element );
+
+ element = null;
}
else
{
@@ -487,6 +491,8 @@
hitCountRam++;
}
+
+ found = true;
}
else
{
@@ -528,7 +534,6 @@
if ( element != null )
{
-
// Item found in one of the auxiliary caches.
if ( isExpired( element ) )
@@ -542,6 +547,8 @@
missCountExpired++;
remove( element );
+
+ element = null;
}
else
{
@@ -561,6 +568,8 @@
memCache.update( element );
}
+ found = true;
+
break;
}
}
@@ -573,7 +582,7 @@
log.error( e );
}
- if ( element == null )
+ if ( ! found )
{
missCountNotFound++;
@@ -581,8 +590,6 @@
{
log.debug( cacheName + " - Miss" );
}
-
- return null;
}
return element;
@@ -679,7 +686,6 @@
*@param localOnly
*@return
*/
-
protected synchronized boolean remove( Serializable key,
boolean localOnly )
{
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>