Search in sources :

Example 1 with GarbageCollector

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;
}
Also used : GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 2 with GarbageCollector

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;
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) InternalVersionManagerImpl(org.apache.jackrabbit.core.version.InternalVersionManagerImpl) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 3 with GarbageCollector

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();
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 4 with GarbageCollector

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;
    }
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) RepositoryException(javax.jcr.RepositoryException) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 5 with GarbageCollector

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();
}
Also used : IPentahoSystemSessionFactory(org.apache.jackrabbit.core.IPentahoSystemSessionFactory) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

GarbageCollector (org.apache.jackrabbit.core.gc.GarbageCollector)9 Node (javax.jcr.Node)4 RepositoryException (javax.jcr.RepositoryException)4 Session (javax.jcr.Session)4 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)4 SessionImpl (org.apache.jackrabbit.core.SessionImpl)4 ValueFactory (javax.jcr.ValueFactory)2 Test (org.junit.Test)2 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Binary (javax.jcr.Binary)1 NodeIterator (javax.jcr.NodeIterator)1 Property (javax.jcr.Property)1 Value (javax.jcr.Value)1 Version (javax.jcr.version.Version)1 VersionHistory (javax.jcr.version.VersionHistory)1 MarkEventListener (org.apache.jackrabbit.api.management.MarkEventListener)1