[Swift-commit] r2103 - trunk/src/org/griphyn/vdl/karajan/lib/cache

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Jul 9 14:48:48 CDT 2008


Author: hategan
Date: 2008-07-09 14:48:48 -0500 (Wed, 09 Jul 2008)
New Revision: 2103

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java
   trunk/src/org/griphyn/vdl/karajan/lib/cache/Site.java
   trunk/src/org/griphyn/vdl/karajan/lib/cache/VDLFileCache.java
Log:
added getFiles and getPaths methods

Modified: trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java	2008-07-09 18:18:48 UTC (rev 2102)
+++ trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java	2008-07-09 19:48:48 UTC (rev 2103)
@@ -3,6 +3,8 @@
  */
 package org.griphyn.vdl.karajan.lib.cache;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -17,22 +19,22 @@
 		Site s = getSite(entry.getHost());
 		return s.addFile(entry);
 	}
-	
+
 	public synchronized CacheReturn addAndLockEntry(File entry) {
 		Site s = getSite(entry.getHost());
 		return s.addAndLockFile(entry);
 	}
-	
+
 	public CacheReturn entryRemoved(File f) {
 		Site s = getSite(f.getHost());
 		return s.fileRemoved(f);
 	}
-	
+
 	public CacheReturn unlockEntry(File f, boolean force) {
 		Site s = getSite(f.getHost());
 		return s.unlockEntry(f, force);
 	}
-	
+
 	public CacheReturn unlockFromProcessing(File f) {
 		Site s = getSite(f.getHost());
 		return s.unlockFromProcessing(f);
@@ -48,4 +50,28 @@
 			return site;
 		}
 	}
+
+	public Collection getFiles(Object host) {
+		synchronized (sites) {
+			Site site = (Site) sites.get(host);
+			if (site == null) {
+				return Collections.EMPTY_LIST;
+			}
+			else {
+				return site.getFiles();
+			}
+		}
+	}
+	
+	public Collection getPaths(Object host) {
+		synchronized(sites) {
+			Site site = (Site) sites.get(host);
+			if (site == null) {
+				return Collections.EMPTY_LIST;
+			}
+			else {
+				return site.getPaths();
+			}
+		}
+	}
 }

Modified: trunk/src/org/griphyn/vdl/karajan/lib/cache/Site.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/cache/Site.java	2008-07-09 18:18:48 UTC (rev 2102)
+++ trunk/src/org/griphyn/vdl/karajan/lib/cache/Site.java	2008-07-09 19:48:48 UTC (rev 2103)
@@ -4,6 +4,7 @@
 package org.griphyn.vdl.karajan.lib.cache;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -157,4 +158,12 @@
 		usage = targetUsage;
 		return l;
 	}
+	
+	public synchronized Collection getFiles() {
+		return new ArrayList(files.entrySet());
+	}
+	
+	public synchronized Collection getPaths() {
+		return new ArrayList(files.keySet());
+	}
 }

Modified: trunk/src/org/griphyn/vdl/karajan/lib/cache/VDLFileCache.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/cache/VDLFileCache.java	2008-07-09 18:18:48 UTC (rev 2102)
+++ trunk/src/org/griphyn/vdl/karajan/lib/cache/VDLFileCache.java	2008-07-09 19:48:48 UTC (rev 2103)
@@ -3,6 +3,8 @@
  */
 package org.griphyn.vdl.karajan.lib.cache;
 
