org.apache.excalibur.store.impl
Class StoreJanitorImpl

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.store.impl.StoreJanitorImpl
All Implemented Interfaces:
Component, LogEnabled, Parameterizable, java.lang.Runnable, Startable, StoreJanitor, ThreadSafe

public class StoreJanitorImpl
extends AbstractLogEnabled
implements StoreJanitor, Parameterizable, ThreadSafe, java.lang.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:
CVS $Id: StoreJanitorImpl.java,v 1.4 2004/02/28 11:47:31 cziegeler Exp $
Author:
Avalon Development Team

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.
 java.util.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()
          Starts the component.
 void stop()
          Stops the component.
 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
Parameters:
params - the Configuration of the application
Throws:
ParameterException

start

public void start()
Description copied from interface: Startable
Starts the component.

Specified by:
start in interface Startable

stop

public void stop()
Description copied from interface: Startable
Stops the component.

Specified by:
stop in interface Startable

run

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

Specified by:
run in interface java.lang.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 java.util.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 © 1997-2005 The Apache Software Foundation. All Rights Reserved.