jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r789796 - in /jackrabbit/branches/1.x: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Date Tue, 30 Jun 2009 15:28:40 GMT
Author: jukka
Date: Tue Jun 30 15:28:40 2009
New Revision: 789796

URL: http://svn.apache.org/viewvc?rev=789796&view=rev
Log:
1.x: Merged revision 779084 (JCR-2106)

Modified:
    jackrabbit/branches/1.x/   (props changed)
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java

Propchange: jackrabbit/branches/1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 30 15:28:40 2009
@@ -1 +1 @@
-/jackrabbit/trunk:770143-773197,773483,773525-773554,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081
+/jackrabbit/trunk:770143-773197,773483,773525-773554,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081,779084

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=789796&r1=789795&r2=789796&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Tue Jun 30 15:28:40 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.SessionListener;
 import org.apache.jackrabbit.core.observation.SynchronousEventListener;
 import org.apache.jackrabbit.core.persistence.IterablePersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateException;
@@ -33,6 +34,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jcr.Item;
 import javax.jcr.Node;
@@ -83,6 +85,9 @@
     private final IterablePersistenceManager[] pmList;
 
     private final Session[] sessionList;
+    private final SessionListener sessionListener;
+    
+    private final AtomicBoolean closed = new AtomicBoolean();
 
     private boolean persistenceManagerScan;
 
@@ -93,7 +98,9 @@
      * This method is usually not called by the application, it is called
      * by SessionImpl.createDataStoreGarbageCollector().
      *
+     * @param session the session that created this object
      * @param list the persistence managers
+     * @param sessionList the sessions to access the workspaces
      */
     public GarbageCollector(SessionImpl session, IterablePersistenceManager[] list, Session[]
sessionList) {
         RepositoryImpl rep = (RepositoryImpl) session.getRepository();
@@ -101,6 +108,16 @@
         this.pmList = list;
         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);
     }
 
     /**
@@ -233,6 +250,10 @@
         }
     }
 
+    /**
+     * The repository was scanned. This method will stop the observation
+     * listener.
+     */
     public void stopScan() throws RepositoryException {
         checkScanStarted();
         for (int i = 0; i < listeners.size(); i++) {
@@ -246,6 +267,11 @@
         listeners.clear();
     }
 
+    /**
+     * Delete all unused items in the data store.
+     * 
+     * @return the number of deleted items
+     */
     public int deleteUnused() throws RepositoryException {
         checkScanStarted();
         checkScanStopped();
@@ -264,6 +290,11 @@
         }
     }
 
+    /**
+     * Get the data store if one is used.
+     * 
+     * @return the data store, or null
+     */
     public DataStore getDataStore() {
         return store;
     }
@@ -332,9 +363,31 @@
          *
          * We can't use node path for this, UUIDs are required as nodes could be
          * moved around.
+         * 
+         * This mechanism requires that all data stores update the last modified 
+         * date when calling addRecord and that record already exists.
          *
          */
     }
+    
+    /**
+     * Cleanup resources used internally by this instance.
+     */
+    public void close() {
+        if (!closed.getAndSet(true)) {
+            for (int i = 0; i < sessionList.length; i++) {
+                sessionList[i].logout();
+            }
+        }
+    }
+
+    /**
+     * Auto-close in case the application didn't call it explicitly.
+     */
+    protected void finalize() throws Throwable {
+        close();
+        super.finalize();
+    }
 
     /**
      * Event listener to detect moved nodes.



Mime
View raw message