changeset 1694:e0297fc99e80

Synchronize access to DocuImage.identify() from Manifester calls. This is maximally synchronized at the DocuDirCache level.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Mon, 10 Dec 2018 20:03:59 +0100
parents dbe534cdb5f6
children ca28745836c1
files common/src/main/java/digilib/io/BaseDirDocuDirectory.java common/src/main/java/digilib/io/DocuDirCache.java common/src/main/java/digilib/io/ImageFile.java iiif-presentation/src/main/java/digilib/servlet/Manifester.java
diffstat 4 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/digilib/io/BaseDirDocuDirectory.java	Sat Apr 07 20:05:20 2018 +0200
+++ b/common/src/main/java/digilib/io/BaseDirDocuDirectory.java	Mon Dec 10 20:03:59 2018 +0100
@@ -77,7 +77,7 @@
     }
 
     @Override
-	public synchronized boolean readDir() {
+	public boolean readDir() {
 		// check directory first
 		if (!isValid) {
 			return false;
--- a/common/src/main/java/digilib/io/DocuDirCache.java	Sat Apr 07 20:05:20 2018 +0200
+++ b/common/src/main/java/digilib/io/DocuDirCache.java	Mon Dec 10 20:03:59 2018 +0100
@@ -167,7 +167,7 @@
 	 *            file index
 	 * @return
 	 */
-	public DocuDirent getFile(String fn, int in) {
+	public synchronized DocuDirent getFile(String fn, int in) {
 		DocuDirectory dd;
 		// file number is 1-based, vector index is 0-based
 		int n = in - 1;
@@ -182,8 +182,9 @@
 			dd = DocuDirectoryFactory.getDocuDirectoryInstance(fn, fileClass);
 			if (dd.isValid()) {
 			    // add to the cache
+			    dd = putDir(dd);
+				// check/read contents
 			    dd.refresh();
-			    dd = putDir(dd);
 			} else {
 				/*
 				 * maybe it's a file
@@ -198,9 +199,9 @@
 					dd = DocuDirectoryFactory.getDocuDirectoryInstance(d, fileClass);
 					if (dd.isValid()) {
 						// add to the cache
-                        // logger.debug(dd + " is valid");
+						dd = putDir(dd);
+						// check/read contents
 					    dd.refresh();
-						dd = putDir(dd);
 					} else {
 						// invalid path
 						return null;
@@ -236,7 +237,7 @@
 	 *            digilib pathname
 	 * @return
 	 */
-	public DocuDirectory getDirectory(String fn) {
+	public synchronized DocuDirectory getDirectory(String fn) {
 		DocuDirectory dd;
 		// first, assume fn is a directory and look in the cache
 		dd = map.get(fn);
@@ -247,8 +248,8 @@
 			dd = DocuDirectoryFactory.getDocuDirectoryInstance(fn, fileClass);
 			if (dd.isValid()) {
 			    // add to the cache
+			    dd = putDir(dd);
                 dd.refresh();
-			    dd = putDir(dd);
 			} else {
 				// try the parent directory in the cache
 				String pn = FileOps.parent(fn);
@@ -258,8 +259,8 @@
 					dd = DocuDirectoryFactory.getDocuDirectoryInstance(pn, fileClass);
 					if (dd.isValid()) {
 						// add to the cache
+						dd = putDir(dd);
 		                dd.refresh();
-						dd = putDir(dd);
 					} else {
 						// invalid path
 						return null;
--- a/common/src/main/java/digilib/io/ImageFile.java	Sat Apr 07 20:05:20 2018 +0200
+++ b/common/src/main/java/digilib/io/ImageFile.java	Mon Dec 10 20:03:59 2018 +0100
@@ -79,7 +79,7 @@
 	/** Checks the image and sets size and type.
 	 * 
 	 */
-	public void check() {
+	public synchronized void check() {
 	    if (pixelSize == null) {
 	        try {
 	            // use the configured toolkit to identify the image
--- a/iiif-presentation/src/main/java/digilib/servlet/Manifester.java	Sat Apr 07 20:05:20 2018 +0200
+++ b/iiif-presentation/src/main/java/digilib/servlet/Manifester.java	Mon Dec 10 20:03:59 2018 +0100
@@ -157,7 +157,7 @@
      * Returns modification time relevant to the request for caching.
      * 
      * @see javax.servlet.http.HttpServlet#getLastModified(javax.servlet.http.HttpServletRequest)
-     */
+     *
     public long getLastModified(HttpServletRequest request) {
         accountlog.debug("GetLastModified from " + request.getRemoteAddr() + " for " + request.getQueryString());
         long mtime = -1;
@@ -182,7 +182,7 @@
         }
         logger.debug("  returns " + mtime);
         return mtime;
-    }
+    } */
 
 	/*
 	 * (non-Javadoc)