Author: epbernard
Date: 2010-06-30 09:40:44 -0400 (Wed, 30 Jun 2010)
New Revision: 19865
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jgroups/JGroupsBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/SharingBufferReaderProvider.java
Log:
HSEARCH-397 Add contract on backend to update the list of directory providers
Also clarify mutability requirements for SharingBufferReaderProvider
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -26,8 +26,10 @@
import java.util.Properties;
import java.util.List;
+import java.util.Set;
import org.hibernate.search.spi.WorkerBuildContext;
+import org.hibernate.search.store.DirectoryProvider;
/**
* Interface for different types of queue processor factories. Implementations need a
no-arg constructor.
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java
(rev 0)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -0,0 +1,20 @@
+package org.hibernate.search.backend;
+
+import java.util.Set;
+
+import org.hibernate.search.spi.WorkerBuildContext;
+import org.hibernate.search.store.DirectoryProvider;
+
+/**
+ * Experimental
+ * Allow a BackendQueueProcessorFactory to be notified of DiurectoryProvider changes
+ *
+ * @author Emmanuel Bernard
+ */
+public interface UpdatableBackendQueueProcessorFactory extends
BackendQueueProcessorFactory {
+ /**
+ * Update the list of <code>DirectoryProvider</code>s in case the
SearchFactory is updated.
+ * The processor factory should react and update its state accordingly.
+ */
+ void updateDirectoryProviders(Set<DirectoryProvider<?>> providers,
WorkerBuildContext context);
+}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/blackhole/BlackHoleBackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -26,10 +26,12 @@
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.util.LoggerFactory;
import org.slf4j.Logger;
@@ -56,7 +58,11 @@
// no-op
log.warn( "initialized \"blackhole\" backend. Index changes will be
prepared but discarded!" );
}
-
+
+ public void updateDirectoryProviders(Set<DirectoryProvider<?>> providers) {
+ log.warn( "update DirectoryProviders \"blackhole\" backend. Index
changes will be prepared but discarded!" );
+ }
+
public void close() {
// no-op
log.info( "closed \"blackhole\" backend." );
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jgroups/JGroupsBackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jgroups/JGroupsBackendQueueProcessorFactory.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jgroups/JGroupsBackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -27,6 +27,7 @@
import java.net.URL;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import org.jgroups.Address;
import org.jgroups.Channel;
@@ -40,6 +41,7 @@
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.util.LoggerFactory;
import org.hibernate.search.util.XMLHelper;
import org.hibernate.util.ConfigHelper;
@@ -77,6 +79,10 @@
prepareJGroupsChannel( props );
}
+ public void updateDirectoryProviders(Set<DirectoryProvider<?>> providers) {
+ //nothing to do here. The DirectoryProviders are not used
+ }
+
private void prepareJGroupsChannel(Properties props) {
log.info( "Starting JGroups Channel" );
try {
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
@@ -39,6 +40,7 @@
import org.hibernate.search.SearchException;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.store.DirectoryProvider;
/**
* @author Emmanuel Bernard
@@ -61,6 +63,10 @@
prepareJMSTools();
}
+ public void updateDirectoryProviders(Set<DirectoryProvider<?>> providers,
WorkerBuildContext context) {
+ //nothing to do here, this backend is not sensible to directory providers
+ }
+
public Runnable getProcessor(List<LuceneWork> queue) {
return new JMSBackendQueueProcessor( queue, this );
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessorFactory.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -28,7 +28,9 @@
import java.util.Map;
import java.util.Properties;
import java.util.List;
+import java.util.Set;
+import org.hibernate.search.SearchException;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneWork;
@@ -57,7 +59,8 @@
* lifecycle (reused and shared by all transactions);
* the LuceneWorkVisitor(s) are stateless, the Workspace(s) are threadsafe.
*/
- private final Map<DirectoryProvider,PerDPResources> resourcesMap = new
HashMap<DirectoryProvider,PerDPResources>();
+ private final Map<DirectoryProvider<?>,PerDPResources> resourcesMap =
+ new HashMap<DirectoryProvider<?>,PerDPResources>();
/**
* copy of BatchedQueueingProcessor.sync
@@ -73,6 +76,23 @@
}
}
+ public void updateDirectoryProviders( Set<DirectoryProvider<?>> providers,
WorkerBuildContext context ) {
+ Map<DirectoryProvider<?>,PerDPResources> newResourceMap =
+ new HashMap<DirectoryProvider<?>, PerDPResources>(resourcesMap);
+ for ( DirectoryProvider<?> provider : providers ) {
+ if ( ! resourcesMap.containsKey( provider ) ) {
+ PerDPResources resources = new PerDPResources( context, provider );
+ newResourceMap.put( provider, resources );
+ }
+ }
+ //TODO we could shut them down
+ for ( DirectoryProvider<?> provider : resourcesMap.keySet() ) {
+ if ( ! newResourceMap.containsKey( provider ) ) {
+ throw new SearchException("DirectoryProvider no longer present during
SearchFactory update" );
+ }
+ }
+ }
+
public Runnable getProcessor(List<LuceneWork> queue) {
return new LuceneBackendQueueProcessor( queue, searchFactoryImp, resourcesMap, sync );
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/SharingBufferReaderProvider.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/SharingBufferReaderProvider.java 2010-06-30
13:39:58 UTC (rev 19864)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/SharingBufferReaderProvider.java 2010-06-30
13:40:44 UTC (rev 19865)
@@ -140,7 +140,8 @@
Directory directory = directoryProviders[index].getDirectory();
log.trace( "Opening IndexReader from {}", directory );
PerDirectoryLatestReader directoryLatestReader = currentReaders.get( directory );
- if ( directoryLatestReader == null ) { // might eg happen for
FSSlaveDirectoryProvider
+ // might eg happen for FSSlaveDirectoryProvider or for mutable SearchFactory
+ if ( directoryLatestReader == null ) {
directoryLatestReader = createReader( directory );
}
readers[index] = directoryLatestReader.refreshAndGet();