[hibernate-commits] Hibernate SVN: r11479 - in trunk/HibernateExt/search/src/java/org/hibernate/search/backend: impl and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon May 7 21:16:40 EDT 2007
Author: epbernard
Date: 2007-05-07 21:16:39 -0400 (Mon, 07 May 2007)
New Revision: 11479
Added:
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/WorkQueue.java
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/LuceneWork.java
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/QueueingProcessor.java
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
Log:
HSEARCH-44 build the Lucene Document before the transaction completion
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/LuceneWork.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/LuceneWork.java 2007-05-08 00:58:54 UTC (rev 11478)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/LuceneWork.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -11,6 +11,7 @@
* @author Emmanuel Bernard
*/
public abstract class LuceneWork implements Serializable {
+ //TODO set a serial id
private Document document;
private Class entityClass;
private Serializable id;
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/QueueingProcessor.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/QueueingProcessor.java 2007-05-08 00:58:54 UTC (rev 11478)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/QueueingProcessor.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -11,6 +11,8 @@
* No thread safety has to be implemented, the queue being scoped already
* The implementation must be "stateless" wrt the queue through (ie not store the queue state)
*
+ * FIXME this Interface does not make much sense, since the impl will not be changed
+ *
* @author Emmanuel Bernard
*/
public interface QueueingProcessor {
@@ -18,17 +20,20 @@
* Add a work
* TODO move that womewhere else, it does not really fit here
*/
- void add(Object entity, Serializable id, WorkType workType, List<Work> queue);
+ void add(Object entity, Serializable id, WorkType workType, WorkQueue workQueue);
/**
+ * prepare resources for a later performWorks call
+ */
+ void prepareWorks(WorkQueue workQueue);
+
+ /**
* Execute works
- * @param queue
*/
- void performWork(List<Work> queue);
+ void performWorks(WorkQueue workQueue);
/**
* Rollback works
- * @param queue
*/
- void cancelWork(List<Work> queue);
+ void cancelWorks(WorkQueue workQueue);
}
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/WorkQueue.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/WorkQueue.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/WorkQueue.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -0,0 +1,52 @@
+//$Id: $
+package org.hibernate.search.backend;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.hibernate.annotations.common.AssertionFailure;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class WorkQueue {
+ //TODO set a serial number
+ private List<Work> queue;
+
+ private List<LuceneWork> sealedQueue;
+
+ public WorkQueue(int size) {
+ queue = new ArrayList<Work>(size);
+ }
+
+ public WorkQueue() {
+ this(10);
+ }
+
+
+ public void add(Work work) {
+ queue.add(work);
+ }
+
+
+ public List<Work> getQueue() {
+ return queue;
+ }
+
+
+ public List<LuceneWork> getSealedQueue() {
+ if (sealedQueue == null) throw new AssertionFailure("Access a Sealed WorkQueue whcih has not been sealed");
+ return sealedQueue;
+ }
+
+ public void setSealedQueue(List<LuceneWork> sealedQueue) {
+ //invalidate the working queue for serializability
+ queue = null;
+ this.sealedQueue = sealedQueue;
+ }
+
+ public void clear() {
+ queue.clear();
+ if (sealedQueue != null) sealedQueue.clear();
+ }
+}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-05-08 00:58:54 UTC (rev 11478)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -21,12 +21,13 @@
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.impl.jms.JMSBackendQueueProcessorFactory;
import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
import org.hibernate.search.engine.DocumentBuilder;
/**
- * Batch work until #performWork is called.
+ * Batch work until #performWorks is called.
* The work is then executed synchronously or asynchronously
*
* @author Emmanuel Bernard
@@ -91,17 +92,17 @@
searchFactory.setBackendQueueProcessorFactory( backendQueueProcessorFactory );
}
- public void add(Object entity, Serializable id, WorkType workType, List<Work> queue) {
- //don't check for builder it's done in performWork
+ public void add(Object entity, Serializable id, WorkType workType, WorkQueue workQueue) {
+ //don't check for builder it's done in performWorks
Work work = new Work(entity, id, workType);
- queue.add( work );
+ workQueue.add( work );
}
- //TODO implements parallel batchWorkers (one per Directory)
- public void performWork(List<Work> queue) {
+
+ public void prepareWorks(WorkQueue workQueue) {
+ List<Work> queue = workQueue.getQueue();
int initialSize = queue.size();
List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize ); //TODO load factor for containedIn
-
for ( int i = 0 ; i < initialSize ; i++ ) {
Work work = queue.get( i );
queue.set( i, null ); // help GC and avoid 2 loaded queues in memory
@@ -110,8 +111,13 @@
if ( builder == null ) return; //or exception?
builder.addWorkToQueue(work.getEntity(), work.getId(), work.getType(), luceneQueue, searchFactory);
}
+ workQueue.setSealedQueue( luceneQueue );
+ }
- Runnable processor = backendQueueProcessorFactory.getProcessor( luceneQueue );
+ //TODO implements parallel batchWorkers (one per Directory)
+ public void performWorks(WorkQueue workQueue) {
+
+ Runnable processor = backendQueueProcessorFactory.getProcessor( workQueue.getSealedQueue() );
if ( sync ) {
processor.run();
}
@@ -120,8 +126,8 @@
}
}
- public void cancelWork(List<Work> queue) {
- queue.clear();
+ public void cancelWorks(WorkQueue workQueue) {
+ workQueue.clear();
}
@Override
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-05-08 00:58:54 UTC (rev 11478)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -8,9 +8,9 @@
import javax.transaction.Synchronization;
import org.hibernate.search.backend.QueueingProcessor;
-import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.util.WeakIdentityHashMap;
/**
@@ -22,7 +22,7 @@
private QueueingProcessor queueingProcessor;
private boolean consumed;
private WeakIdentityHashMap queuePerTransaction;
- private List<Work> queue = new ArrayList<Work>();
+ private WorkQueue queue = new WorkQueue();
/**
* in transaction work
@@ -41,15 +41,16 @@
}
public void beforeCompletion() {
+ queueingProcessor.prepareWorks(queue);
}
public void afterCompletion(int i) {
try {
if ( Status.STATUS_COMMITTED == i ) {
- queueingProcessor.performWork(queue);
+ queueingProcessor.performWorks(queue);
}
else {
- queueingProcessor.cancelWork(queue);
+ queueingProcessor.cancelWorks(queue);
}
}
finally {
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-05-08 00:58:54 UTC (rev 11478)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-05-08 01:16:39 UTC (rev 11479)
@@ -7,10 +7,10 @@
import java.io.Serializable;
import org.hibernate.search.backend.Worker;
-import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.impl.BatchedQueueingProcessor;
import org.hibernate.search.util.WeakIdentityHashMap;
import org.hibernate.search.SearchFactory;
@@ -44,9 +44,10 @@
txSync.add( entity, id, workType );
}
else {
- List<Work> queue = new ArrayList<Work>(2); //one work can be split
+ WorkQueue queue = new WorkQueue(2); //one work can be split
queueingProcessor.add( entity, id, workType, queue );
- queueingProcessor.performWork( queue );
+ queueingProcessor.prepareWorks( queue );
+ queueingProcessor.performWorks( queue );
}
}
More information about the hibernate-commits
mailing list