mirror of https://github.com/apache/lucene.git
tweaks
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/branches/newtrunk@925626 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a75151efd5
commit
aa9b85c260
|
@ -7,37 +7,35 @@ import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
|
|
||||||
public class RefCntRamDirectory extends RAMDirectory {
|
public class RefCntRamDirectory extends RAMDirectory {
|
||||||
|
|
||||||
private final AtomicInteger refCount = new AtomicInteger();
|
private final AtomicInteger refCount = new AtomicInteger();
|
||||||
|
|
||||||
public RefCntRamDirectory() {
|
public RefCntRamDirectory() {
|
||||||
super();
|
super();
|
||||||
incRef();
|
refCount.set(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefCntRamDirectory(Directory dir) throws IOException {
|
public RefCntRamDirectory(Directory dir) throws IOException {
|
||||||
this();
|
this();
|
||||||
Directory.copy(dir, this, false);
|
Directory.copy(dir, this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incRef() {
|
public void incRef() {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
refCount.incrementAndGet();
|
refCount.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decRef() {
|
public void decRef() {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
if (refCount.getAndDecrement() == 1) {
|
if (refCount.getAndDecrement() == 1) {
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final synchronized void close() {
|
public final synchronized void close() {
|
||||||
if (isOpen) {
|
decRef();
|
||||||
decRef();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return isOpen;
|
return isOpen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue