mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Split transactional EHCache configuration from entity and other EHCache configuration. This will allow a smoother transition to EHCache 1.2, which is to be released soon.
Added a deep cache tracer for EHCaches. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2364 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,14 +1,21 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Configuration of in-transaction caches along with the shared (cross-transaction) caches.
|
||||||
|
The in-transaction caches do not share the same configuration as the shared caches.
|
||||||
|
This is because the shared caches can support replication (EHCache 1.2), while the
|
||||||
|
in-transaction caches must not use these features.
|
||||||
|
-->
|
||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
<!-- ==================================================== -->
|
<!-- ==================================================== -->
|
||||||
<!-- EH Cache Manager to produce in-transaction EH Caches -->
|
<!-- EH Cache Manager to produce in-transaction EH Caches -->
|
||||||
<!-- ==================================================== -->
|
<!-- ==================================================== -->
|
||||||
|
|
||||||
<bean name="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" >
|
<bean name="transactionalEHCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" >
|
||||||
<property name="configLocation">
|
<property name="configLocation">
|
||||||
<value>classpath:ehcache.xml</value>
|
<value>classpath:ehcache-transactional.xml</value>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
@@ -42,7 +49,7 @@
|
|||||||
<ref bean="nullPermissionSharedCache" />
|
<ref bean="nullPermissionSharedCache" />
|
||||||
</property>
|
</property>
|
||||||
<property name="cacheManager" >
|
<property name="cacheManager" >
|
||||||
<ref bean="ehCacheManager" />
|
<ref bean="transactionalEHCacheManager" />
|
||||||
</property>
|
</property>
|
||||||
<!-- Eh cache area -->
|
<!-- Eh cache area -->
|
||||||
<property name="name">
|
<property name="name">
|
||||||
@@ -83,7 +90,7 @@
|
|||||||
<ref bean="userToAuthoritySharedCache" />
|
<ref bean="userToAuthoritySharedCache" />
|
||||||
</property>
|
</property>
|
||||||
<property name="cacheManager" >
|
<property name="cacheManager" >
|
||||||
<ref bean="ehCacheManager" />
|
<ref bean="transactionalEHCacheManager" />
|
||||||
</property>
|
</property>
|
||||||
<!-- Eh cache area -->
|
<!-- Eh cache area -->
|
||||||
<property name="name">
|
<property name="name">
|
||||||
@@ -124,7 +131,7 @@
|
|||||||
<ref bean="permissionsAccessSharedCache" />
|
<ref bean="permissionsAccessSharedCache" />
|
||||||
</property>
|
</property>
|
||||||
<property name="cacheManager" >
|
<property name="cacheManager" >
|
||||||
<ref bean="ehCacheManager" />
|
<ref bean="transactionalEHCacheManager" />
|
||||||
</property>
|
</property>
|
||||||
<!-- Eh cache area -->
|
<!-- Eh cache area -->
|
||||||
<property name="name">
|
<property name="name">
|
||||||
@@ -165,7 +172,7 @@
|
|||||||
<ref bean="nodeOwnerSharedCache" />
|
<ref bean="nodeOwnerSharedCache" />
|
||||||
</property>
|
</property>
|
||||||
<property name="cacheManager" >
|
<property name="cacheManager" >
|
||||||
<ref bean="ehCacheManager" />
|
<ref bean="transactionalEHCacheManager" />
|
||||||
</property>
|
</property>
|
||||||
<!-- Eh cache area -->
|
<!-- Eh cache area -->
|
||||||
<property name="name">
|
<property name="name">
|
||||||
|
@@ -131,6 +131,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- enable DEBUG for 'org.alfresco.repo.cache.EhCacheTracerJob' to activate -->
|
||||||
|
<bean id="ehCacheTracerJob" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
|
||||||
|
<property name="jobDetail">
|
||||||
|
<bean id="ehCacheTracerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
|
||||||
|
<property name="jobClass">
|
||||||
|
<value>org.alfresco.repo.cache.EhCacheTracerJob</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</property>
|
||||||
|
<property name="startDelay">
|
||||||
|
<value>3600000</value><!-- start after an hour -->
|
||||||
|
</property>
|
||||||
|
<property name="repeatInterval">
|
||||||
|
<value>3600000</value><!-- repeat every hour -->
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- Scheduled tasks -->
|
<!-- Scheduled tasks -->
|
||||||
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||||
<property name="triggers">
|
<property name="triggers">
|
||||||
@@ -144,7 +161,9 @@
|
|||||||
<ref bean="ldapGroupTrigger" />
|
<ref bean="ldapGroupTrigger" />
|
||||||
<ref bean="ldapPeopleTrigger" />
|
<ref bean="ldapPeopleTrigger" />
|
||||||
-->
|
-->
|
||||||
|
<!--
|
||||||
|
<ref bean="ehCacheTracerJob" />
|
||||||
|
-->
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
<property name="waitForJobsToCompleteOnShutdown">
|
<property name="waitForJobsToCompleteOnShutdown">
|
||||||
|
14
config/ehcache-transactional.xml
Normal file
14
config/ehcache-transactional.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!--
|
||||||
|
This configures the cache properties for Alfresco's in-transaction caches.
|
||||||
|
-->
|
||||||
|
<ehcache>
|
||||||
|
<diskStore
|
||||||
|
path="java.io.tmpdir"/>
|
||||||
|
<defaultCache
|
||||||
|
maxElementsInMemory="5000"
|
||||||
|
eternal="true"
|
||||||
|
timeToIdleSeconds="0"
|
||||||
|
timeToLiveSeconds="0"
|
||||||
|
overflowToDisk="false"
|
||||||
|
/>
|
||||||
|
</ehcache>
|
@@ -1,4 +1,5 @@
|
|||||||
<ehcache>
|
<ehcache>
|
||||||
|
<!-- defaults -->
|
||||||
<diskStore
|
<diskStore
|
||||||
path="java.io.tmpdir"/>
|
path="java.io.tmpdir"/>
|
||||||
<defaultCache
|
<defaultCache
|
||||||
@@ -8,11 +9,23 @@
|
|||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
/>
|
/>
|
||||||
|
<!-- Hibernate usage -->
|
||||||
|
<cache
|
||||||
|
name="org.hibernate.cache.StandardQueryCache"
|
||||||
|
maxElementsInMemory="50"
|
||||||
|
eternal="true"
|
||||||
|
timeToLiveSeconds="0"
|
||||||
|
overflowToDisk="false"/>
|
||||||
|
<cache
|
||||||
|
name="org.hibernate.cache.UpdateTimestampsCache"
|
||||||
|
maxElementsInMemory="5000"
|
||||||
|
eternal="true"
|
||||||
|
overflowToDisk="false"/>
|
||||||
<!-- Nodes: Most other objects are cached as a ratio against the number of nodes cached -->
|
<!-- Nodes: Most other objects are cached as a ratio against the number of nodes cached -->
|
||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl"
|
||||||
maxElementsInMemory="100000"
|
maxElementsInMemory="100000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -21,7 +34,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeStatusImpl"
|
name="org.alfresco.repo.domain.hibernate.NodeStatusImpl"
|
||||||
maxElementsInMemory="100000"
|
maxElementsInMemory="100000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -30,7 +43,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.aspects"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.aspects"
|
||||||
maxElementsInMemory="500000"
|
maxElementsInMemory="500000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -39,7 +52,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.properties"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.properties"
|
||||||
maxElementsInMemory="1000000"
|
maxElementsInMemory="1000000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -48,7 +61,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.childAssocs"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.childAssocs"
|
||||||
maxElementsInMemory="100000"
|
maxElementsInMemory="100000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -57,7 +70,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.parentAssocs"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.parentAssocs"
|
||||||
maxElementsInMemory="100000"
|
maxElementsInMemory="100000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -66,7 +79,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.ChildAssocImpl"
|
name="org.alfresco.repo.domain.hibernate.ChildAssocImpl"
|
||||||
maxElementsInMemory="100000"
|
maxElementsInMemory="100000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -75,7 +88,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.sourceNodeAssocs"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.sourceNodeAssocs"
|
||||||
maxElementsInMemory="10000"
|
maxElementsInMemory="10000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -84,7 +97,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeImpl.targetNodeAssocs"
|
name="org.alfresco.repo.domain.hibernate.NodeImpl.targetNodeAssocs"
|
||||||
maxElementsInMemory="10000"
|
maxElementsInMemory="10000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -93,7 +106,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.NodeAssocImpl"
|
name="org.alfresco.repo.domain.hibernate.NodeAssocImpl"
|
||||||
maxElementsInMemory="10000"
|
maxElementsInMemory="10000"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -102,7 +115,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.StoreImpl"
|
name="org.alfresco.repo.domain.hibernate.StoreImpl"
|
||||||
maxElementsInMemory="100"
|
maxElementsInMemory="100"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -111,7 +124,7 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.VersionCountImpl"
|
name="org.alfresco.repo.domain.hibernate.VersionCountImpl"
|
||||||
maxElementsInMemory="100"
|
maxElementsInMemory="100"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="0"
|
timeToLiveSeconds="0"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
@@ -120,22 +133,11 @@
|
|||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.domain.hibernate.AppliedPatchImpl"
|
name="org.alfresco.repo.domain.hibernate.AppliedPatchImpl"
|
||||||
maxElementsInMemory="100"
|
maxElementsInMemory="100"
|
||||||
eternal="false"
|
eternal="true"
|
||||||
timeToIdleSeconds="0"
|
timeToIdleSeconds="0"
|
||||||
timeToLiveSeconds="60"
|
timeToLiveSeconds="60"
|
||||||
overflowToDisk="false"
|
overflowToDisk="false"
|
||||||
/>
|
/>
|
||||||
<cache
|
|
||||||
name="org.hibernate.cache.StandardQueryCache"
|
|
||||||
maxElementsInMemory="50"
|
|
||||||
eternal="false"
|
|
||||||
timeToLiveSeconds="0"
|
|
||||||
overflowToDisk="false"/>
|
|
||||||
<cache
|
|
||||||
name="org.hibernate.cache.UpdateTimestampsCache"
|
|
||||||
maxElementsInMemory="5000"
|
|
||||||
eternal="true"
|
|
||||||
overflowToDisk="false"/>
|
|
||||||
<!-- Permission related caches -->
|
<!-- Permission related caches -->
|
||||||
<cache
|
<cache
|
||||||
name="org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl"
|
name="org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl"
|
||||||
|
191
source/java/org/alfresco/repo/cache/EhCacheTracerJob.java
vendored
Normal file
191
source/java/org/alfresco/repo/cache/EhCacheTracerJob.java
vendored
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005 Alfresco, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Mozilla Public License version 1.1
|
||||||
|
* with a permitted attribution clause. You may obtain a
|
||||||
|
* copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.alfresco.org/legal/license.txt
|
||||||
|
*
|
||||||
|
* 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.alfresco.repo.cache;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.ehcache.Cache;
|
||||||
|
import net.sf.ehcache.CacheException;
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Element;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the size of EHCache caches used.
|
||||||
|
* <p>
|
||||||
|
* To activate this class, call the {@link #init()} method.
|
||||||
|
*
|
||||||
|
* @author Derek Hulley
|
||||||
|
*/
|
||||||
|
public class EhCacheTracerJob implements Job
|
||||||
|
{
|
||||||
|
private static Log logger = LogFactory.getLog(EhCacheTracerJob.class);
|
||||||
|
|
||||||
|
private CacheManager cacheManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cache manager to analyze. The default cache manager will be analyzed
|
||||||
|
* if this property is not set.
|
||||||
|
*
|
||||||
|
* @param cacheManager optional cache manager to analyze
|
||||||
|
*/
|
||||||
|
public void setCacheManager(CacheManager cacheManager)
|
||||||
|
{
|
||||||
|
this.cacheManager = cacheManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
logger.error("Exception during execution of job", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execute() throws Exception
|
||||||
|
{
|
||||||
|
if (cacheManager == null)
|
||||||
|
{
|
||||||
|
cacheManager = CacheManager.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
long maxHeapSize = Runtime.getRuntime().maxMemory();
|
||||||
|
long totalSize = 0L;
|
||||||
|
// get all the caches
|
||||||
|
String[] cacheNames = cacheManager.getCacheNames();
|
||||||
|
logger.debug("Dumping EHCache info:");
|
||||||
|
for (String cacheName : cacheNames)
|
||||||
|
{
|
||||||
|
Cache cache = cacheManager.getCache(cacheName);
|
||||||
|
if (cache == null) // perhaps a temporary cache
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// dump
|
||||||
|
CacheAnalysis analysis = new CacheAnalysis(cache);
|
||||||
|
logger.debug(analysis);
|
||||||
|
// get the size
|
||||||
|
totalSize += analysis.getSize();
|
||||||
|
}
|
||||||
|
// check the size
|
||||||
|
double sizePercentage = (double)totalSize / (double)maxHeapSize * 100.0;
|
||||||
|
String msg = String.format(
|
||||||
|
"EHCaches currently consume %5.2f MB or %3.2f percent of system VM size",
|
||||||
|
(double)totalSize / 1024.0 / 1024.0,
|
||||||
|
sizePercentage);
|
||||||
|
logger.debug(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CacheAnalysis
|
||||||
|
{
|
||||||
|
private Cache cache;
|
||||||
|
private long size = 0L;
|
||||||
|
|
||||||
|
public CacheAnalysis(Cache cache) throws CacheException
|
||||||
|
{
|
||||||
|
this.cache = cache;
|
||||||
|
calculateSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized long getSize()
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private synchronized void calculateSize() throws CacheException
|
||||||
|
{
|
||||||
|
// calculate the cache deep size - EHCache 1.1 is always returning 0L
|
||||||
|
List<Serializable> keys = cache.getKeys();
|
||||||
|
for (Serializable key : keys)
|
||||||
|
{
|
||||||
|
Element element = cache.get(key);
|
||||||
|
size += getSize(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getSize(Serializable obj)
|
||||||
|
{
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oos = new ObjectOutputStream(bout);
|
||||||
|
oos.writeObject(obj);
|
||||||
|
return bout.size();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
logger.warn("Deep size calculation failed for cache: \n" + cache);
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try { oos.close(); } catch (IOException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusStr()
|
||||||
|
{
|
||||||
|
switch (cache.getStatus())
|
||||||
|
{
|
||||||
|
case Cache.STATUS_ALIVE:
|
||||||
|
return "ALIVE";
|
||||||
|
case Cache.STATUS_DISPOSED:
|
||||||
|
return "DISPOSED";
|
||||||
|
case Cache.STATUS_UNINITIALISED:
|
||||||
|
return "UNINITIALIZED";
|
||||||
|
default:
|
||||||
|
throw new AlfrescoRuntimeException("Unknown cache status: " + cache.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
double sizeMB = (double)getSize()/1024.0/1024.0;
|
||||||
|
long maxSize = cache.getMaxElementsInMemory();
|
||||||
|
long currentSize = cache.getMemoryStoreSize();
|
||||||
|
double percentageFull = (double)currentSize / (double)maxSize * 100.0;
|
||||||
|
double estMaxSize = sizeMB / (double) currentSize * (double) maxSize;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(512);
|
||||||
|
sb.append(" Analyzing EHCache: \n")
|
||||||
|
.append("===> ").append(cache).append("\n")
|
||||||
|
.append(" Deep Size: ").append(String.format("%5.2f MB", sizeMB)).append("\n")
|
||||||
|
.append(" Percentage used: ").append(String.format("%5.2f percent", percentageFull)).append("\n")
|
||||||
|
.append(" Estimated maximum size: ").append(String.format("%5.2f MB", estMaxSize));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user