use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class SessionImpl method createDataStoreGarbageCollector.
/**
* Create a data store garbage collector for this repository.
*
* @throws RepositoryException
*/
public GarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
final GarbageCollector gc = repositoryContext.getRepository().createDataStoreGarbageCollector();
// Auto-close if the main session logs out
addListener(new SessionListener() {
public void loggedOut(SessionImpl session) {
}
public void loggingOut(SessionImpl session) {
gc.close();
}
});
return gc;
}
use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class RepositoryImpl method createDataStoreGarbageCollector.
/**
* Creates a data store garbage collector for this repository.
* <p>
* Note that you should use the {@link RepositoryManager} interface
* to access this functionality. This RepositoryImpl method may be
* removed in future Jackrabbit versions.
*/
public GarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
ArrayList<PersistenceManager> pmList = new ArrayList<PersistenceManager>();
InternalVersionManagerImpl vm = context.getInternalVersionManager();
PersistenceManager pm = vm.getPersistenceManager();
pmList.add(pm);
String[] wspNames = getWorkspaceNames();
SessionImpl[] sessions = new SessionImpl[wspNames.length];
for (int i = 0; i < wspNames.length; i++) {
String wspName = wspNames[i];
WorkspaceInfo wspInfo = getWorkspaceInfo(wspName);
// this will initialize the workspace if required
SessionImpl systemSession = SystemSession.create(context, wspInfo.getConfig());
// mark the workspace as 'active' so it does not get disposed by
// the workspace-janitor until the garbage collector is done
wspInfo.setActive(true);
// the workspace could be disposed, so re-initialize if required
// afterwards it will not be disposed because it was marked active
wspInfo.initialize();
sessions[i] = systemSession;
pm = wspInfo.getPersistenceManager();
pmList.add(pm);
}
IterablePersistenceManager[] ipmList = new IterablePersistenceManager[pmList.size()];
for (int i = 0; i < pmList.size(); i++) {
pm = pmList.get(i);
if (!(pm instanceof IterablePersistenceManager)) {
ipmList = null;
break;
}
ipmList[i] = (IterablePersistenceManager) pm;
}
GarbageCollector gc = new GarbageCollector(context, context.getDataStore(), ipmList, sessions);
synchronized (this) {
if (context.isGcRunning()) {
throw new RepositoryException("Cannot create GC. GC already running");
}
context.setGcRunning(true);
}
return gc;
}
use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class GarbageCollectorTest method runGC.
private void runGC(Session session, boolean all) throws Exception {
GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
gc.setMarkEventListener(this);
gc.setPersistenceManagerScan(false);
if (gc.getDataStore() instanceof FileDataStore) {
// make sure the file is old (access time resolution is 2 seconds)
Thread.sleep(2000);
}
gc.mark();
gc.stopScan();
if (all) {
gc.getDataStore().clearInUse();
}
gc.sweep();
gc.close();
}
use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class GCThread method run.
public void run() {
try {
GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
gc.setMarkEventListener(this);
while (!stop) {
LOG.debug("Scanning...");
gc.mark();
int count = listIdentifiers(gc);
LOG.debug("Stop; currently " + count + " identifiers");
gc.stopScan();
int numDeleted = gc.sweep();
if (numDeleted > 0) {
LOG.debug("Deleted " + numDeleted + " identifiers");
}
LOG.debug("Waiting...");
Thread.sleep(10);
}
gc.close();
} catch (Exception ex) {
LOG.error("Error scanning", ex);
exception = ex;
}
}
use of org.apache.jackrabbit.core.gc.GarbageCollector in project pentaho-platform by pentaho.
the class RepositoryCleanerTest method gc.
@Test
public void gc() throws Exception {
GarbageCollector collector = mock(GarbageCollector.class);
RepositoryImpl repository = mock(RepositoryImpl.class);
when(repository.createDataStoreGarbageCollector()).thenReturn(collector);
MicroPlatform mp = new MicroPlatform(getSolutionPath());
mp.defineInstance(Repository.class, repository);
mp.defineInstance("jcrRepository", repository);
mp.start();
RepositoryCleaner cleaner = new RepositoryCleaner();
Session systemSession = mock(Session.class);
IPentahoSystemSessionFactory sessionFactory = mock(IPentahoSystemSessionFactory.class);
when(sessionFactory.create(repository)).thenReturn(systemSession);
cleaner.setSystemSessionFactory(sessionFactory);
try {
cleaner.gc();
} finally {
mp.stop();
}
verify(collector, times(1)).mark();
verify(collector, times(1)).sweep();
verify(collector, times(1)).close();
}
Aggregations