org.apache.jackrabbit.core.data
Class GarbageCollector

java.lang.Object
  extended by org.apache.jackrabbit.core.data.GarbageCollector

public class GarbageCollector
extends Object

Garbage collector for DataStore. This implementation is iterates through all nodes and reads the binary properties. To detect nodes that are moved while the scan runs, event listeners are started. Like the well known garbage collection in Java, the items that are still in use are marked. Currently this achieved by updating the modified date of the entries. Newly added entries are detected because the modified date is changed when they are added.

Example code to run the data store garbage collection:

 GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
 gc.scan();
 gc.stopScan();
 gc.deleteUnused();
 


Constructor Summary
GarbageCollector(SessionImpl session, IterablePersistenceManager[] list, Session[] sessionList)
          Create a new garbage collector.
 
Method Summary
 int deleteUnused()
           
 DataStore getDataStore()
           
 void scan()
          Scan the repository.
 void setScanEventListener(ScanEventListener callback)
          Set the event listener.
 void setSleepBetweenNodes(int millis)
          Set the delay between scanning items.
 void setTestDelay(int testDelay)
          When testing the garbage collection, a delay is used instead of simulating concurrent access.
 void stopScan()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GarbageCollector

public GarbageCollector(SessionImpl session,
                        IterablePersistenceManager[] list,
                        Session[] sessionList)
Create a new garbage collector. This method is usually not called by the application, it is called by SessionImpl.createDataStoreGarbageCollector().

Parameters:
list - the persistence managers
Method Detail

setSleepBetweenNodes

public void setSleepBetweenNodes(int millis)
Set the delay between scanning items. The main scan loop sleeps this many milliseconds after scanning a node. The default is 0, meaning the scan should run at full speed.

Parameters:
sleepBetweenNodes - the number of milliseconds to sleep

setTestDelay

public void setTestDelay(int testDelay)
When testing the garbage collection, a delay is used instead of simulating concurrent access.

Parameters:
testDelay - the delay in milliseconds

setScanEventListener

public void setScanEventListener(ScanEventListener callback)
Set the event listener. If set, the event listener will be called for each item that is scanned. This mechanism can be used to display the progress.

Parameters:
callback - if set, this is called while scanning

scan

public void scan()
          throws RepositoryException,
                 IllegalStateException,
                 IOException,
                 ItemStateException
Scan the repository. The garbage collector will iterate over all nodes in the repository and update the last modified date. If all persistence managers implement the IterablePersistenceManager interface, this mechanism will be used; if not, the garbage collector will scan the repository using the JCR API starting from the root node.

Throws:
RepositoryException
IllegalStateException
IOException
ItemStateException

stopScan

public void stopScan()
              throws RepositoryException
Throws:
RepositoryException

deleteUnused

public int deleteUnused()
                 throws RepositoryException
Throws:
RepositoryException

getDataStore

public DataStore getDataStore()


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.