git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/branches/newtrunk@925626 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2010-03-20 15:15:34 +00:00
parent a75151efd5
commit aa9b85c260
1 changed files with 8 additions and 10 deletions

View File

@ -7,37 +7,35 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
public class RefCntRamDirectory extends RAMDirectory {
private final AtomicInteger refCount = new AtomicInteger();
public RefCntRamDirectory() {
super();
incRef();
refCount.set(1);
}
public RefCntRamDirectory(Directory dir) throws IOException {
this();
Directory.copy(dir, this, false);
}
public void incRef() {
ensureOpen();
refCount.incrementAndGet();
}
public void decRef() {
ensureOpen();
if (refCount.getAndDecrement() == 1) {
super.close();
}
}
public final synchronized void close() {
if (isOpen) {
decRef();
}
decRef();
}
public boolean isOpen() {
return isOpen;
}