incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1188465 - in /incubator/lcf/trunk: connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
Date Tue, 25 Oct 2011 00:31:35 GMT
Author: kwright
Date: Tue Oct 25 00:31:35 2011
New Revision: 1188465

URL: http://svn.apache.org/viewvc?rev=1188465&view=rev
Log:
Reduce the scope of synchronizers so that we don't single-thread file operations.  Part of
CONNECTORS-281.

Modified:
    incubator/lcf/trunk/connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java

Modified: incubator/lcf/trunk/connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java?rev=1188465&r1=1188464&r2=1188465&view=diff
==============================================================================
--- incubator/lcf/trunk/connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java
(original)
+++ incubator/lcf/trunk/connectors/rss/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/rss/DataCache.java
Tue Oct 25 00:31:35 2011
@@ -124,13 +124,14 @@ public class DataCache
           os.close();
         }
 
+        deleteData(documentIdentifier);
+        
         synchronized(this)
         {
-          deleteData(documentIdentifier);
           cacheData.put(documentIdentifier,new DocumentData(tempFile,contentType));
-          return checkSum;
         }
-
+        
+        return checkSum;
       }
       catch (IOException e)
       {
@@ -170,10 +171,14 @@ public class DataCache
   *@param documentIdentifier is the document identifier.
   *@return the length.
   */
-  public synchronized long getDataLength(String documentIdentifier)
+  public long getDataLength(String documentIdentifier)
     throws ManifoldCFException
   {
-    DocumentData f = cacheData.get(documentIdentifier);
+    DocumentData f;
+    synchronized (this)
+    {
+      f = cacheData.get(documentIdentifier);
+    }
     if (f == null)
       return 0L;
     return f.getData().length();
@@ -183,10 +188,14 @@ public class DataCache
   *@param documentIdentifier is the document identifier (url).
   *@return a binary data stream.
   */
-  public synchronized InputStream getData(String documentIdentifier)
+  public InputStream getData(String documentIdentifier)
     throws ManifoldCFException
   {
-    DocumentData f = cacheData.get(documentIdentifier);
+    DocumentData f;
+    synchronized (this)
+    {
+      f = cacheData.get(documentIdentifier);
+    }
     if (f == null)
       return null;
     try
@@ -203,9 +212,13 @@ public class DataCache
   *@param documentIdentifier is the document identifier.
   *@return the content type, or null if there is none.
   */
-  public synchronized String getContentType(String documentIdentifier)
+  public String getContentType(String documentIdentifier)
   {
-    DocumentData dd = cacheData.get(documentIdentifier);
+    DocumentData dd;
+    synchronized (this)
+    {
+      dd = cacheData.get(documentIdentifier);
+    }
     if (dd == null)
       return null;
     return dd.getContentType();
@@ -214,10 +227,13 @@ public class DataCache
   /** Delete specified item of data.
   *@param documentIdentifier is the document identifier (url).
   */
-  public synchronized void deleteData(String documentIdentifier)
+  public void deleteData(String documentIdentifier)
   {
-    DocumentData f = cacheData.get(documentIdentifier);
-    cacheData.remove(documentIdentifier);
+    DocumentData f;
+    synchronized (this)
+    {
+      f = cacheData.remove(documentIdentifier);
+    }
     if (f != null)
     {
       ManifoldCF.deleteFile(f.getData());

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java?rev=1188465&r1=1188464&r2=1188465&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
Tue Oct 25 00:31:35 2011
@@ -1164,7 +1164,7 @@ public class ManifoldCF
   protected static class FileTrack implements IShutdownHook
   {
     /** Key and value are both File objects */
-    protected HashMap filesToDelete = new HashMap();
+    protected Map<File,File> filesToDelete = new HashMap<File,File>();
 
     /** Constructor */
     public FileTrack()
@@ -1172,17 +1172,25 @@ public class ManifoldCF
     }
 
     /** Add a file to track */
-    public synchronized void addFile(File f)
+    public void addFile(File f)
     {
-      filesToDelete.put(f,f);
+      synchronized (this)
+      {
+        filesToDelete.put(f,f);
+      }
     }
 
     /** Delete a file */
-    public synchronized void deleteFile(File f)
+    public void deleteFile(File f)
     {
+      // Because we never reuse file names, it is OK to delete twice.
+      // So the delete() can be outside the synchronizer.
       f.delete();
-      filesToDelete.remove(f);
-    }
+      synchronized (this)
+      {
+        filesToDelete.remove(f);
+      }
+  }
 
     /** Delete all remaining files */
     public void doCleanup()



Mime
View raw message