org.apache.cocoon.components.store.impl
Class StoreJanitorImpl

java.lang.Object
  extended byorg.apache.cocoon.components.store.impl.StoreJanitorImpl
All Implemented Interfaces:
Runnable, StoreJanitor
Direct Known Subclasses:
CocoonStoreJanitor

public class StoreJanitorImpl
extends Object
implements StoreJanitor, Runnable

This class is a implentation of a StoreJanitor. Store classes can register to the StoreJanitor. When memory is too low, the StoreJanitor frees the registered caches until memory is normal.

A few parameters can be used:

Version:
$Id: StoreJanitorImpl.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  long interval
          The calculated delay for the next checker run in ms
protected  long inUse
          Amount of memory in use before sleep().
protected  boolean invokeGC
          Should the gc be called on low memory?
 
Fields inherited from interface org.apache.excalibur.store.StoreJanitor
ROLE
 
Constructor Summary
StoreJanitorImpl()
           
 
Method Summary
protected  void checkMemory()
          The "checker" thread checks if memory is running low in the jvm.
 void destroy()
           
 Log getLogger()
           
 void init()
          Initialize the StoreJanitorImpl.
 Iterator iterator()
          This method return a java.util.Iterator of every registered stores The iterators returned is fail-fast: if list is structurally modified at any time after the iterator is created, in any way, the iterator will throw a ConcurrentModificationException.
protected  long memoryInUse()
          Calculate the JVM memory in use now.
 void register(Store store)
          This method register the stores
 void run()
          The "checker" thread loop.
 void setAdaptiveThreadInterval(boolean adaptiveThreadInterval)
          Experimental adaptive algorithm for cleanup interval
 void setCleanupThreadInterval(int cleanupThreadInterval)
          How often shall the cleanup thread check memory? If not specified, defaults to 10 seconds.
 void setFreeingAlgorithm(String algorithm)
           
 void setFreeMemory(int freeMemory)
          How much free memory shall be available in the jvm? If not specified, defaults to 1Mb.
 void setHeapSize(int heapSize)
          How much memory at max jvm can consume? The default max heapsize for Sun's JVM is (almost) 64Mb, can be increased by specifying -Xmx command line parameter.
 void setInvokeGC(boolean invokeGC)
          Shall garbage collector be invoked on low memory? If not specified, defaults to false.
 void setLogger(Log l)
           
 void setPercentToFree(double percentToFree)
          What percent of the store elements shall be dropped on low memory? If not specified, defaults to 10%
 void setThreadPriority(int threadPriority)
          What should be the priority of the cleanup thread? This property is used only by older implementation of the janitor.
 void unregister(Store store)
          This method unregister the stores
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

invokeGC

protected boolean invokeGC
Should the gc be called on low memory?


inUse

protected long inUse
Amount of memory in use before sleep(). Must be initially set a resonable value; ie. memoryInUse()


interval

protected long interval
The calculated delay for the next checker run in ms

Constructor Detail

StoreJanitorImpl

public StoreJanitorImpl()
Method Detail

setFreeMemory

public void setFreeMemory(int freeMemory)
How much free memory shall be available in the jvm? If not specified, defaults to 1Mb.

Parameters:
freeMemory -

setHeapSize

public void setHeapSize(int heapSize)
How much memory at max jvm can consume? The default max heapsize for Sun's JVM is (almost) 64Mb, can be increased by specifying -Xmx command line parameter. If not specified, defaults to 66600000 bytes.

Parameters:
heapSize -

setCleanupThreadInterval

public void setCleanupThreadInterval(int cleanupThreadInterval)
How often shall the cleanup thread check memory? If not specified, defaults to 10 seconds.

Parameters:
cleanupThreadInterval -

setAdaptiveThreadInterval

public void setAdaptiveThreadInterval(boolean adaptiveThreadInterval)
Experimental adaptive algorithm for cleanup interval

Parameters:
adaptiveThreadInterval -

setPercentToFree

public void setPercentToFree(double percentToFree)
What percent of the store elements shall be dropped on low memory? If not specified, defaults to 10%

Parameters:
percentToFree -

setInvokeGC

public void setInvokeGC(boolean invokeGC)
Shall garbage collector be invoked on low memory? If not specified, defaults to false.

Parameters:
invokeGC -

setThreadPriority

public void setThreadPriority(int threadPriority)
What should be the priority of the cleanup thread? This property is used only by older implementation of the janitor. New implementation uses centrally configured thread pool (see thread-pools element below).

Parameters:
threadPriority -

setFreeingAlgorithm

public void setFreeingAlgorithm(String algorithm)

getLogger

public Log getLogger()

setLogger

public void setLogger(Log l)

init

public void init()
          throws Exception
Initialize the StoreJanitorImpl.

Throws:
Exception

destroy

public void destroy()

run

public void run()
The "checker" thread loop.

Specified by:
run in interface Runnable

checkMemory

protected void checkMemory()
The "checker" thread checks if memory is running low in the jvm.


memoryInUse

protected long memoryInUse()
Calculate the JVM memory in use now.

Returns:
memory in use.

register

public void register(Store store)
This method register the stores

Specified by:
register in interface StoreJanitor
Parameters:
store - the store to be registered

unregister

public void unregister(Store store)
This method unregister the stores

Specified by:
unregister in interface StoreJanitor
Parameters:
store - the store to be unregistered

iterator

public Iterator iterator()
This method return a java.util.Iterator of every registered stores The iterators returned is fail-fast: if list is structurally modified at any time after the iterator is created, in any way, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Specified by:
iterator in interface StoreJanitor
Returns:
a java.util.Iterator


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.