You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/09/04 18:33:20 UTC

svn commit: r811475 [1/2] - in /cocoon/cocoon3/trunk: cocoon-docs/ cocoon-docs/src/docbkx/reference/ cocoon-monitoring/ cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/ cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cac...

Author: reinhard
Date: Fri Sep  4 16:33:16 2009
New Revision: 811475

URL: http://svn.apache.org/viewvc?rev=811475&view=rev
Log:
COCOON3-39 Cache overview via JMX

Added:
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java   (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java   (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java   (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java   (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java   (with props)
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java   (with props)
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java   (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-docs/pom.xml
    cocoon/cocoon3/trunk/cocoon-docs/src/docbkx/reference/web-applications.xml
    cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
    cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/AbstractPipeline.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/Pipeline.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCache.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/Cache.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheValue.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ObjectCacheValue.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCache.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/InvocationImpl.java
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/cocoon-sitemap-1.0.xsd

Modified: cocoon/cocoon3/trunk/cocoon-docs/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/pom.xml?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-docs/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-docs/pom.xml Fri Sep  4 16:33:16 2009
@@ -58,6 +58,7 @@
       <url>http://agilejava.com/maven</url>
     </pluginRepository>
   </pluginRepositories>
+  
   <build>
     <plugins>
       <plugin>
@@ -156,7 +157,6 @@
           <highlightDefaultLanguage></highlightDefaultLanguage>
           <!-- callouts -->
           <calloutsExtension>1</calloutsExtension>
-
           <entities>
             <entity>
               <name>version</name>

Modified: cocoon/cocoon3/trunk/cocoon-docs/src/docbkx/reference/web-applications.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/src/docbkx/reference/web-applications.xml?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-docs/src/docbkx/reference/web-applications.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-docs/src/docbkx/reference/web-applications.xml Fri Sep  4 16:33:16 2009
@@ -574,14 +574,14 @@
     <section id="webapps.monitoring.configuration">
       <title>Module configuration</title>
       <para>
-        All module configuration is defined in <literal>META-INF/cocoon/spring/cocoon-monitoring.xml.</literal>
+        All module configurations are defined in <literal>META-INF/cocoon/spring/cocoon-monitoring.xml.</literal>
         Each part of module can be enabled or disabled by commenting (or removing) appropriate
         entry in configuration file, by default all parts are enabled.    
       </para>
     </section>
     <section id="webapps.monitoring.parts">
-      <title>Available parts in module</title>
-      <section id="webapps.monitoring.reconfiguration">
+      <title>Available parts</title>
+      <section id="webapps.monitoring.logging">
         <title>Inspect logging settings and reconfigure them</title>
         <section>
           <title>Inspect all configured loggers</title>
@@ -634,6 +634,262 @@
           </para>
         </section>
       </section>
+      <section id="webapps.monitoring.servletservices">
+        <title>Inspect available Servlet-Services</title>
+        <para>
+          Every single Servlet-Service makes his own node in JXM MBean tree. Such node contains below above functions.
+        </para>
+        <section>
+          <title>Get path of Servlet-Services</title>
+          <para>
+            Function <code>getServletServiceMountPaths()</code> returns Servlet-Service mount path.
+          </para>
+        </section>
+        <section>
+          <title>Get all connections for Servlet-Service</title>
+          <para>
+            Function <code>getServletServiceConnections()</code> returns an array of <code>String</code> contains
+            all connections names for given Servlet-Service. Every connection is represented by: <literal>
+            &lt;short name&gt;</literal> => <literal>&lt;full qualified bean name&gt;</literal>
+          </para>
+        </section>
+        <section>
+          <title>Get informations about Servlet-Service</title>
+          <para>
+            Function <code>getServletServiceInfo()</code> returns information about Servlet-Service, such as author,
+            version, and copyright.
+          </para>
+        </section>
+        <section>
+          <title>List Servlet-Service parameters</title>
+          <para>
+            Function <code>getServletServiceInitParameters()</code> list all init parameters provided for that
+            Servlet-Service.
+          </para>
+        </section>
+      </section>
+      <section id="webapps.monitoring.cacheoverview">
+        <title>Overview of cache entries</title>
+        <para>
+          This module contains three smaller submodules:
+          <simplelist>
+            <member><link linkend="webapps.monitoring.cacheoverview.cachemonitor">CacheMonitor</link></member>
+            <member><link linkend="webapps.monitoring.cacheoverview.cacheburstactions">CacheBurstActions</link></member>
+            <member><link linkend="webapps.monitoring.cacheoverview.cacheentrysmonitor">CacheEntrysMonitor</link></member>
+          </simplelist>
+        </para>
+        <section id="webapps.monitoring.cacheoverview.cachemonitor">
+          <title>CacheMonitor</title>
+          <para>
+            This submodule exposes all configured caches on with basic operations on every cache.
+          </para>
+          <section>
+            <title>Clear cache</title>
+            <para>
+              Operation <literal>clear()</literal> remove all cache entry's from this particular cache.
+            </para>
+          </section>
+          <section>
+            <title>List all cache key</title>
+            <para>
+              Operation <literal>listKey()</literal> returns list of all <literal>CacheKey</literal>s that are stored in this particular cache.
+            </para>
+          </section>
+          <section>
+            <title>Removing cache entry</title>
+            <para>
+              If you want remove single cache entry you should use operation <literal>removeKey(String)</literal>, where parameter is
+              <literal>CacheKey</literal> name taken from <literal>listKey()</literal> result. This operation returns <literal>true</literal>
+              if it was successes otherwise it return <literal>false</literal>.
+            </para>
+          </section>
+          <section>
+            <title>Checking size of cache</title>
+            <para>
+              It is also possible to check size of particular cache using function <literal>size</literal>. It will return human readable
+              size of this cache.
+            </para>
+          </section>
+        </section>
+        <section id="webapps.monitoring.cacheoverview.cacheburstactions">
+          <title>CacheBurstActions</title>
+          <para>
+            This module add set of operations that can be performed on all caches. You can find and remove all cache entry's which meet certain
+            requirements, specified in operation parameters.
+          </para>
+          <section>
+            <title>Find all cache entry's that size is greater then specified value</title>
+            <para>
+              Operation <literal>listAllGreatherThen(long)</literal> finds all cache entry's in all configured cache's that size (in bytes)
+              is greather then value passed as a parameter.
+            </para>
+          </section>
+          <section>
+            <title>Find all cache entry's that size is smaller then specified value</title>
+            <para>
+              Operation <literal>listAllSmalledThen(long)</literal> finds all cache entry's in all configured cache's that size (in bytes) is
+              smaller then value passed as a parameter.
+            </para>
+          </section>
+          <section>
+            <title>Find all cache entry's that are older then specified date</title>
+            <para>
+              Operation <literal>listAllOlderThen(String)</literal> finds all cache entry's in all configured cache's that are older then
+              value specified in a parameter. Parameter value must match regular expression: <literal>^\d+[smhd]$</literal> where each
+              letter stands for:
+              <simplelist>
+                <member>s - second</member>
+                <member>m - minutes</member>
+                <member>h - hours</member>
+                <member>d - days</member>
+              </simplelist>
+            </para>
+          </section>
+          <section>
+            <title>Find all cache entry's that are younger then specified date</title>
+            <para>
+              Operation <literal>listAllYoungerThen(String)</literal> finds all cache entry's in all configured cache's that are younger
+              then value specified in a parameter. For parameter description see <literal>listAllOlderThen(String)</literal>.
+            </para>
+          </section>
+          <section>
+            <title>More flexible cache entry's search</title>
+            <para>
+              If you want to get more flexibility searching you can use <literal>list(long, long, String, String, Sting, Sting)</literal>.
+              First two <literal>long</literal> parameters limits cache entry's size, their minimum and maximum size. Second two
+              <literal>String</literal> parameters limits cache entry minimum and maximum age (syntax is same as in
+              <literal>listAllOlderThen(Sting)</literal> and <literal>listAllYoungerThen(String)</literal> functions). Last two
+              <literal>String</literal> parameters are applicable only to <literal>ExpiresCacheKey</literal> instances and they limit
+              result entry's on minimum and maximum experience time of entry. Every result entry meets all limitations. For excluding one
+              (or more) limitation you must pas value -1 for <literal>long</literal> parameters and <literal>null</literal> or empty
+              <literal>String</literal> for rest parameters.
+            </para>
+          </section>
+          <section>
+            <title>Remove all cache entry's that size is greater then specified value</title>
+            <para>
+              Operation <literal>clearAllGreatherThen(long)</literal> perform same search action as <literal>listAllGratherThen(long)</literal>
+              but it removes cache entry's that fulfilled requirements instead of listing them. It will return <literal>true</literal> if
+              every cache entry was successfully removed, after first failure of removing cache entry this operation will stop and return
+              <literal>false</literal>.
+            </para>
+          </section>
+          <section>
+            <title>Remove all cache entry's that size is smaller then specified value.</title>
+            <para>
+              Operation <literal>clearAllSmallerThen(long)</literal> perform same search action as <literal>listAllSmallerThen(long)</literal>
+              but it removes cache entry's that fulfilled requirements instead of listing them. It will return <literal>true</literal> if
+              every cache entry was successfully removed, after first failure of removing cache entry this operation will stop and return
+              <literal>false</literal>.
+            </para>
+          </section>
+          <section>
+            <title>Remove all cache entry's that are older then specified value.</title>
+            <para>
+              Operation <literal>clearAllOlderThen(String)</literal> perform same search action as <literal>listAllOlderThen(String)</literal>
+              but it remove cache etry's that fulfilled requirements instead of listing them, this operation also require same parameter schema
+              as in <literal>listAllOlderThen(String)</literal>. It will return <literal>true</literal> if every cache entry was successfully
+              removed, after first failure of removing cache entry this operation will stop and return
+              <literal>false</literal>.
+            </para>
+          </section>
+          <section>
+            <title>Remove all cache entry's that are younger then specified value.</title>
+            <para>
+              Operation <literal>clearAllYoungerThen(String)</literal> perform same search action as <literal>listAllYoungerThen(String)</literal>
+              but it remove cache etry's that fulfilled requirements instead of listing them, this operation also require same parameter schema
+              as in <literal>listAllYoungerThen(String)</literal>. It will return <literal>true</literal> if every cache entry was successfully
+              removed, after first failure of removing cache entry this operation will stop and return
+              <literal>false</literal>.
+            </para>
+          </section>
+          <section>
+            <title>More flexible cache entry's removing</title>
+            <para>
+              Operation <literal>clear(long, long, String, String, String, String)</literal> perform same search action and takes same parameters
+              as described above <literal>list(long, long, String, String, String)</literal> please see it if you are looking for detailed description.
+            </para>
+          </section>
+          <section>
+            <title>Extending BurstCacheAction module</title>
+            <para>
+              You can add your own burst actions. It is very simple, just obtain instance of <literal>org.apache.cocoon.monitoring.cache.CacheBurstActions</literal>
+              from the container and you can perform any action on cache entry's using <literal>performActionOnCaches(long, long, String, String,
+              String, String, CacheAction)</literal> method. Meaning of each parameter in this method is same as in <literal>list(long, long, String,
+              String, String, String)</literal> and <literal>clear(long, long, String, String, String, String)</literal> methods, but there is one
+              additional parameter, it is implementation of <literal>CacheAction</literal> interface. This interface has only one method
+              <literal>performAction(Cache, CacheKey)</literal> and it will be executed on every cache entry that match passed parameters.
+            </para>
+          </section>
+        </section>
+        <section id="webapps.monitoring.cacheoverview.cacheentrysmonitor">
+          <title>CacheEntrysMonitor</title>
+          <para>
+            This module enables overview of cache entry's that are connected with specified pipeline. This module will only publish cache entry's for
+            those pipeline's that had <literal>jmx-group-id</literal> parameter set for unique value/name. This module also require additional refresh
+            action, it can be performed by user or it can be executed in some period of time eg every one minute. Behavior of refresh action can be
+            configured by <literal>CacheEntrysMonitorInitializer</literal> constructor parameter or on JMX.
+          </para>
+          <section>
+            <title>Configuring refresh action</title>
+            <para>
+              <literal>AutoRefresh</literal> action can be enabled and disabled during runtime. This action will register new <literal>MBean</literal>s
+              that are connected with new cache entry's and unregister old <literal>MBean</literal>s that was connected with expired or removed
+              cache entry's.
+            </para>
+            <section>
+              <title>Enable <literal>AutoRefresh</literal> action</title>
+              <para>
+                For enable <literal>AutoRefresh</literal> action call operation <literal>enableAutoRefresh(long)</literal> where <literal>long</literal>
+                parameter is period time (in millisecond) between each refresh. This operation will stop previously configured <literal>AutoRefresh</literal>
+                action and run new with new time period.
+              </para>
+            </section>
+            <section>
+              <title>Disable <literal>AutoRefresh</literal> action</title>
+              <para>
+                Operation <literal>disableAutoRefresh()</literal> will stops actual running <literal>AutoRefresh</literal> action.
+              </para>
+            </section>
+            <section>
+              <title>Manually perform refresh action</title>
+              <para>
+                Operation <literal>performRefreshAction()</literal> will immediately refre's published cache entry's.
+              </para>
+            </section>
+          </section>
+          <section>
+            <title>Cache entry's operations</title>
+            <para>
+              On each published cache entry you can perform that set of actions:
+            </para>
+            <section>
+              <title>Obtain <literal>CacheKey</literal> for that entry</title>
+              <para>
+                Operation <literal>getCacheKey()</literal> will return <literal>CacheKey</literal> connected with that entry.
+              </para>
+            </section>
+            <section>
+              <title>Obtain cache value</title>
+              <para>
+                Operation <literal>getCacheValue()</literal> will return value of this cache entry.
+              </para>
+            </section>
+            <section>
+              <title>Set cache value</title>
+              <para>
+                Operation <literal>setCacheValue(String)</literal> will set new value of this cache entry.
+              </para>
+            </section>
+            <section>
+              <title>Obtain size of entry</title>
+              <para>
+                Operation <literal>getSize()</literal> will return human readable size of current entry.
+              </para>
+            </section>
+          </section>
+        </section>
+      </section>
     </section>
   </section>
   

Modified: cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml Fri Sep  4 16:33:16 2009
@@ -36,6 +36,14 @@
 
   <dependencies>
     <dependency>
+      <groupId>org.apache.cocoon.pipeline</groupId>
+      <artifactId>cocoon-pipeline</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
     </dependency>

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,393 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.monitoring.cache;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.cocoon.pipeline.caching.Cache;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.CacheValue;
+import org.apache.cocoon.pipeline.caching.ExpiresCacheKey;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
+import org.springframework.jmx.export.annotation.ManagedOperationParameters;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ * This class can perform burst operation (like cleaning specified cache elements) on all cache data.
+ *
+ */
+@ManagedResource(objectName = "org.apache.cocoon.monitoring:group=Cache,name=CacheBurstActions", description = "This module can perform burst operation (like cleaning specified cache elements) on all cache data.")
+public class CacheBurstActions {
+
+    private final List<Cache> caches;
+
+    public CacheBurstActions(Map<String, Cache> caches) {
+        this.caches = new ArrayList<Cache>(caches.values());
+    }
+
+    /**
+     * Clears all cache entry's that size is greater that minSize parameter.<br>
+     * <br>
+     * This operation will stops clearing elements after first failure, this means that
+     * it will clear all cache entry's until one of that entry's fails to clear.
+     *
+     * @param minSize Minimal size (in bytes) of cache entry that should be cleaned.
+     * @return true if operation ends with success, false otherwise
+     */
+    @ManagedOperation(description = "Clears all cache entry's that size is greater that minSize parameter.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "minSize", description = "Minimal size (in bytes) of cache entry that should be cleaned.") })
+    public final boolean clearAllGreaterThen(long minSize) {
+        return this.clear(minSize, -1, null, null, null, null);
+    }
+
+    /**
+     * Clears all cache entries whose size is smaller than maxSize parameter.<br>
+     * <br>
+     * This operation will stops clearing elements after first failure, this means that it will
+     * clear all cache entry's until one of that entry's fails to clear.
+     *
+     * @param maxSize Maximum size (in bytes) of cache entry that should be cleaned.
+     * @return true if operation ends with success, false otherwise
+     */
+    @ManagedOperation(description = "Clears all cache entry's that size is smaller than maxSize parameter.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "maxSize", description = "Maximum size (in bytes) of cache entry that should be cleaned.") })
+    public final boolean clearAllSmallerThen(long maxSize) {
+        return this.clear(-1, maxSize, null, null, null, null);
+    }
+
+    /**
+     * Clears all cache entry's that are older than baseDate parameter.<br>
+     * <br>
+     * This operation will stops clearing elements after first failure, this means that
+     * it will clear all cache entry's until one of that entry's fails to clear.
+     *
+     * @param baseDate
+     * @return true if operation ends with success, false otherwise
+     */
+    @ManagedOperation(description = "Clears all cache entry's that are older than baseDate parameter.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "baseDate", description = "") })
+    public final boolean clearAllOlderThen(String baseDate) {
+        return this.clear(-1, -1, baseDate, null, null, null);
+    }
+
+    /**
+     * Clears all cache entry's that are younger than baseDate parameter.<br>
+     * <br>
+     * This operation will stops clearing elements after first failure, this means that
+     * it will clear all cache entry's until one of that entry's fails to clear.
+     *
+     * @param baseDate
+     * @return true if operation ends with success, false otherwise
+     */
+    @ManagedOperation(description = "Clears all cache entry's that are younger than baseDate parameter.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "baseDate", description = "") })
+    public final boolean clearAllYoungerThen(String baseDate) {
+        return this.clear(-1, -1, null, baseDate, null, null);
+    }
+
+    /**
+     * Clears all cache entry's that matches all conditions in parameters. All parameters are connected logical AND, so to perform action cache entry should match all conditions at once.<br>
+     * <br>
+     * This operation will stops clearing elements after first failure, this means that
+     * it will clear all cache entry's until one of that entry's fails to clear.
+     *
+     * @param minSize Minimal size (in bytes) of cache entry that should be cleaned. If value of this parameter < 0 then it isn't consider.
+     * @param maxSize Maximum size (in bytes) of cache entry that should be cleaned. If value of this parameter < 0 then it isn't consider.
+     * @param minLasModifyDate If this parameter is null or is empty it isn't consider.
+     * @param maxLasModifyDate If this parameter is null or is empty it isn't consider.
+     * @param minExpiresDate This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.
+     * @param maxExpiresDate This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.
+     * @return true if operation ends with success, false otherwise
+     */
+    @ManagedOperation(description = "Clears all cache entry's that matches all conditions in parameters. All parameters are connected logical AND, so to perform action cache entry should match all conditions at once.")
+    @ManagedOperationParameters( {
+            @ManagedOperationParameter(name = "minSize", description = "Minimal size (in bytes) of cache entry that should be cleaned. If value of this parameter < 0 then it isn't consider."),
+            @ManagedOperationParameter(name = "maxSize", description = "Maximum size (in bytes) of cache entry that should be cleaned. If value of this parameter < 0 then it isn't consider."),
+            @ManagedOperationParameter(name = "minLastModifyDate", description = "If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "maxLastModifyDate", description = "If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "minExpiresDate", description = "This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "maxExpiresDate", description = "This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.") })
+    public final boolean clear(long minSize, long maxSize, String minLastModifyDate, String maxLastModifiDate,
+            String minExpiresDate, String maxExpiresDate) {
+
+        final AtomicBoolean state = new AtomicBoolean(true);
+        this.performActionOnCaches(minSize, maxSize, minLastModifyDate, maxLastModifiDate, minExpiresDate, maxExpiresDate,
+                new CacheAction() {
+
+                    public void performAction(Cache cache, CacheKey cacheKey) {
+                        if (state.get()) {
+                            boolean tmp = cache.remove(cacheKey);
+                            state.set(tmp);
+                        }
+                    }
+                });
+
+        return state.get();
+    }
+
+    /**
+     * List all cache entry's that size is greater then minSize parameter. You should use this operation just before performing clearAllGreaterThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.
+     *
+     * @param Minimal size (in bytes) of cache entry.
+     * @return list of cache entry's that matches query arguments
+     */
+    @ManagedOperation(description = "List all cache entry's that size is greater then minSize parameter. You should use this operation just before performing clearAllGreaterThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "minSize", description = "Minimal size (in bytes) of cache entry.") })
+    public final String[] listAllGreaterThen(long minSize) {
+        return this.list(minSize, -1, null, null, null, null);
+    }
+
+    /**
+     * List all cache entry's that size is smaller then minSize parameter. You should use this operation just before performing clearAllSmallerThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.
+     *
+     * @param maxSize Maximum size (in bytes) of cache entry.
+     * @return list of cache entry's that matches query arguments
+     */
+    @ManagedOperation(description = "List all cache entry's that size is smaller then minSize parameter. You should use this operation just before performing clearAllSmallerThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "maxSize", description = "Maximum size (in bytes) of cache entry.") })
+    public final String[] listAllSmallerThen(long maxSize) {
+        return this.list(-1, maxSize, null, null, null, null);
+    }
+
+    /**
+     * List all cache entry's that older than baseDate parameter. You should use this operation just before performing clearAllOlderThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.
+     *
+     * @param baseDate
+     * @return list of cache entry's that matches query arguments
+     */
+    @ManagedOperation(description = "List all cache entry's that older than baseDate parameter. You should use this operation just before performing clearAllOlderThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "baseDate", description = "") })
+    public final String[] listAllOlderThen(String baseDate) {
+        return this.list(-1, -1, baseDate, null, null, null);
+    }
+
+    /**
+     * List all cache entry's that younger than baseDate parameter. You should use this operation just before performing clearAllYoungerThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.
+     *
+     * @param baseDate
+     * @return list of cache entry's that matches query arguments
+     */
+    @ManagedOperation(description = "List all cache entry's that younger than baseDate parameter. You should use this operation just before performing clearAllYoungerThen() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "baseDate", description = "") })
+    public final String[] listAllYoungerThen(String baseDate) {
+        return this.list(-1, -1, baseDate, null, null, null);
+    }
+
+    /**
+     * List all cache entry's that that matches all conditions in parameters. All parameters are connected logical AND, so to perform action cache entry should match all conditions at once. You should use this operation just before performing clear() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.
+     *
+     * @param minSize Minimal size (in bytes) of cache entry. If value of this parameter < 0 then it isn't consider.
+     * @param maxSize Maximum size (in bytes) of cache entry. If value of this parameter < 0 then it isn't consider.
+     * @param minLastModifyDate If this parameter is null or is empty it isn't consider.
+     * @param maxLastModifiDate If this parameter is null or is empty it isn't consider.
+     * @param minExpiresDate This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.
+     * @param maxExpiresDate This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.
+     * @return
+     */
+    @ManagedOperation(description = "List all cache entry's that that matches all conditions in parameters. All parameters are connected logical AND, so to perform action cache entry should match all conditions at once. You should use this operation just before performing clear() to check what entry's would be cleaned. Returned list is limited to first 100 entry's.")
+    @ManagedOperationParameters( {
+            @ManagedOperationParameter(name = "minSize", description = "Minimal size (in bytes) of cache entry. If value of this parameter < 0 then it isn't consider."),
+            @ManagedOperationParameter(name = "maxSize", description = "Maximum size (in bytes) of cache entry. If value of this parameter < 0 then it isn't consider."),
+            @ManagedOperationParameter(name = "minLastModifyDate", description = "If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "maxLastModifyDate", description = "If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "minExpiresDate", description = "This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider."),
+            @ManagedOperationParameter(name = "maxExpiresDate", description = "This parameter apply's only to ExpiresCacheKey entry's. If this parameter is null or is empty it isn't consider.") })
+    public final String[] list(long minSize, long maxSize, String minLastModifyDate, String maxLastModifiDate,
+            String minExpiresDate, String maxExpiresDate) {
+
+        final List<String> results = new ArrayList<String>();
+        this.performActionOnCaches(minSize, maxSize, minLastModifyDate, maxLastModifiDate, minExpiresDate, maxExpiresDate,
+                new CacheAction() {
+
+                    public void performAction(Cache cache, CacheKey cacheKey) {
+                        results.add(cache.toString() + cacheKey.toString());
+                    }
+                });
+
+        List<String> returnList;
+        if (results.size() > 100) {
+            returnList = results.subList(0, 99);
+            returnList.add("There is " + (results.size() - 100) + " more elements that matches this filter.");
+        } else {
+            returnList = results;
+        }
+
+        return returnList.toArray(new String[] {});
+    }
+
+    /**
+     * This method actually performs action on cache's.
+     *
+     * @param minSize If value of this parameter < 0 value of point wouldn't increased.
+     * @param maxSize If value of this parameter < 0 value of point wouldn't increased.
+     * @param minLastModifyDate If this parameter is null or is empty value of point wouldn't increased.
+     * @param maxLastModifiDate If this parameter is null or is empty value of point wouldn't increased.
+     * @param minExpiresDate If this parameter is null or is empty value of point wouldn't increased.
+     * @param maxExpiresDate If this parameter is null or is empty value of point wouldn't increased.
+     * @param action call back to action that should be performed if cache entry matches given criteria
+     */
+    private void performActionOnCaches(long minSize, long maxSize, String minLastModifyDate, String maxLastModifyDate,
+            String minExpiresDate, String maxExpiresDate, CacheAction action) {
+
+        Date minExpires = this.parseDate(minExpiresDate);
+        Date maxExpires = this.parseDate(maxExpiresDate);
+        Date minLastModify = this.parseDate(minLastModifyDate);
+        Date maxLastModify = this.parseDate(maxLastModifyDate);
+        int points = this.countPoints(minSize, maxSize, minLastModify, maxLastModify, minExpires, maxExpires);
+
+        for (Cache cache : this.caches) {
+            for (CacheKey cacheKey : cache.keySet()) {
+                int score = 0;
+                CacheValue cacheValue = cache.get(cacheKey);
+                if (cacheValue == null) { // prevent from NullPointerException
+                    continue;
+                }
+
+                // check minSize condition
+                if (minSize >= 0 && cacheValue.size() >= minSize) {
+                    // if minSize condition is set (it value is < 0) and it is not fulfilled we skip this element
+                    score++;
+                }
+
+                // check maxSize condition
+                if (maxSize >= 0 && cacheValue.size() <= maxSize) {
+                    score++;
+                }
+
+                Date lastModifyDate = new Date(cacheKey.getLastModified());
+                if (minLastModify != null && lastModifyDate.compareTo(minLastModify) >= 0) {
+                    score++;
+                }
+
+                if (maxLastModify != null && lastModifyDate.compareTo(maxLastModify) <= 0) {
+                    score++;
+                }
+
+                // expires condition can be only applied to ExpiresCacheKey instances
+                if ((minExpires != null || maxExpires != null) && cacheKey instanceof ExpiresCacheKey) {
+                    ExpiresCacheKey expiresCacheKey = (ExpiresCacheKey) cacheKey;
+                    Date expiresDate = new Date(expiresCacheKey.getExpirationTimestamp());
+
+                    if (minExpires != null && expiresDate.compareTo(minExpires) >= 0) {
+                        score++;
+                    }
+
+                    if (maxExpires != null && expiresDate.compareTo(maxExpires) <= 0) {
+                        score++;
+                    }
+                }
+
+                if (score == points) {
+                    action.performAction(cache, cacheKey);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns date i past based on value of string parameter.
+     *
+     * @param date string in format that matches regular expression ^\d+[smhd]$
+     * @return
+     */
+    private Date parseDate(String date) {
+        if (StringUtils.isEmpty(date)) {
+            return null;
+        }
+
+        if (!date.matches("^\\d+[smhd]$")) {
+            throw new UnsupportedOperationException("Unsupported date format: " + date);
+        }
+
+        char unit = date.charAt(date.length() - 1);
+        long multipler = Long.parseLong(date.substring(0, date.length() - 2));
+
+        long factor;
+        switch (unit) {
+        case 's': // second
+            factor = 1000;
+            break;
+        case 'm': // minute
+            factor = 60 * 1000;
+            break;
+        case 'h': // hour
+            factor = 60 * 60 * 1000;
+            break;
+        case 'd': // day
+            factor = 24 * 60 * 60 * 1000;
+            break;
+        default:
+            throw new UnsupportedOperationException("Unsupported unit: " + unit);
+        }
+
+        return new Date(System.currentTimeMillis() - multipler * factor);
+    }
+
+    /**
+     * Counts points for single cache query. If
+     *
+     * @param minSize If value of this parameter < 0 value of point wouldn't increased.
+     * @param maxSize If value of this parameter < 0 value of point wouldn't increased.
+     * @param minLastModifyDate If this parameter is null value of point wouldn't increased.
+     * @param maxLastModifiDate If this parameter is null value of point wouldn't increased.
+     * @param minExpiresDate If this parameter is null or of point wouldn't increased.
+     * @param maxExpiresDate If this parameter is null or of point wouldn't increased.
+     * @return value of point's
+     */
+    private int countPoints(long minSize, long maxSize, Date minLastModifyDate, Date maxLastModifiDate,
+            Date minExpiresDate, Date maxExpiresDate) {
+
+        int points = 0;
+
+        if (minSize >= 0) {
+            points++;
+        }
+
+        if (maxSize >= 0) {
+            points++;
+        }
+
+        if (minLastModifyDate != null) {
+            points++;
+        }
+
+        if (maxLastModifiDate != null) {
+            points++;
+        }
+
+        if (minExpiresDate != null) {
+            points++;
+        }
+
+        if (maxExpiresDate != null) {
+            points++;
+        }
+        return points;
+    }
+
+    private interface CacheAction {
+        void performAction(Cache cache, CacheKey cacheKey);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheBurstActions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.monitoring.cache;
+
+import java.util.Set;
+
+import org.apache.cocoon.monitoring.util.UnitSizeFormatter;
+import org.apache.cocoon.pipeline.caching.Cache;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.CacheValue;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ * JMX MBean to monitor caches.
+ */
+@ManagedResource
+public class CacheMonitor {
+
+    private final Cache cache;
+
+    public CacheMonitor(Cache cache) {
+        this.cache = cache;
+    }
+
+    /**
+     * Removes all cached data.
+     */
+    @ManagedOperation(description = "Removes all cached data.")
+    public final void clear() {
+        this.cache.clear();
+    }
+
+    /**
+     * List available cache keys
+     *
+     * @return
+     */
+    @ManagedOperation(description = "Removes all cached data.")
+    public final String[] listKeys() { // TODO make cache names more readable and usable for user
+        Set<CacheKey> keySet = this.cache.keySet();
+        String[] result = new String[keySet.size()];
+
+        int i = 0;
+        for (CacheKey cacheKey : keySet) {
+            result[i++] = cacheKey.toString();
+        }
+
+        return result;
+    }
+
+    /**
+     * Remove specific key for cache
+     *
+     * @param cacheKeyName name of CacheKey with should be removed
+     * @return
+     */
+    @ManagedOperation(description = "Remove specific key for cache")
+    @ManagedOperationParameter(name = "cacheKeyName", description = "Name of CacheKey with should be removed")
+    public final boolean removeKey(String cacheKeyName) {
+        Set<CacheKey> keySet = this.cache.keySet();
+
+        for (CacheKey cacheKey : keySet) {
+            if (cacheKey.equals(cacheKeyName)) {
+                this.cache.remove(cacheKey);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns size of this cache
+     *
+     * @return
+     */
+    @ManagedOperation(description = "Returns size of this cache")
+    public final String size() {
+        double result = 0;
+        for (CacheKey key : this.cache.keySet()) {
+            CacheValue cacheValue = this.cache.get(key);
+            if (cacheValue != null) { // prevent from NullPointerException
+                double size = cacheValue.size();
+                if (size != -1) {
+                    result += size;
+                }
+            }
+        }
+
+        return UnitSizeFormatter.getHumanReadableSize(result);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.monitoring.cache;
+
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.cocoon.pipeline.caching.Cache;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.export.MBeanExporter;
+
+public class CacheMonitorInitializer {
+
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    public CacheMonitorInitializer(Map<String, Cache> caches, MBeanExporter exporter) {
+        for (Cache cache : caches.values()) {
+            // '=' is disallowed in ObjectName so it is replaced by ' '
+            String stringName = "org.apache.cocoon.monitoring:group=Cache,subGroup=Caches,name=" + cache.toString().replace("=", " ");
+
+            ObjectName name;
+            try {
+                name = new ObjectName(stringName);
+            } catch (MalformedObjectNameException e) {
+                this.logger.error("Invalid name of manager resource: " + stringName, e);
+                continue;
+            } catch (NullPointerException e) {
+                this.logger.error("Should never happened. Value of name parameter always is different than null.", e);
+                continue;
+            }
+
+            exporter.registerManagedResource(new CacheMonitor(cache), name);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/CacheMonitorInitializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.monitoring.cache.entry;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.cocoon.monitoring.util.UnitSizeFormatter;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.CacheValue;
+import org.apache.cocoon.pipeline.caching.CompleteCacheValue;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
+import org.springframework.jmx.export.annotation.ManagedOperationParameters;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource
+public class CacheEntryMonitor {
+
+    private final CacheKey cacheKey;
+    private final CacheValue cacheValue;
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    public CacheEntryMonitor(CacheKey cacheKey, CacheValue cacheValue) {
+        this.cacheKey = cacheKey;
+        this.cacheValue = cacheValue;
+    }
+
+    @ManagedAttribute(description = "Retuns tihs cache value key.")
+    public final String getCacheKey() {
+        return this.cacheKey.toString();
+    }
+
+    /**
+     *
+     * @return size of this cache entry
+     */
+    @ManagedAttribute(description = "Returns content of this cache entry.")
+    public final String getCacheValue() {
+        if (this.cacheValue instanceof CompleteCacheValue) {
+            ByteArrayOutputStream test = new ByteArrayOutputStream();
+            try {
+                this.cacheValue.writeTo(test);
+            } catch (IOException e) {
+                this.logger.fatal(e.getMessage(), e);
+                return "IOException occurs, please check logs.";
+            }
+
+            return new String(test.toByteArray());
+        } else {
+            return String.valueOf(this.cacheValue.getValue());
+        }
+    }
+
+    /**
+     * Sets value of this cache entry.
+     *
+     * @param value new value of cache
+     */
+    @ManagedOperation(description = "Sets value of this cache entry.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "value", description = "New value of cache.") })
+    public final boolean setCacheValue(String value) {
+        this.cacheValue.setValue(value);
+        return true;
+    }
+
+    /**
+     *
+     * @return size of this cache entry
+     */
+    @ManagedAttribute(description = "Returns size of this cache entry.")
+    public final String getSize() {
+        return UnitSizeFormatter.getHumanReadableSize(this.cacheValue.size());
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntryMonitor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.monitoring.cache.entry;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.cocoon.pipeline.caching.Cache;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.export.MBeanExporter;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
+import org.springframework.jmx.export.annotation.ManagedOperationParameters;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource(objectName = "org.apache.cocoon.monitoring:group=Cache,name=CacheEntrysRefresher")
+public class CacheEntrysMonitorInitializer {
+
+    private static final String namePrefix = "org.apache.cocoon.monitoring:group=Cache,subGroup=Entrys,groupName=";
+    private final Log logger = LogFactory.getLog(this.getClass());
+
+    private final MBeanServer mBeanServer;
+    private final MBeanExporter mBeanExporter;
+    private final Map<String, Cache> caches;
+    private final List<ObjectName> registerdMBeans;
+
+    private Timer autoRefreshTimer;
+
+    public CacheEntrysMonitorInitializer(Map<String, Cache> caches, MBeanExporter exporter) {
+        this(caches, exporter, 0);
+    }
+
+    /**
+     *
+     * @param caches
+     * @param exporter
+     * @param refreshTimeOut if this value is greater than 0 then would be started an automatic refresh task
+     */
+    public CacheEntrysMonitorInitializer(Map<String, Cache> caches, MBeanExporter exporter, long refreshTimeOut) {
+        this.caches = caches;
+        this.mBeanExporter = exporter;
+        this.mBeanServer = exporter.getServer();
+        this.registerdMBeans = new ArrayList<ObjectName>();
+
+        if (refreshTimeOut > 0) {
+            this.enableAutoRefresh(refreshTimeOut);
+        }
+    }
+
+    /**
+     * Forces refresh action on CachesEntrys monitor.
+     *
+     * @return <code>true</code> if every useless MBean was successfully unregistered, <code>false</code> after first failed MBean to unregister.
+     */
+    @ManagedOperation(description = "Forces refresh action on CachesEntrys monitor.")
+    public final boolean performRefresh() {
+        List<ObjectName> toRemove = this.processCaches(this.caches);
+        for (ObjectName objectName : toRemove) {
+            if (this.mBeanServer.isRegistered(objectName)) {
+                try {
+                    this.mBeanServer.unregisterMBean(objectName);
+                } catch (MBeanRegistrationException e) {
+                    this.logger.fatal(e.getMessage(), e);
+                    return false;
+                } catch (InstanceNotFoundException e) {
+                    this.logger.fatal(e.getMessage(), e);
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Enables auto refresh action. If there is already refresh action started it would be  stopped and started new refresh action with defined refreshTimeOut parameter.
+     *
+     * @param refreshTimeOut refresh operation time out in milliseconds
+     */
+    @ManagedOperation(description = "Enables auto refresh action. If there is already refresh action started it would be  stopped and started new refresh action with defined refreshTimeOut parameter.")
+    @ManagedOperationParameters( { @ManagedOperationParameter(name = "refreshTimeOut", description = "Refresh operation time out in milliseconds.") })
+    public final void enableAutoRefresh(long refreshTimeOut) {
+        // stop auto refresh task if it is already running.
+        if (this.autoRefreshTimer != null) {
+            this.disableAutoRefresh();
+        }
+
+        this.autoRefreshTimer = new Timer(true);
+        this.autoRefreshTimer.scheduleAtFixedRate(new RefreshTask(), 0, refreshTimeOut);
+    }
+
+    /**
+     * Stops refresh action if there is any refresh action already running.
+     */
+    @ManagedOperation(description = "Stops refresh action if there is any refresh action already running.")
+    public final void disableAutoRefresh() {
+        if (this.autoRefreshTimer != null) {
+            this.autoRefreshTimer.cancel();
+            this.autoRefreshTimer.purge();
+            this.autoRefreshTimer = null;
+        }
+    }
+
+    /**
+     * Register unregistered MBeans and returns list of removed cache's that should be unregistered from MBean server.
+     *
+     * @param caches
+     * @return list of {@link ObjectName}s that should be unregister form MBean server
+     */
+    private List<ObjectName> processCaches(Map<String, Cache> caches) {
+        List<ObjectName> objectsToBeRemoved = new ArrayList<ObjectName>(this.registerdMBeans);
+        this.registerdMBeans.clear();
+        for (Cache cache : caches.values()) {
+            for (CacheKey cacheKey : cache.keySet()) {
+                if (cacheKey.hasJmxGroupName()) {
+                    ObjectName objectName;
+                    String cacheType = cacheKey.getClass().getSimpleName();
+                    String cacheName = cacheKey.toString().replaceAll("[=:,]", "_");
+                    String fullObjectName = namePrefix + cacheKey.getJmxGroupName() + ",cacheType=" + cacheType + ",name=" + cacheName;
+                    try {
+                        objectName = new ObjectName(fullObjectName);
+                    } catch (MalformedObjectNameException e) {
+                        this.logger.error("Invalid name of manager resource: " + fullObjectName, e);
+                        continue;
+                    } catch (NullPointerException e) {
+                        this.logger.error("Should never happened. Value of name parameter always is different than null.", e);
+                        continue;
+                    }
+
+                    if (!this.mBeanServer.isRegistered(objectName)) { // register MBean only when it isn't already registered
+                        this.mBeanExporter.registerManagedResource(new CacheEntryMonitor(cacheKey, cache.get(cacheKey)), objectName);
+                    }
+
+                    this.registerdMBeans.add(objectName);
+                    objectsToBeRemoved.remove(objectName);
+                }
+            }
+        }
+        return objectsToBeRemoved;
+    }
+
+    private class RefreshTask extends TimerTask {
+        @Override
+        public void run() {
+            CacheEntrysMonitorInitializer.this.performRefresh();
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/cache/entry/CacheEntrysMonitorInitializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.monitoring.util;
+
+public class UnitSizeFormatter {
+
+    private static final String[] UNITS = { "b", "kb", "Mb", "Gb", "Tb" };
+
+    public static String getHumanReadableSize(double bytes) {
+        int i; // count unit
+        for (i = 0; i < UNITS.length && bytes > 1024; i++) {
+            bytes /= 1024;
+        }
+
+        // multiply and divide by 100 to get two place precision
+        return Math.round(bytes * 100) / 100.0 + UNITS[i];
+    }
+}
\ No newline at end of file

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/util/UnitSizeFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml Fri Sep  4 16:33:16 2009
@@ -52,5 +52,23 @@
     </constructor-arg>
     <constructor-arg ref="exporter" index="1"/>
   </bean>
+  <bean id="org.apache.cocoon.monitoring.cache.CacheMonitorInitializer" class="org.apache.cocoon.monitoring.cache.CacheMonitorInitializer">
+    <constructor-arg index="0">
+      <configurator:bean-map type="org.apache.cocoon.pipeline.caching.Cache" />
+    </constructor-arg>
+    <constructor-arg ref="exporter" index="1" />
+  </bean>
+  
+  <bean id="org.apache.cocoon.monitoring.cache.CacheBurstActions" class="org.apache.cocoon.monitoring.cache.CacheBurstActions">
+    <constructor-arg index="0">
+      <configurator:bean-map type="org.apache.cocoon.pipeline.caching.Cache" />
+    </constructor-arg>
+  </bean>
 
+  <bean id="org.apache.cocoon.monitoring.cache.entry.CacheEntrysMonitorInitializer" class="org.apache.cocoon.monitoring.cache.entry.CacheEntrysMonitorInitializer">
+    <constructor-arg index="0">
+        <configurator:bean-map type="org.apache.cocoon.pipeline.caching.Cache" />
+    </constructor-arg>
+    <constructor-arg ref="exporter" index="1" />
+  </bean>
 </beans>

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/AbstractPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/AbstractPipeline.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/AbstractPipeline.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/AbstractPipeline.java Fri Sep  4 16:33:16 2009
@@ -46,7 +46,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#addComponent(org.apache.cocoon.pipeline.component.PipelineComponent)
      */
     public void addComponent(T pipelineComponent) {
@@ -64,7 +64,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#execute()
      */
     public void execute() throws Exception {
@@ -78,7 +78,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#getContentType()
      */
     public String getContentType() {
@@ -92,7 +92,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#setConfiguration(java.util.Map)
      */
     public void setConfiguration(Map<String, ? extends Object> parameters) {
@@ -101,7 +101,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#setup(java.io.OutputStream,
      *      java.util.Map)
      */
@@ -111,7 +111,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.Pipeline#setup(java.io.OutputStream,
      *      java.util.Map)
      */

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java Fri Sep  4 16:33:16 2009
@@ -53,6 +53,8 @@
     /** Expires time in seconds */
     private String expires;
 
+    private String jmxGroupName;
+
     /**
      * Expires pipelines that have non-cacheable pipeline components require an
      * explicit cache key
@@ -149,6 +151,7 @@
     public void setConfiguration(Map<String, ? extends Object> parameters) {
         this.expires = (String) parameters.get("expires");
         this.expiresCacheKey = (Serializable) parameters.get("expires-cache-key");
+        this.jmxGroupName = (String) parameters.get("jmx-group-name");
 
         super.setConfiguration(parameters);
     }
@@ -211,6 +214,7 @@
         if (this.logger.isDebugEnabled()) {
             this.logger.debug("Putting result into pipeline cache: " + cacheValue + ")");
         }
+        cacheKey.setJmxGroupName(this.jmxGroupName);
         this.cache.put(cacheKey, cacheValue);
     }
 }

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/Pipeline.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/Pipeline.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/Pipeline.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/Pipeline.java Fri Sep  4 16:33:16 2009
@@ -38,17 +38,17 @@
  * {@link OutputStream} which has been passed to the
  * {@link #setup(OutputStream, Map)} method.
  * </p>
- * 
+ *
  * <p>
  * A pipeline works based on two fundamental concepts:
- * 
+ *
  * <ul>
  * <li>The first component of a pipeline is of type {@link Starter}. The last
  * component is of type {@link Finisher}. </li>
  * <li>In order to link components with each other, the first has to be a
  * {@link Producer}, the latter {@link Consumer}. </li>
  * </ul>
- * 
+ *
  * <p>
  * When the pipeline links the components, it merely checks whether the above
  * mentioned interfaces are present. So the pipeline does not know about the
@@ -66,7 +66,7 @@
     /**
      * Add a {@link PipelineComponent} to the pipeline. The order of when the
      * components are passed is significant.
-     * 
+     *
      * @param pipelineComponent The {@link PipelineComponent}.
      */
     void addComponent(T pipelineComponent);
@@ -74,7 +74,7 @@
     /**
      * After the pipeline has been setup ({@link #setup(OutputStream, Map)},
      * this method can be invoked in order to produce the result.
-     * 
+     *
      * @throws Exception Any problem that might occur while processing the
      *             pipeline.
      */
@@ -83,14 +83,14 @@
     /**
      * Get the mime-type {@linkref http://tools.ietf.org/html/rfc2046} of the
      * content produced by the pipeline.
-     * 
+     *
      * @return The mime-type of the content.
      */
     String getContentType();
 
     /**
      * Get the time of the last modification.
-     * 
+     *
      * @return The last modification date
      */
     long getLastModified();
@@ -99,7 +99,7 @@
      * After the pipeline has been prepared ({@link #addComponent(PipelineComponent)},
      * this method can be invoked in order to setup and initialize the pipeline
      * and its components.
-     * 
+     *
      * @param outputStream An {@link OutputStream} where the pipeline execution
      *            result is written.
      */
@@ -108,7 +108,7 @@
     /**
      * The same as {@link #setup(OutputStream)} but also allows passing
      * parameters to the pipeline components.
-     * 
+     *
      * @param outputStream An {@link OutputStream} where the pipeline execution
      *            result is written.
      * @param parameters A {@link Map} of parameters that are available to all
@@ -121,7 +121,7 @@
      * in a generic way. This is useful in environments that automatically
      * assemble pipelines with their components and can't use the pipeline's
      * constructors or setters.
-     * 
+     *
      * @param configuration The {@link Map} of configuration parameters.
      */
     void setConfiguration(Map<String, ? extends Object> parameters);

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCache.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCache.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCache.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCache.java Fri Sep  4 16:33:16 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.cocoon.pipeline.caching;
 
+import java.util.Set;
+
 /**
  * An abstract implementation of the {@link Cache} interface.<br>
  * <br>
@@ -61,11 +63,38 @@
     }
 
     /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.cocoon.pipeline.caching.Cache#clear()
+     */
+    public void clear() {
+        this.doClear();
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.cocoon.pipeline.caching.Cache#remove(org.apache.cocoon.pipeline.caching.CacheKey)
+     */
+    public boolean remove(CacheKey cacheKey) {
+        return this.doRemove(cacheKey);
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.cocoon.pipeline.caching.Cache#keySet()
+     */
+    public Set<CacheKey> keySet() {
+        return this.retrieveKeySet();
+    }
+
+    /**
      * Determines if the given <code>cacheValue</code> is valid according to the given <code>cacheKey</code>.<br>
      * <br>
      * This method returns <code>true</code> if and only if the given <code>cacheValue</code> is not <code>null</code> and calling
      * {@link CacheValue#isValid(CacheKey)} with the given <code>cacheKey</code> returns <code>true</code>.
-     * 
+     *
      * @param cacheKey The {@link CacheKey} to be used for checking the <code>cacheValue</code>'s validity.
      * @param cacheValue The {@link CacheValue} to check for validity.
      * @return <code>true</code> if the given <code>cacheValue</code> is not <code>null</code> and valid for the given
@@ -93,9 +122,29 @@
      * Actually stores the given <code>cacheValue</code> at the given <code>cacheKey</code> in the underlying storage.<br>
      * <br>
      * This method is to replace any previously stored {@link CacheValue} (if any).
-     * 
+     *
      * @param cacheKey The {@link CacheKey} to be used for storing.
      * @param cacheValue The {@link CacheValue} to be stored.
      */
     protected abstract void store(CacheKey cacheKey, CacheValue cacheValue);
+
+    /**
+     * Actually clears the underlying storage.
+     */
+    protected abstract void doClear();
+
+    /**
+     * Actually removes cached data from underlying storage.
+     *
+     * @param cacheKey The {@link CacheKey} to be removed.
+     */
+    protected abstract boolean doRemove(CacheKey cacheKey);
+
+    /**
+     * Actually retrieves the {@link Set} for {@link CacheKey} from underlying storage.
+     *
+     * @return The {@link Set} of {@link CacheKey} of containded data.
+     */
+    protected abstract Set<CacheKey> retrieveKeySet();
+
 }

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java?rev=811475&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java (added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java Fri Sep  4 16:33:16 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.caching;
+
+@SuppressWarnings("serial")
+public abstract class AbstractCacheKey implements CacheKey {
+
+    private String jmxGroupName;
+
+    public String getJmxGroupName() {
+        return this.jmxGroupName;
+    }
+
+    public boolean hasJmxGroupName() {
+        return this.jmxGroupName != null && !this.jmxGroupName.equals("");
+    }
+
+    public void setJmxGroupName(String jmxGroupName) {
+        this.jmxGroupName = jmxGroupName;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/AbstractCacheKey.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/Cache.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/Cache.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/Cache.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/Cache.java Fri Sep  4 16:33:16 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.cocoon.pipeline.caching;
 
+import java.util.Set;
+
 public interface Cache {
 
     /**
@@ -62,4 +64,23 @@
      *         given <code>cacheValue</code>.
      */
     CacheValue get(CacheKey cacheKey, boolean includeInvalid);
+
+    /**
+     * Returns {@link Set} of {@link CacheKey} contained in this Cache
+     *
+     * @return a set CacheKey contained in this Cache
+     */
+    Set<CacheKey> keySet();
+
+    /**
+     * Removes that CacheKey from this Cache.
+     *
+     * @param cacheKey
+     */
+    boolean remove(CacheKey cacheKey);
+
+    /**
+     * Removes all data coneined in this Cache
+     */
+    void clear();
 }

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheKey.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheKey.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheKey.java Fri Sep  4 16:33:16 2009
@@ -24,5 +24,11 @@
 
     boolean isValid(CacheKey cacheKey);
 
+    boolean hasJmxGroupName();
+
     long getLastModified();
+
+    String getJmxGroupName();
+
+    void setJmxGroupName(String jmxGroupName);
 }

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheValue.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheValue.java?rev=811475&r1=811474&r2=811475&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheValue.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CacheValue.java Fri Sep  4 16:33:16 2009
@@ -29,4 +29,18 @@
     void writeTo(OutputStream outputStream) throws IOException;
 
     Object getValue();
+
+    /**
+     * Sets value of this cache
+     *
+     * @param value
+     */
+    void setValue(Object value);
+
+    /**
+     * Returns size of this {@link CacheValue} in bytes.
+     *
+     * @return size of cached value in bytes or -1 if something goes wrong.
+     */
+    double size();
 }