jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r815340 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/data/ test/java/org/apache/jackrabbit/core/data/
Date Tue, 15 Sep 2009 14:16:25 GMT
Author: thomasm
Date: Tue Sep 15 14:16:24 2009
New Revision: 815340

URL: http://svn.apache.org/viewvc?rev=815340&view=rev
Log:
JCR-1865 Add the Data Store to the Jackrabbit API

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryManagerImpl.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/ScanEventListener.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCThread.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
Tue Sep 15 14:16:24 2009
@@ -16,20 +16,23 @@
  */
 package org.apache.jackrabbit.core;
 
+import java.util.HashSet;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Set;
 
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
-import javax.jcr.RepositoryFactory;
 import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.api.JackrabbitRepositoryFactory;
+import org.apache.jackrabbit.api.management.RepositoryManager;
 
 /**
  * <code>RepositoryFactoryImpl</code> implements a repository factory that
  * creates a {@link TransientRepository} on {@link #getRepository(Map)}.
  */
-public class RepositoryFactoryImpl implements RepositoryFactory {
+public class RepositoryFactoryImpl implements JackrabbitRepositoryFactory {
 
     /**
      * Name of the repository home parameter.
@@ -49,6 +52,11 @@
      */
     private static final Map<String, JackrabbitRepository> REPOSITORY_INSTANCES = new
HashMap<String, JackrabbitRepository>();
 
+    /**
+     * The repository instances that were created by this factory.
+     */
+    private final Set<TransientRepository> ownRepositories = new HashSet<TransientRepository>();
+
     public Repository getRepository(Map parameters) throws RepositoryException {
         JackrabbitRepository repo;
         synchronized (REPOSITORY_INSTANCES) {
@@ -91,8 +99,19 @@
                 tr = new TransientRepository(conf, home);
             }
             REPOSITORY_INSTANCES.put(tr.getHomeDir(), tr);
+            ownRepositories.add(tr);
             repo = tr;
         }
         return repo;
     }
+
+    public RepositoryManager getRepositoryManager(JackrabbitRepository repo) throws RepositoryException
{
+        if (repo instanceof TransientRepository) {
+            throw new RepositoryException("The repository was not created in this factory");
+        }
+        if (!ownRepositories.contains(repo)) {
+            throw new RepositoryException("The repository was not created in this factory");
+        }
+        return new RepositoryManagerImpl((TransientRepository) repo);
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Tue Sep 15 14:16:24 2009
@@ -34,8 +34,6 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.Iterator;
-import java.util.concurrent.Executors;
-import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -1181,7 +1179,7 @@
         // wake up threads waiting on this instance's monitor (e.g. workspace janitor)
         notifyAll();
 
-        // Shut down the executor service 
+        // Shut down the executor service
         executor.shutdown();
         try {
             // Wait for all remaining background threads to terminate

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryManagerImpl.java?rev=815340&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryManagerImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryManagerImpl.java
Tue Sep 15 14:16:24 2009
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core;
+
+import java.util.ArrayList;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.RepositoryManager;
+import org.apache.jackrabbit.core.RepositoryImpl.WorkspaceInfo;
+import org.apache.jackrabbit.core.data.GarbageCollector;
+import org.apache.jackrabbit.core.persistence.IterablePersistenceManager;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
+import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
+
+/**
+ * The repository manager implementation.
+ */
+public class RepositoryManagerImpl implements RepositoryManager {
+
+    private final TransientRepository tr;
+
+    RepositoryManagerImpl(TransientRepository tr) {
+        this.tr = tr;
+    }
+
+    public DataStoreGarbageCollector createDataStoreGarbageCollector() throws RepositoryException
{
+        RepositoryImpl rep = tr.getRepository();
+        if (rep == null) {
+            throw new RepositoryException("Repository is stopped");
+        }
+        ArrayList<PersistenceManager> pmList = new ArrayList<PersistenceManager>();
+        InternalVersionManagerImpl vm = (InternalVersionManagerImpl) rep.getVersionManager();
+        PersistenceManager pm = vm.getPersistenceManager();
+        pmList.add(pm);
+        String[] wspNames = rep.getWorkspaceNames();
+        Session[] sessions = new Session[wspNames.length];
+        for (int i = 0; i < wspNames.length; i++) {
+            String wspName = wspNames[i];
+            WorkspaceInfo wspInfo = rep.getWorkspaceInfo(wspName);
+            // this will initialize the workspace if required
+            SessionImpl session = SystemSession.create(rep, wspInfo.getConfig());
+            // mark this session as 'active' so the workspace does not get disposed
+            // by the workspace-janitor until the garbage collector is done
+            rep.onSessionCreated(session);
+            // the workspace could be disposed again, so re-initialize if required
+            // afterwards it will not be disposed because a session is registered
+            wspInfo.initialize();
+            sessions[i] = session;
+            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(null, ipmList, sessions);
+        return gc;
+    }
+
+    public void stop() {
+        tr.shutdown();
+    }
+
+}

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
Tue Sep 15 14:16:24 2009
@@ -418,4 +418,13 @@
     public void loggingOut(SessionImpl session) {
     }
 
+    /**
+     * Get the current repository.
+     *
+     * @return the repository
+     */
+    RepositoryImpl getRepository() {
+        return repository;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Tue Sep 15 14:16:24 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.RepositoryImpl;
@@ -32,7 +34,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -64,20 +65,25 @@
  * <p>
  * Example code to run the data store garbage collection:
  * <pre>
- * GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
- * gc.scan();
- * gc.stopScan();
- * gc.deleteUnused();
+ * JackrabbitRepositoryFactory jf = (JackrabbitRepositoryFactory) factory;
+ * RepositoryManager m = factory.getRepositoryManager((JackrabbitRepository) rep);
+ * GarbageCollector gc = m.createDataStoreGarbageCollector();
+ * try {
+ *     gc.mark();
+ *     gc.sweep();
+ * } finally {
+ *     gc.close();
+ * }
  * </pre>
  */
-public class GarbageCollector {
+public class GarbageCollector implements DataStoreGarbageCollector {
 
     /** logger instance */
     private static final Logger LOG = LoggerFactory.getLogger(GarbageCollector.class);
 
-    private ScanEventListener callback;
+    private MarkEventListener callback;
 
-    private int sleepBetweenNodes;
+    private long sleepBetweenNodes;
 
     private int testDelay;
 
@@ -90,14 +96,12 @@
     private final IterablePersistenceManager[] pmList;
 
     private final Session[] sessionList;
-    private final SessionListener sessionListener;
+    private SessionListener sessionListener;
 
     private final AtomicBoolean closed = new AtomicBoolean();
 
     private boolean persistenceManagerScan;
 
-    // TODO It should be possible to stop and restart a garbage collection scan.
-
     /**
      * Create a new garbage collector.
      * This method is usually not called by the application, it is called
@@ -114,28 +118,27 @@
         this.persistenceManagerScan = list != null;
         this.sessionList = sessionList;
 
-        // Auto-close if the main session logs out
-        this.sessionListener = new SessionListener() {
-            public void loggedOut(SessionImpl session) {
-            }
-            public void loggingOut(SessionImpl session) {
-                close();
-            }
-        };
-        session.addListener(sessionListener);
+        if (session != null) {
+            // Auto-close if the main session logs out
+            this.sessionListener = new SessionListener() {
+                public void loggedOut(SessionImpl session) {
+                }
+                public void loggingOut(SessionImpl session) {
+                    close();
+                }
+            };
+            session.addListener(sessionListener);
+        }
     }
 
-    /**
-     * 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.
-     *
-     * @param millis the number of milliseconds to sleep
-     */
-    public void setSleepBetweenNodes(int millis) {
+    public void setSleepBetweenNodes(long millis) {
         this.sleepBetweenNodes = millis;
     }
 
+    public long getSleepBetweenNodes() {
+        return sleepBetweenNodes;
+    }
+
     /**
      * When testing the garbage collection, a delay is used instead of simulating concurrent
access.
      *
@@ -146,29 +149,24 @@
     }
 
     /**
-     * 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.
-     *
-     * @param callback if set, this is called while scanning
+     * @deprecated use setMarkEventListener().
      */
     public void setScanEventListener(ScanEventListener callback) {
+        setMarkEventListener(callback);
+    }
+
+    public void setMarkEventListener(MarkEventListener callback) {
         this.callback = callback;
     }
 
     /**
-     * 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 will be used; if not, the garbage
-     * collector will scan the repository using the JCR API starting from the root node.
-     *
-     * @throws RepositoryException
-     * @throws IllegalStateException
-     * @throws IOException
-     * @throws ItemStateException
+     * @deprecated use mark().
      */
-    public void scan() throws RepositoryException,
-            IllegalStateException, IOException, ItemStateException {
+    public void scan() throws RepositoryException {
+        mark();
+    }
+
+    public void mark() throws RepositoryException {
         if (store == null) {
             throw new RepositoryException("No DataStore configured.");
         }
@@ -183,12 +181,15 @@
                 scanNodes(s);
             }
         } else {
-            scanPersistenceManagers();
+            try {
+                scanPersistenceManagers();
+            } catch (ItemStateException e) {
+                throw new RepositoryException(e);
+            }
         }
     }
 
-    private void scanNodes(Session session)
-        throws RepositoryException, IllegalStateException, IOException {
+    private void scanNodes(Session session) throws RepositoryException {
 
         // add a listener to get 'new' nodes
         // actually, new nodes are not the problem, but moved nodes
@@ -199,28 +200,22 @@
         recurse(session.getRootNode(), sleepBetweenNodes);
     }
 
-    /**
-     * 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.
-     *
-     * @param allow true if using the IterablePersistenceManager interface is allowed
-     */
     public void setPersistenceManagerScan(boolean allow) {
         persistenceManagerScan = allow;
     }
 
+    public boolean isPersistenceManagerScan() {
+        return persistenceManagerScan;
+    }
+
     /**
-     * Check if using the IterablePersistenceManager interface is allowed.
-     *
-     * @return true if using IterablePersistenceManager is possible.
+     * @deprecated use isPersistenceManagerScan().
      */
     public boolean getPersistenceManagerScan() {
-        return persistenceManagerScan;
+        return isPersistenceManagerScan();
     }
 
-    private void scanPersistenceManagers() throws ItemStateException, RepositoryException
{
+    private void scanPersistenceManagers() throws RepositoryException, ItemStateException
{
         for (IterablePersistenceManager pm : pmList) {
             for (NodeId id : pm.getAllNodeIds(null, 0)) {
                 if (callback != null) {
@@ -244,50 +239,39 @@
                     // the node may have been deleted or moved in the meantime
                     // ignore it
                 }
-                if (callback != null) {
-                    callback.afterScanning(null);
-                }
             }
         }
     }
 
     /**
-     * The repository was scanned. This method will stop the observation
-     * listener.
+     * Stop the observation listener if any are installed.
      */
     public void stopScan() throws RepositoryException {
-        checkScanStarted();
-        for (Listener listener : listeners) {
-            try {
-                listener.stop();
-            } catch (Exception e) {
-                throw new RepositoryException(e);
+        if (listeners.size() > 0) {
+            for (Listener listener : listeners) {
+                try {
+                    listener.stop();
+                } catch (Exception e) {
+                    throw new RepositoryException(e);
+                }
             }
+            listeners.clear();
         }
-        listeners.clear();
     }
 
     /**
-     * Delete all unused items in the data store.
-     *
-     * @return the number of deleted items
+     * @deprecated use sweep().
      */
     public int deleteUnused() throws RepositoryException {
-        checkScanStarted();
-        checkScanStopped();
-        return store.deleteAllOlderThan(startScanTimestamp);
+        return sweep();
     }
 
-    private void checkScanStarted() throws RepositoryException {
+    public int sweep() throws RepositoryException {
         if (startScanTimestamp == 0) {
             throw new RepositoryException("scan must be called first");
         }
-    }
-
-    private void checkScanStopped() throws RepositoryException {
-        if (listeners.size() > 0) {
-            throw new RepositoryException("stopScan must be called first");
-        }
+        stopScan();
+        return store.deleteAllOlderThan(startScanTimestamp);
     }
 
     /**
@@ -299,8 +283,7 @@
         return store;
     }
 
-    private void recurse(final Node n, int sleep) throws RepositoryException,
-            IllegalStateException, IOException {
+    private void recurse(final Node n, long sleep) throws RepositoryException {
         if (sleep > 0) {
             try {
                 Thread.sleep(sleep);
@@ -334,9 +317,6 @@
         } catch (InvalidItemStateException e) {
             LOG.debug("Node removed concurrently - ignoring", e);
         }
-        if (callback != null) {
-            callback.afterScanning(n);
-        }
         try {
             for (NodeIterator it = n.getNodes(); it.hasNext();) {
                 recurse(it.nextNode(), sleep);
@@ -382,11 +362,13 @@
          */
     }
 
-    /**
-     * Cleanup resources used internally by this instance.
-     */
     public void close() {
         if (!closed.getAndSet(true)) {
+            try {
+                stopScan();
+            } catch (RepositoryException e) {
+                LOG.warn("An error occured when stopping the event listener", e);
+            }
             for (Session s : sessionList) {
                 s.logout();
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/ScanEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/ScanEventListener.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/ScanEventListener.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/ScanEventListener.java
Tue Sep 15 14:16:24 2009
@@ -16,28 +16,11 @@
  */
 package org.apache.jackrabbit.core.data;
 
-import java.util.EventListener;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 
 /**
  * The listener interface for receiving garbage collection scan events.
  */
-public interface ScanEventListener extends EventListener {
-
-    /**
-     * This method is called before a node is scanned.
-     */
-    void beforeScanning(Node n) throws RepositoryException;
-
-    /**
-     * This method is called after a node is scanned.
-     */
-    void afterScanning(Node n) throws RepositoryException;
+public interface ScanEventListener extends MarkEventListener {
 
-    /**
-     * This method is called when the garbage collection scan is finished.
-     */
-    void done();
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCConcurrentTest.java
Tue Sep 15 14:16:24 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
@@ -52,22 +54,19 @@
         final String testNodeName = "testConcurrentDelete";
         node(root, testNodeName);
         session.save();
-        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
         gc.setPersistenceManagerScan(false);
-        gc.setScanEventListener(new ScanEventListener() {
+        gc.setMarkEventListener(new MarkEventListener() {
             public void beforeScanning(Node n) throws RepositoryException {
                 if (n.getName().equals(testNodeName)) {
                     n.remove();
                     n.getSession().save();
                 }
             }
-            public void afterScanning(Node n) throws RepositoryException {
-            }
-            public void done() {
-            }
+
         });
-        gc.scan();
-        gc.stopScan();
+        gc.mark();
+        gc.close();
     }
 
     public void testGC() throws Exception {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCEventListenerTest.java
Tue Sep 15 14:16:24 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.slf4j.Logger;
@@ -35,17 +37,17 @@
  *
  * @author Thomas Mueller
  */
-public class GCEventListenerTest extends AbstractJCRTest implements ScanEventListener {
+public class GCEventListenerTest extends AbstractJCRTest implements MarkEventListener {
 
     /** logger instance */
     private static final Logger LOG = LoggerFactory.getLogger(GCEventListenerTest.class);
 
+    private static final String TEST_NODE_NAME = "testGCEventListener";
+
     private boolean gotNullNode;
     private boolean gotNode;
     private int count;
 
-    private static final String TEST_NODE_NAME = "testGCEventListener";
-
     public void testEventListener() throws Exception {
         doTestEventListener(true);
         doTestEventListener(false);
@@ -74,16 +76,16 @@
         }
         session.save();
         SessionImpl si = (SessionImpl) session;
-        GarbageCollector gc = si.createDataStoreGarbageCollector();
-        if (gc.getDataStore() != null) {
-            gc.getDataStore().clearInUse();
-            boolean pmScan = gc.getPersistenceManagerScan();
+        DataStoreGarbageCollector gc = si.createDataStoreGarbageCollector();
+        DataStore ds = ((GarbageCollector) gc).getDataStore();
+        if (ds != null) {
+            ds.clearInUse();
+            boolean pmScan = gc.isPersistenceManagerScan();
             gc.setPersistenceManagerScan(allowPmScan);
             gotNullNode = false;
             gotNode = false;
-            gc.setScanEventListener(this);
-            gc.scan();
-            gc.stopScan();
+            gc.setMarkEventListener(this);
+            gc.mark();
             if (pmScan && allowPmScan) {
                 assertTrue("PM scan without null Node", gotNullNode);
                 assertFalse("PM scan, but got a real node", gotNode);
@@ -91,7 +93,7 @@
                 assertFalse("Not a PM scan - but got a null Node", gotNullNode);
                 assertTrue("Not a PM scan - without a real node", gotNode);
             }
-            int deleted = gc.deleteUnused();
+            int deleted = gc.sweep();
             LOG.debug("Deleted " + deleted);
             assertTrue("Should delete at least one item", deleted >= 0);
             gc.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCThread.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCThread.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCThread.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GCThread.java
Tue Sep 15 14:16:24 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,7 +31,7 @@
 /**
  * Helper class that runs data store garbage collection as a background thread.
  */
-public class GCThread implements Runnable, ScanEventListener {
+public class GCThread implements Runnable, MarkEventListener {
 
     /** logger instance */
     private static final Logger LOG = LoggerFactory.getLogger(GCThread.class);
@@ -45,15 +47,16 @@
     public void run() {
 
         try {
-            GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
-            gc.setScanEventListener(this);
+            GarbageCollector gc = ((SessionImpl) session)
+                    .createDataStoreGarbageCollector();
+            gc.setMarkEventListener(this);
             while (!stop) {
                 LOG.debug("Scanning...");
-                gc.scan();
+                gc.mark();
                 int count = listIdentifiers(gc);
                 LOG.debug("Stop; currently " + count + " identifiers");
                 gc.stopScan();
-                int numDeleted = gc.deleteUnused();
+                int numDeleted = gc.sweep();
                 if (numDeleted > 0) {
                     LOG.debug("Deleted " + numDeleted + " identifiers");
                 }
@@ -75,8 +78,9 @@
         return exception;
     }
 
-    private int listIdentifiers(GarbageCollector gc) throws DataStoreException {
-        Iterator<DataIdentifier> it = gc.getDataStore().getAllIdentifiers();
+    private int listIdentifiers(DataStoreGarbageCollector gc) throws DataStoreException {
+        DataStore ds = ((GarbageCollector) gc).getDataStore();
+        Iterator<DataIdentifier> it = ds.getAllIdentifiers();
         int count = 0;
         while (it.hasNext()) {
             DataIdentifier id = it.next();

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java?rev=815340&r1=815339&r2=815340&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
Tue Sep 15 14:16:24 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.data;
 
+import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
+import org.apache.jackrabbit.api.management.MarkEventListener;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
@@ -48,22 +50,15 @@
             LOG.info("testConcurrentClose skipped. Data store is not used.");
             return;
         }
-        final GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        final DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
         final Exception[] ex = new Exception[1];
-        gc.setScanEventListener(new ScanEventListener() {
+        gc.setMarkEventListener(new MarkEventListener() {
             boolean closed;
 
-            public void afterScanning(Node n) throws RepositoryException {
-                closeTest();
-            }
-
             public void beforeScanning(Node n) throws RepositoryException {
                 closeTest();
             }
 
-            public void done() {
-            }
-
             private void closeTest() throws RepositoryException {
                 if (closed) {
                     ex[0] = new Exception("Scanning after the session is closed");
@@ -74,7 +69,7 @@
 
         });
         try {
-            gc.scan();
+            gc.mark();
             fail("Exception 'session has been closed' expected");
         } catch (RepositoryException e) {
             LOG.debug("Expected exception caught: " + e.getMessage());
@@ -127,10 +122,9 @@
             }
         }.start();
         assertEquals("x", sync.take());
-        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
-        gc.scan();
-        gc.stopScan();
-        gc.deleteUnused();
+        DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        gc.mark();
+        gc.sweep();
         sync.put("deleted");
         assertEquals("saved", sync.take());
         InputStream in = node.getProperty("slowBlob").getBinary().getStream();
@@ -176,13 +170,13 @@
         }
 
         LOG.debug("scanning...");
-        gc.scan();
+        gc.mark();
         int count = listIdentifiers(gc);
         LOG.debug("stop scanning; currently " + count + " identifiers");
         gc.stopScan();
         LOG.debug("deleting...");
         gc.getDataStore().clearInUse();
-        assertTrue(gc.deleteUnused() > 0);
+        assertTrue(gc.sweep() > 0);
         int count2 = listIdentifiers(gc);
         assertEquals(count - 1, count2);
 
@@ -193,17 +187,17 @@
 
     private void runGC(Session session, boolean all) throws Exception {
         GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
-        gc.setScanEventListener(this);
+        gc.setMarkEventListener(this);
         if (gc.getDataStore() instanceof FileDataStore) {
             // make sure the file is old (access time resolution is 2 seconds)
             Thread.sleep(2000);
         }
-        gc.scan();
+        gc.mark();
         gc.stopScan();
         if (all) {
             gc.getDataStore().clearInUse();
         }
-        gc.deleteUnused();
+        gc.sweep();
         gc.close();
     }
 



Mime
View raw message