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();
 }
 


Field Summary
protected  int testDelay
           
 
Constructor Summary
GarbageCollector(DataStore dataStore, IterablePersistenceManager[] list, Session[] sessionList)
          Create a new garbage collector.
 
Method Summary
 void close()
          Cleanup resources used internally by this instance.
 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()
          Get the delay between scanning items.
 boolean isPersistenceManagerScan()
          Check if using the IterablePersistenceManager interface is allowed.
 void mark()
          Scan the repository.
 void scan()
          Deprecated. use mark().
 void setMarkEventListener(MarkEventListener callback)
          Set the event listener.
 void setPersistenceManagerScan(boolean allow)
          Enable or disable using the IterablePersistenceManager interface to scan the items.
 void setScanEventListener(ScanEventListener callback)
          Deprecated. use setMarkEventListener().
 void setSleepBetweenNodes(long 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()
          Stop the observation listener if any are installed.
 int sweep()
          Delete all unused items in the data store.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

testDelay

protected int testDelay
Constructor Detail

GarbageCollector

public GarbageCollector(DataStore dataStore,
                        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:
dataStore - the data store to be garbage-collected
list - the persistence managers
sessionList - the sessions to access the workspaces
Method Detail

setSleepBetweenNodes

public void setSleepBetweenNodes(long millis)
Description copied from interface: DataStoreGarbageCollector
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.

Specified by:
setSleepBetweenNodes in interface DataStoreGarbageCollector
Parameters:
millis - the number of milliseconds to sleep

getSleepBetweenNodes

public long getSleepBetweenNodes()
Description copied from interface: DataStoreGarbageCollector
Get the delay between scanning items.

Specified by:
getSleepBetweenNodes in interface DataStoreGarbageCollector
Returns:
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)
Deprecated. use setMarkEventListener().


setMarkEventListener

public void setMarkEventListener(MarkEventListener callback)
Description copied from interface: DataStoreGarbageCollector
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.

Specified by:
setMarkEventListener in interface DataStoreGarbageCollector
Parameters:
callback - if set, this is called while scanning

scan

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

Throws:
RepositoryException

mark

public void mark()
          throws RepositoryException
Description copied from interface: DataStoreGarbageCollector
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 is used; if not, the garbage collector scans the repository using the JCR API starting from the root node.

Specified by:
mark in interface DataStoreGarbageCollector
Throws:
RepositoryException

setPersistenceManagerScan

public void setPersistenceManagerScan(boolean allow)
Description copied from interface: DataStoreGarbageCollector
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.

Specified by:
setPersistenceManagerScan in interface DataStoreGarbageCollector
Parameters:
allow - true if using the IterablePersistenceManager interface is allowed

isPersistenceManagerScan

public boolean isPersistenceManagerScan()
Description copied from interface: DataStoreGarbageCollector
Check if using the IterablePersistenceManager interface is allowed.

Specified by:
isPersistenceManagerScan in interface DataStoreGarbageCollector
Returns:
true if using IterablePersistenceManager is possible.

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
Description copied from interface: DataStoreGarbageCollector
Delete all unused items in the data store.

Specified by:
sweep in interface DataStoreGarbageCollector
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()
Description copied from interface: DataStoreGarbageCollector
Cleanup resources used internally by this instance.

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.