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

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.store.impl.StoreJanitorImpl
All Implemented Interfaces:
Runnable, Startable, Component, LogEnabled, Parameterizable, ThreadSafe, StoreJanitor
Direct Known Subclasses:
CocoonStoreJanitor

public class StoreJanitorImpl
extends AbstractLogEnabled
implements StoreJanitor, Parameterizable, ThreadSafe, Runnable, Startable

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 1304258 2012-03-23 10:09:27Z ilgrosso $
Avalon component
Implements service:
type=StoreJanitor

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.
 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 parameterize(Parameters params)
          Parameterize the StoreJanitorImpl.
 void register(Store store)
          This method register the stores
 void run()
          The "checker" thread loop.
 void start()
           
 void stop()
           
 void unregister(Store store)
          This method unregister the stores
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
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

parameterize

public void parameterize(Parameters params)
                  throws ParameterException
Parameterize the StoreJanitorImpl.

Specified by:
parameterize in interface Parameterizable
Throws:
ParameterException

start

public void start()
           throws Exception
Specified by:
start in interface Startable
Throws:
Exception

stop

public void stop()
Specified by:
stop in interface Startable

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-2010 The Apache Software Foundation. All Rights Reserved.