+import java.util.Collection;
+
 /**
  * Describes a client caching mechanism. Classes implementing this interface
  * would not deal with the actual physical data processing required to move data
@@ -11,45 +13,47 @@
  * 
  * The logical flow of the process is as follows:
  * <ol>
- * 	<li> The client code wants to cache an entry
- * 	<li> The client code calls <code>addAndLockEntry</code> with the respective
- * 		entry. This will lock the entry for both usage and processing. The
- * 		<code>addAndLockEntry</code> method returns a <code>CacheReturn</code>
- * 		object (let's call it <code>status</code>), which can signal a few things:
+ * <li> The client code wants to cache an entry
+ * <li> The client code calls <code>addAndLockEntry</code> with the respective
+ * entry. This will lock the entry for both usage and processing. The
+ * <code>addAndLockEntry</code> method returns a <code>CacheReturn</code>
+ * object (let's call it <code>status</code>), which can signal a few things:
  * 
- * 		<ol>
- * 			<li> If the entry is already cached, then <code>status.alreadyCached</code>
- * 				will be <code>true</code>, and <code>status.cached</code> will contain
- * 				the cached entry. The client code should check then if the already cached
- * 				entry is locked for processing by calling the
- * 				<code>isLockedForProcessing</code> method, and:
- * 				<ol>
- * 					<li> If the entry is locked for processing, the client code should add a
- * 						listener to the entry in order to get notified when the processing is
- * 						complete (<code>status.cached.addProcessingListener</code>). Upon receipt
- * 						of notification of processing completion, the client code should retry
- * 						calling the addAndLockEntry, since the processing may have involved the
- * 						removal of the file from the cache.
- * 					<li> If the entry is not locked for processing, the client code can assume
- * 						that the entry is correctly present in the physical cache
- * 				</ol>
- * 			<li> If the entry is not cached (<code>status.alreadyCached</code> is <code>false</code>), 
- * 				then the client code must physically put the entry into the cache, after which it 
- * 				shoult call <code>unlockFromProcessing</code>
- * 			<li> Removal requests are listed in the <code>status.remove</code> list. The entries
- * 				returned must be already locked for processing by the cache implementation, in 
- * 				order to prevent them from being used by other threads. 
- * 				The application code should physically remove such entries from the cache, and 
- * 				then call <code>fileRemoved</code>.
- * 		</ol> 
- * 	<li> The client code uses the cached data
- * 	<li> The client code calls <code>unlockEntry</code> to signal that the data is not needed by the
- * 		application any more, and it can eventually be removed from the cache
+ * <ol>
+ * <li> If the entry is already cached, then <code>status.alreadyCached</code>
+ * will be <code>true</code>, and <code>status.cached</code> will contain
+ * the cached entry. The client code should check then if the already cached
+ * entry is locked for processing by calling the
+ * <code>isLockedForProcessing</code> method, and:
+ * <ol>
+ * <li> If the entry is locked for processing, the client code should add a
+ * listener to the entry in order to get notified when the processing is
+ * complete (<code>status.cached.addProcessingListener</code>). Upon receipt
+ * of notification of processing completion, the client code should retry
+ * calling the addAndLockEntry, since the processing may have involved the
+ * removal of the file from the cache.
+ * <li> If the entry is not locked for processing, the client code can assume
+ * that the entry is correctly present in the physical cache
  * </ol>
+ * <li> If the entry is not cached (<code>status.alreadyCached</code> is
+ * <code>false</code>), then the client code must physically put the entry
+ * into the cache, after which it shoult call <code>unlockFromProcessing</code>
+ * <li> Removal requests are listed in the <code>status.remove</code> list.
+ * The entries returned must be already locked for processing by the cache
+ * implementation, in order to prevent them from being used by other threads.
+ * The application code should physically remove such entries from the cache,
+ * and then call <code>fileRemoved</code>.
+ * </ol>
+ * <li> The client code uses the cached data
+ * <li> The client code calls <code>unlockEntry</code> to signal that the data
+ * is not needed by the application any more, and it can eventually be removed
+ * from the cache
+ * </ol>
  * 
- * Alternatively, the <code>addEntry</code> method can be used to add an entry to the cache without
- * locking it in any way. This is intended for cases when the client code does not have direct control
- * over what goes into the physical cache.
+ * Alternatively, the <code>addEntry</code> method can be used to add an entry
+ * to the cache without locking it in any way. This is intended for cases when
+ * the client code does not have direct control over what goes into the physical
+ * cache.
  */
 public interface VDLFileCache {
 	/**
@@ -99,4 +103,16 @@
 	 * the entry was locked for being removed).
 	 */
 	CacheReturn unlockFromProcessing(File f);
+
+	/**
+	 * Returns a collection of {@link File} objects representing the files
+	 * stored in the cache for the specified host
+	 */
+	Collection getFiles(Object host);
+
+	/**
+	 * Returns a collection of {@link String} objects representing the file
+	 * paths stored in the cache for the specified host
+	 */
+	Collection getPaths(Object host);
 }




More information about the Swift-commit mailing list