Author: sannegrinovero
Date: 2008-06-16 11:08:45 -0400 (Mon, 16 Jun 2008)
New Revision: 14769
Modified:
search/trunk/src/java/org/hibernate/search/reader/ReaderProviderHelper.java
search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java
Log:
moved IndexReader extraction from SharedReaderProvider to
ReaderProviderHelper.getSubReadersFromMultiReader
Modified: search/trunk/src/java/org/hibernate/search/reader/ReaderProviderHelper.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/ReaderProviderHelper.java 2008-06-15
14:39:42 UTC (rev 14768)
+++ search/trunk/src/java/org/hibernate/search/reader/ReaderProviderHelper.java 2008-06-16
15:08:45 UTC (rev 14769)
@@ -2,10 +2,12 @@
package org.hibernate.search.reader;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiSearcher;
import org.apache.lucene.search.Searchable;
@@ -15,6 +17,28 @@
* @author Emmanuel Bernard
*/
public abstract class ReaderProviderHelper {
+
+ private static final Field subReadersField = getSubReadersField();
+
+ private static Field getSubReadersField() {
+ try {
+ Field field = MultiReader.class.getDeclaredField( "subReaders" );
+ if ( ! field.isAccessible() ) field.setAccessible( true );
+ return field;
+ }
+ catch (NoSuchFieldException e) {
+ throw new SearchException( "Incompatible version of Lucene:
MultiReader.subReaders not available", e );
+ }
+ }
+
+ public static IndexReader[] getSubReadersFromMultiReader(MultiReader parentReader) {
+ try {
+ return (IndexReader[]) subReadersField.get( parentReader );
+ } catch (IllegalAccessException e) {
+ throw new SearchException( "Incompatible version of Lucene:
MultiReader.subReaders not accessible", e );
+ }
+ }
+
@SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
public static IndexReader buildMultiReader(int length, IndexReader[] readers) {
if ( length == 0 ) {
Modified: search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java 2008-06-15
14:39:42 UTC (rev 14768)
+++ search/trunk/src/java/org/hibernate/search/reader/SharedReaderProvider.java 2008-06-16
15:08:45 UTC (rev 14769)
@@ -2,7 +2,6 @@
package org.hibernate.search.reader;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -28,7 +27,6 @@
* @author Emmanuel Bernard
*/
public class SharedReaderProvider implements ReaderProvider {
- private static Field subReadersField;
private final Logger log = LoggerFactory.getLogger ( SharedReaderProvider.class );
/**
* nonfair lock. Need to be acquired on indexReader acquisition or release (semaphore)
@@ -151,7 +149,7 @@
if ( outOfDateReader != null ) {
ReaderData readerData = searchIndexReaderSemaphores.get( outOfDateReader );
if ( readerData == null ) {
- closeOutOfDateReader = false; //already removed by another prevous thread
+ closeOutOfDateReader = false; //already removed by another previous thread
}
else if ( readerData.semaphore == 0 ) {
searchIndexReaderSemaphores.remove( outOfDateReader );
@@ -211,12 +209,7 @@
IndexReader[] readers;
//TODO should it be CacheableMultiReader? Probably no
if ( reader instanceof MultiReader ) {
- try {
- readers = (IndexReader[]) subReadersField.get( reader );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Incompatible version of Lucene:
MultiReader.subReaders not accessible", e );
- }
+ readers = ReaderProviderHelper.getSubReadersFromMultiReader( (MultiReader) reader );
if ( trace ) log.trace( "Closing MultiReader: {}", reader );
}
else {
@@ -289,15 +282,6 @@
}
public void initialize(Properties props, SearchFactoryImplementor
searchFactoryImplementor) {
- if ( subReadersField == null ) {
- try {
- subReadersField = MultiReader.class.getDeclaredField( "subReaders" );
- if ( !subReadersField.isAccessible() ) subReadersField.setAccessible( true );
- }
- catch (NoSuchFieldException e) {
- throw new SearchException( "Incompatible version of Lucene:
MultiReader.subReaders not accessible", e );
- }
- }
Set<DirectoryProvider> providers =
searchFactoryImplementor.getLockableDirectoryProviders().keySet();
perDirectoryProviderManipulationLocks = new HashMap<DirectoryProvider, Lock>(
providers.size() );
for (DirectoryProvider dp : providers) {
Show replies by date