jtaylor     02/05/20 05:35:49

  Modified:    src/java/org/apache/jcs/servlet JCSAdminServlet.java
                        JCSAdminServletDefault.vm
  Added:       src/java/org/apache/jcs/servlet
                        JCSAdminServletRegionDetail.vm
  Log:
  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.
  
  Revision  Changes    Path
  1.2       +53 -5     
jakarta-turbine-jcs/src/java/org/apache/jcs/servlet/JCSAdminServlet.java
  
  Index: JCSAdminServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/servlet/JCSAdminServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JCSAdminServlet.java      18 May 2002 02:11:31 -0000      1.1
  +++ JCSAdminServlet.java      20 May 2002 12:35:49 -0000      1.2
  @@ -47,25 +47,30 @@
    *        precedence.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Taylor</a>
  - * @version $Id: JCSAdminServlet.java,v 1.1 2002/05/18 02:11:31 jtaylor Exp $
  + * @version $Id: JCSAdminServlet.java,v 1.2 2002/05/20 12:35:49 jtaylor Exp $
    */
   public class JCSAdminServlet extends VelocityServlet
   {
       private static final String DEFAULT_TEMPLATE_NAME =
           "/org/apache/jcs/servlet/JCSAdminServletDefault.vm";
   
  +    private static final String REGION_DETAIL_TEMPLATE_NAME =
  +        "/org/apache/jcs/servlet/JCSAdminServletRegionDetail.vm";
  +
       // Keys for parameters
   
       private static final String CACHE_NAME_PARAM = "cacheName";
   
       private static final String ACTION_PARAM = "action";
       private static final String KEY_PARAM = "key";
  +    private static final String SILENT_PARAM = "silent";
   
       // Possible values for 'action' parameter
   
       private static final String CLEAR_ALL_REGIONS_ACTION = "clearAllRegions";
       private static final String CLEAR_REGION_ACTION = "clearRegion";
       private static final String REMOVE_ACTION = "remove";
  +    private static final String DETAIL_ACTION = "detail";
   
       private CacheHub cacheHub = CacheHub.getInstance();
   
  @@ -75,6 +80,10 @@
                                         Context context )
           throws Exception
       {
  +        String templateName = DEFAULT_TEMPLATE_NAME;
  +
  +        // Get cacheName for actions from request (might be null)
  +
           String cacheName = request.getParameter( CACHE_NAME_PARAM );
   
           // If an action was provided, handle it
  @@ -106,11 +115,52 @@
                   {
                       removeItem( cacheName, keys[ i ] );
                   }
  +
  +                templateName = REGION_DETAIL_TEMPLATE_NAME;
  +            }
  +            else if ( action.equals( DETAIL_ACTION ) )
  +            {
  +                templateName = REGION_DETAIL_TEMPLATE_NAME;
  +            }
  +        }
  +
  +        if ( request.getParameter( SILENT_PARAM ) != null )
  +        {
  +            // If silent parameter was passed, no output should be produced.
  +
  +            return null;
  +        }
  +        else
  +        {
  +            // Populate the context based on the template
  +
  +            if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
  +            {
  +                context.put( "cacheName", cacheName );
  +                context.put( "keys", getSortedKeys( cacheName ) );
               }
  +            else if ( templateName == DEFAULT_TEMPLATE_NAME )
  +            {
  +                context.put( "cacheInfoRecords", buildCacheInfo() );
  +            }
  +
  +            return getTemplate( templateName );
           }
  +    }
   
  -        // Now populate the context
  +    private Object[] getSortedKeys( String cacheName )
  +    {
  +        Cache cache = ( Cache ) cacheHub.getCache( cacheName );
  +
  +        Object[] keys = cache.getMemoryCache().getKeyArray();
  +
  +        Arrays.sort( keys );
   
  +        return keys;
  +    }
  +
  +    private LinkedList buildCacheInfo() throws Exception
  +    {
           String[] cacheNames = cacheHub.getCacheNames();
   
           Arrays.sort( cacheNames );
  @@ -134,9 +184,7 @@
               cacheInfo.add( regionInfo );
           }
   
  -        context.put( "cacheInfoRecords", cacheInfo );
  -
  -        return getTemplate( DEFAULT_TEMPLATE_NAME );
  +        return cacheInfo;
       }
   
       public int getByteCount( Cache cache )
  
  
  
  1.2       +15 -2     
jakarta-turbine-jcs/src/java/org/apache/jcs/servlet/JCSAdminServletDefault.vm
  
  Index: JCSAdminServletDefault.vm
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/servlet/JCSAdminServletDefault.vm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JCSAdminServletDefault.vm 18 May 2002 02:11:31 -0000      1.1
  +++ JCSAdminServletDefault.vm 20 May 2002 12:35:49 -0000      1.2
  @@ -1,3 +1,9 @@
  +<html>
  +
  +<head><title> JCS Admin Servlet </title></head>
  +
  +<body>
  +
   <h1> Cache Regions </h1>
   
   <p>These are the regions which are currently defined in the cache. 'Items' and
  @@ -20,8 +26,15 @@
               <td> $record.ItemCount </td>
               <td> $record.ByteCount </td>
               <td> $record.Status </td>
  -            <td> <a href="?action=clearRegion&cacheName=${record.Name}"> Remove all 
</a> </td>
  +            <td>
  +                <a href="?action=detail&cacheName=${record.Name}"> Detail </a>
  +                | <a href="?action=clearRegion&cacheName=${record.Name}"> Remove 
all </a>
  +            </td>
           </tr>
       #end
   
  -</table>
  \ No newline at end of file
  +</table>
  +
  +</body>
  +
  +</html>
  \ No newline at end of file
  
  
  
  1.1                  
jakarta-turbine-jcs/src/java/org/apache/jcs/servlet/JCSAdminServletRegionDetail.vm
  
  Index: JCSAdminServletRegionDetail.vm
  ===================================================================
  <html>
  
  <head><title> JCS Admin Servlet Region Detail </title></head>
  
  <body>
  
  <h1> Keys for region: $cacheName </h1>
  
  <table border="1" cellpadding="5" >
      <tr>
          <th> Key </th>
      </tr>
  
      #foreach ( $key in $keys )
          <tr>
              <td> $key </td>
              <td> <a href="?action=remove&cacheName=${cacheName}&key=${key}"> Remove 
</a> </td>
          </tr>
      #end
  
  </table>
  
  </body>
  
  </html>
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to