org.apache.jackrabbit.core.data
Class GarbageCollector

java.lang.Object
  extended by org.apache.jackrabbit.core.data.GarbageCollector
All Implemented Interfaces:
DataStoreGarbageCollector

public class GarbageCollector
extends Object
implements DataStoreGarbageCollector

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:

 JackrabbitRepositoryFactory jf = (JackrabbitRepositoryFactory) factory;
 RepositoryManager m = factory.getRepositoryManager((JackrabbitRepository) rep);
 GarbageCollector gc = m.createDataStoreGarbageCollector();
 try {
     gc.mark();
     gc.sweep();
 } finally {
     gc.close();
 }
 


Constructor Summary
GarbageCollector(RepositoryImpl rep, SessionImpl session, IterablePersistenceManager[] list, Session[] sessionList)
          Create a new garbage collector.
 
Method Summary
 void close()
           
 int deleteUnused()
          Deprecated. use sweep().
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()
          Deprecated. use isPersistenceManagerScan().
 long getSleepBetweenNodes()
           
 boolean isPersistenceManagerScan()
           
 void mark()
           
 void scan()
          Deprecated. use mark().
 void setMarkEventListener(MarkEventListener callback)
           
 void setPersistenceManagerScan(boolean allow)
           
 void setScanEventListener(ScanEventListener callback)
          Deprecated. use setMarkEventListener().
 void setSleepBetweenNodes(long millis)
           
 void setTestDelay(int testDelay)
          When testing the garbage collection, a delay is used instead of simulating concurrent access.
 void stopScan()
          Stop the observation listener if any are installed.
 int sweep()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GarbageCollector

public GarbageCollector(RepositoryImpl rep,
                        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:
rep - the repository
session - the session that created this object (optional)
list - the persistence managers
sessionList - the sessions to access the workspaces
Method Detail

setSleepBetweenNodes

public void setSleepBetweenNodes(long millis)
Specified by:
setSleepBetweenNodes in interface DataStoreGarbageCollector

getSleepBetweenNodes

public long getSleepBetweenNodes()
Specified by:
getSleepBetweenNodes in interface DataStoreGarbageCollector

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)
Deprecated. use setMarkEventListener().


setMarkEventListener

public void setMarkEventListener(MarkEventListener callback)
Specified by:
setMarkEventListener in interface DataStoreGarbageCollector

scan

public void scan()
          throws RepositoryException
Deprecated. use mark().

Throws:
RepositoryException

mark

public void mark()
          throws RepositoryException
Specified by:
mark in interface DataStoreGarbageCollector
Throws:
RepositoryException

setPersistenceManagerScan

public void setPersistenceManagerScan(boolean allow)
Specified by:
setPersistenceManagerScan in interface DataStoreGarbageCollector

isPersistenceManagerScan

public boolean isPersistenceManagerScan()
Specified by:
isPersistenceManagerScan in interface DataStoreGarbageCollector

getPersistenceManagerScan

public boolean getPersistenceManagerScan()
Deprecated. use isPersistenceManagerScan().


stopScan

public void stopScan()
              throws RepositoryException
Stop the observation listener if any are installed.

Throws:
RepositoryException

deleteUnused

public int deleteUnused()
                 throws RepositoryException
Deprecated. use sweep().

Throws:
RepositoryException

sweep

public int sweep()
          throws RepositoryException
Specified by:
sweep in interface DataStoreGarbageCollector
Throws:
RepositoryException

getDataStore

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

Returns:
the data store, or null

close

public void close()
Specified by:
close in interface DataStoreGarbageCollector

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