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
 void close()
          Cleanup resources used internally by this instance.
 int deleteUnused()
          Delete all unused items in the data store.
protected  void finalize()
          Auto-close in case the application didn't call it explicitly.
 DataStore getDataStore()
          Get the data store if one is used.
 boolean getPersistenceManagerScan()
          Check if using the IterablePersistenceManager interface is allowed.
 void scan()
          Scan the repository.
 void setPersistenceManagerScan(boolean allow)
          Enable or disable using the IterablePersistenceManager interface to scan the items.
 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()
          The repository was scanned.
 
Methods inherited from class java.lang.Object
clone, equals, 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:
session - the session that created this object
list - the persistence managers
sessionList - the sessions to access the workspaces
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:
millis - 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

setPersistenceManagerScan

public void setPersistenceManagerScan(boolean allow)
Enable or disable using the IterablePersistenceManager interface to scan the items. This is important for clients that need the complete Node implementation in the ScanEventListener callback.

Parameters:
allow - true if using the IterablePersistenceManager interface is allowed

getPersistenceManagerScan

public boolean getPersistenceManagerScan()
Check if using the IterablePersistenceManager interface is allowed.

Returns:
true if using IterablePersistenceManager is possible.

stopScan

public void stopScan()
              throws RepositoryException
The repository was scanned. This method will stop the observation listener.

Throws:
RepositoryException

deleteUnused

public int deleteUnused()
                 throws RepositoryException
Delete all unused items in the data store.

Returns:
the number of deleted items
Throws:
RepositoryException

getDataStore

public DataStore getDataStore()
Get the data store if one is used.

Returns:
the data store, or null

close

public void close()
Cleanup resources used internally by this instance.


finalize

protected void finalize()
                 throws Throwable
Auto-close in case the application didn't call it explicitly.

Overrides:
finalize in class Object
Throws:
Throwable


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