Mark, did you intend to add Apache License to this file? On Sat, Mar 20, 2010 at 10:57 AM, <markrmil...@apache.org> wrote: > Author: markrmiller > Date: Sat Mar 20 14:57:28 2010 > New Revision: 925620 > > URL: http://svn.apache.org/viewvc?rev=925620&view=rev > Log: > Change to RefCntRamDirectory rather than RamDirectory > > Added: > > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RefCntRamDirectory.java > Modified: > > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RAMDirectoryFactory.java > > Modified: > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RAMDirectoryFactory.java > URL: > http://svn.apache.org/viewvc/lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RAMDirectoryFactory.java?rev=925620&r1=925619&r2=925620&view=diff > ============================================================================== > --- > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RAMDirectoryFactory.java > (original) > +++ > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RAMDirectoryFactory.java > Sat Mar 20 14:57:28 2010 > @@ -29,15 +29,17 @@ import java.util.HashMap; > * Directory provider for using lucene RAMDirectory > */ > public class RAMDirectoryFactory extends StandardDirectoryFactory { > - private Map<String, Directory> directories = new HashMap<String, > Directory>(); > + private Map<String, RefCntRamDirectory> directories = new HashMap<String, > RefCntRamDirectory>(); > > @Override > public Directory open(String path) throws IOException { > synchronized (this) { > - Directory directory = directories.get(path); > - if (directory == null) { > - directory = openNew(path); > + RefCntRamDirectory directory = directories.get(path); > + if (directory == null || !directory.isOpen()) { > + directory = (RefCntRamDirectory) openNew(path); > directories.put(path, directory); > + } else { > + directory.incRef(); > } > > return directory; > @@ -53,9 +55,9 @@ public class RAMDirectoryFactory extends > boolean indexExists = dirFile.canRead(); > if (indexExists) { > Directory dir = super.open(path); > - directory = new RAMDirectory(dir); > + directory = new RefCntRamDirectory(dir); > } else { > - directory = new RAMDirectory(); > + directory = new RefCntRamDirectory(); > } > return directory; > } > > Added: > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RefCntRamDirectory.java > URL: > http://svn.apache.org/viewvc/lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RefCntRamDirectory.java?rev=925620&view=auto > ============================================================================== > --- > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RefCntRamDirectory.java > (added) > +++ > lucene/solr/branches/newtrunk/solr/src/java/org/apache/solr/core/RefCntRamDirectory.java > Sat Mar 20 14:57:28 2010 > @@ -0,0 +1,46 @@ > +package org.apache.solr.core; > + > +import java.io.IOException; > +import java.util.concurrent.atomic.AtomicInteger; > + > +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(); > + } > + > + 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) { > + close(); > + } > + } > + > + public final synchronized void close() { > + if (isOpen) { > + decRef(); > + super.close(); > + } > + } > + > + public boolean isOpen() { > + return isOpen; > + } > + > +} > > >
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org