LUCENE-2778: port from 3x

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1039156 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2010-11-25 19:42:50 +00:00
parent 66c8234469
commit b57c84611b
2 changed files with 16 additions and 5 deletions

View File

@ -161,6 +161,9 @@ API Changes
* LUCENE-2566: QueryParser: Unary operators +,-,! will not be treated as
operators if they are followed by whitespace. (yonik)
* LUCENE-2778: RAMDirectory now exposes newRAMFile() which allows to override
and return a different RAMFile implementation. (Shai Erera)
New features
* LUCENE-2604: Added RegexpQuery support to QueryParser. Regular expressions

View File

@ -35,8 +35,8 @@ public class RAMDirectory extends Directory implements Serializable {
private static final long serialVersionUID = 1l;
HashMap<String,RAMFile> fileMap = new HashMap<String,RAMFile>();
final AtomicLong sizeInBytes = new AtomicLong();
protected HashMap<String,RAMFile> fileMap = new HashMap<String,RAMFile>();
protected final AtomicLong sizeInBytes = new AtomicLong();
// *****
// Lock acquisition sequence: RAMDirectory, then RAMFile
@ -169,9 +169,8 @@ public class RAMDirectory extends Directory implements Serializable {
@Override
public synchronized void deleteFile(String name) throws IOException {
ensureOpen();
RAMFile file = fileMap.get(name);
RAMFile file = fileMap.remove(name);
if (file!=null) {
fileMap.remove(name);
file.directory = null;
sizeInBytes.addAndGet(-file.sizeInBytes);
} else
@ -182,7 +181,7 @@ public class RAMDirectory extends Directory implements Serializable {
@Override
public IndexOutput createOutput(String name) throws IOException {
ensureOpen();
RAMFile file = new RAMFile(this);
RAMFile file = newRAMFile();
synchronized (this) {
RAMFile existing = fileMap.get(name);
if (existing!=null) {
@ -194,6 +193,15 @@ public class RAMDirectory extends Directory implements Serializable {
return new RAMOutputStream(file);
}
/**
* Returns a new {@link RAMFile} for storing data. This method can be
* overridden to return different {@link RAMFile} impls, that e.g. override
* {@link RAMFile#newBuffer(int)}.
*/
protected RAMFile newRAMFile() {
return new RAMFile(this);
}
/** Returns a stream reading an existing file. */
@Override
public IndexInput openInput(String name) throws IOException {