Package org.apache.jackrabbit.core.gc

Examples of org.apache.jackrabbit.core.gc.GarbageCollector


                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);
View Full Code Here


     * 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;
    }
View Full Code Here

                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);
View Full Code Here

        session.save();

        n.remove();
        session.save();

        GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
        gc.getDataStore().clearInUse();
        gc.setPersistenceManagerScan(false);
        gc.setMarkEventListener(this);

        if (gc.getDataStore() instanceof FileDataStore) {
            // make sure the file is old (access time resolution is 2 seconds)
            Thread.sleep(2000);
        }

        LOG.debug("scanning...");
        gc.mark();
        int count = listIdentifiers(gc);
        LOG.debug("stop scanning; currently " + count + " identifiers");
        LOG.debug("deleting...");
        gc.getDataStore().clearInUse();
        assertTrue(gc.sweep() > 0);
        int count2 = listIdentifiers(gc);
        assertEquals(count - 1, count2);

        // verify the node was moved, and that the binary is still there
        n = root.getNode("node1").getNode("nodeWithBlob").getNode("sub");
        b = n.getProperty("test").getValue().getBinary();
        InputStream in = b.getStream();
        InputStream in2 = new RandomInputStream(20, 1000);
        verifyInputStream(in, in2);

        deleteMyNodes();

        gc.close();
    }
View Full Code Here

        int count = (gct1.getException() == null ? 0 : 1) + (gct2.getException() == null ? 0 : 1);
        assertEquals("only one gc should throw exception ", 1, count);
    }

    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();
    }
View Full Code Here

    }

    public void test() {
        setupRepository();

        GarbageCollector garbageCollector = setupGarbageCollector();
        // To make sure even listener for NODE_ADDED is registered in GC.
        garbageCollector.setPersistenceManagerScan(false);

        assertEquals(0, getBinaryCount(garbageCollector));
        setupNodes();
        assertEquals(1, getBinaryCount(garbageCollector));
        garbageCollector.getDataStore().clearInUse();

        garbageCollector.setMarkEventListener(new MarkEventListener() {

            public void beforeScanning(Node node) throws RepositoryException {
                String path = node.getPath();
                if (path.startsWith("/node")) {
                    log("Traversing: " + node.getPath());
                }

                if ("/node1".equals(node.getPath())) {
                    String from = "/node2/node3";
                    String to = "/node0/node3";
                    log("Moving " + from + " -> " + to);
                    sessionMover.move(from, to);
                    sessionMover.save();
                    sleepForFile();
                }
            }
        });

        try {
            garbageCollector.getDataStore().clearInUse();
            garbageCollector.mark();
            garbageCollector.stopScan();
            sleepForFile();
            int numberOfDeleted = garbageCollector.sweep();
            log("Number of deleted: " + numberOfDeleted);
            // Binary data should still be there.
            assertEquals(1, getBinaryCount(garbageCollector));
        } catch (RepositoryException e) {
            e.printStackTrace();
            failWithException(e);
        } finally {
            garbageCollector.close();
        }
    }
View Full Code Here

    }

    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;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.gc.GarbageCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.