[infinispan-commits] Infinispan SVN: r2293 - branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Sep 1 12:54:50 EDT 2010
Author: sannegrinovero
Date: 2010-09-01 12:54:50 -0400 (Wed, 01 Sep 2010)
New Revision: 2293
Modified:
branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/FileListOperations.java
branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java
Log:
[ISPN-625] (Lucene Directory's methods length, filemodified, touch should return 0L instead of FileNotFoundException for unexistent files) - branch 4.1
Modified: branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/FileListOperations.java
===================================================================
--- branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/FileListOperations.java 2010-09-01 10:54:54 UTC (rev 2292)
+++ branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/FileListOperations.java 2010-09-01 16:54:50 UTC (rev 2293)
@@ -52,9 +52,14 @@
*/
Set<String> getFileList() {
Set<String> fileList = (Set<String>) cache.withFlags(Flag.SKIP_LOCKING).get(fileListCacheKey);
- if (fileList == null)
+ if (fileList == null) {
fileList = new ConcurrentHashSet<String>();
- return fileList;
+ Set<String> prev = (Set<String>) cache.putIfAbsent(fileListCacheKey, fileList);
+ return prev == null ? fileList : prev;
+ }
+ else {
+ return fileList;
+ }
}
/**
@@ -83,15 +88,11 @@
/**
* @param fileName
- * @return the FileMetadata associated with the fileName
- * @throws FileNotFoundException if the metadata was not found
+ * @return the FileMetadata associated with the fileName, or null if the file wasn't found.
*/
FileMetadata getFileMetadata(String fileName) throws FileNotFoundException {
FileCacheKey key = new FileCacheKey(indexName, fileName);
FileMetadata metadata = (FileMetadata) cache.withFlags(Flag.SKIP_LOCKING).get(key);
- if (metadata == null) {
- throw new FileNotFoundException(fileName);
- }
return metadata;
}
Modified: branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java
===================================================================
--- branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java 2010-09-01 10:54:54 UTC (rev 2292)
+++ branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java 2010-09-01 16:54:50 UTC (rev 2293)
@@ -158,7 +158,13 @@
*/
public long fileModified(String name) throws IOException {
checkIsOpen();
- return fileOps.getFileMetadata(name).getLastModified();
+ FileMetadata fileMetadata = fileOps.getFileMetadata(name);
+ if (fileMetadata == null) {
+ return 0L;
+ }
+ else {
+ return fileMetadata.getLastModified();
+ }
}
/**
@@ -166,13 +172,15 @@
*/
public void touchFile(String fileName) throws IOException {
checkIsOpen();
- FileCacheKey key = new FileCacheKey(indexName, fileName);
- FileMetadata file = (FileMetadata) cache.get(key);
+ FileMetadata file = fileOps.getFileMetadata(fileName);
if (file == null) {
- throw new FileNotFoundException(fileName);
+ return;
}
- file.touch();
- cache.put(key, file);
+ else {
+ FileCacheKey key = new FileCacheKey(indexName, fileName);
+ file.touch();
+ cache.put(key, file);
+ }
}
/**
@@ -226,7 +234,13 @@
*/
public long fileLength(String name) throws IOException {
checkIsOpen();
- return fileOps.getFileMetadata(name).getSize();
+ FileMetadata fileMetadata = fileOps.getFileMetadata(name);
+ if (fileMetadata == null) {
+ return 0L;//as in FSDirectory (RAMDirectory throws an exception instead)
+ }
+ else {
+ return fileMetadata.getSize();
+ }
}
/**
More information about the infinispan-commits
mailing list