Author: hardy.ferentschik
Date: 2010-10-14 08:56:59 -0400 (Thu, 14 Oct 2010)
New Revision: 20831
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/Worker.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java
Log:
HSEARCH-554 Some formatting and javadoc changes while working on the documentation of the
worker configuration
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-10-14
11:08:07 UTC (rev 20830)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/BackendQueueProcessorFactory.java 2010-10-14
12:56:59 UTC (rev 20831)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.backend;
@@ -40,7 +39,7 @@
/**
* Used at startup, called once as first method.
* @param props all configuration properties
- * @param searchFactory the client
+ * @param context context giving access to required meta data
*/
void initialize(Properties props, WorkerBuildContext context);
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Worker.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Worker.java 2010-10-14
11:08:07 UTC (rev 20830)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/Worker.java 2010-10-14
12:56:59 UTC (rev 20831)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.backend;
@@ -29,15 +28,16 @@
import org.hibernate.search.spi.WorkerBuildContext;
/**
- * Perform work for a given session. This implementation has to be multi threaded.
+ * Perform work for a given context (eg a transaction). This implementation has to be
threaded-safe.
*
* @author Emmanuel Bernard
*/
public interface Worker {
/**
* Declare a work to be done within a given transaction context
- * @param work
- * @param transactionContext
+ *
+ * @param work the work to be executed
+ * @param transactionContext transactional context information
*/
void performWork(Work<?> work, TransactionContext transactionContext);
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2010-10-14
11:08:07 UTC (rev 20830)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java 2010-10-14
12:56:59 UTC (rev 20831)
@@ -42,10 +42,9 @@
Properties props = cfg.getProperties();
Properties workerProperties = new Properties();
for ( Map.Entry entry : props.entrySet() ) {
- String key = ( String ) entry.getKey();
+ String key = (String) entry.getKey();
if ( key.startsWith( Environment.WORKER_PREFIX ) ) {
- //key.substring( Environment.WORKER_PREFIX.length() )
- workerProperties.setProperty( key, ( String ) entry.getValue() );
+ workerProperties.setProperty( key, (String) entry.getValue() );
}
}
return workerProperties;
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-10-14
11:08:07 UTC (rev 20830)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2010-10-14
12:56:59 UTC (rev 20831)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.backend.impl;
@@ -43,13 +42,13 @@
public class PostTransactionWorkQueueSynchronization implements Synchronization {
private static final Logger log = LoggerFactory.make();
-
+
/**
* FullTextIndexEventListener is using a
WeakIdentityHashMap<Session,Synchronization>
* So make sure all Synchronization implementations don't have any
* (direct or indirect) reference to the Session.
*/
-
+
private final QueueingProcessor queueingProcessor;
private boolean consumed;
private boolean prepared;
@@ -75,14 +74,16 @@
public void beforeCompletion() {
if ( prepared ) {
if ( log.isTraceEnabled() ) {
- log.trace("Transaction's beforeCompletion() phase already been processed,
ignoring: {}", this.toString() );
+ log.trace(
+ "Transaction's beforeCompletion() phase already been processed, ignoring:
{}", this.toString()
+ );
}
}
else {
if ( log.isTraceEnabled() ) {
- log.trace("Processing Transaction's beforeCompletion() phase: {}",
this.toString() );
+ log.trace( "Processing Transaction's beforeCompletion() phase: {}",
this.toString() );
}
- queueingProcessor.prepareWorks(queue);
+ queueingProcessor.prepareWorks( queue );
prepared = true;
}
}
@@ -91,22 +92,30 @@
try {
if ( Status.STATUS_COMMITTED == i ) {
if ( log.isTraceEnabled() ) {
- log.trace("Processing Transaction's afterCompletion() phase for {}.
Performing work.", this.toString() );
+ log.trace(
+ "Processing Transaction's afterCompletion() phase for {}. Performing
work.", this.toString()
+ );
}
- queueingProcessor.performWorks(queue);
+ queueingProcessor.performWorks( queue );
}
else {
if ( log.isTraceEnabled() ) {
- log.trace("Processing Transaction's afterCompletion() phase for {}.
Cancelling work due to transaction status {}", this.toString(), i );
+ log.trace(
+ "Processing Transaction's afterCompletion() phase for {}. Cancelling work
due to transaction status {}",
+ this.toString(),
+ i
+ );
}
- queueingProcessor.cancelWorks(queue);
+ queueingProcessor.cancelWorks( queue );
}
}
finally {
consumed = true;
//clean the Synchronization per Transaction
//not needed stricto sensus but a cleaner approach and faster than the GC
- if (queuePerTransaction != null) queuePerTransaction.removeValue( this );
+ if ( queuePerTransaction != null ) {
+ queuePerTransaction.removeValue( this );
+ }
}
}
Modified:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
---
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2010-10-14
11:08:07 UTC (rev 20830)
+++
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2010-10-14
12:56:59 UTC (rev 20831)
@@ -1,26 +1,25 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors
as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat, Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors
as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
*/
package org.hibernate.search.backend.impl;
@@ -30,13 +29,13 @@
import org.slf4j.Logger;
import org.hibernate.search.SearchException;
-import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.TransactionContext;
import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.Worker;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.util.HibernateHelper;
import org.hibernate.search.util.LoggerFactory;
import org.hibernate.search.util.WeakIdentityHashMap;
@@ -47,15 +46,15 @@
* <p/>
* When <code>hibernate.search.worker.type</code> is set to
<code>async</code>
* the work is done in a separate thread (threads are pooled)
- *
+ *
* @author Emmanuel Bernard
*/
public class TransactionalWorker implements Worker {
-
+
//note: there is one Worker instance per SearchFactory, reused concurrently for all
sessions.
-
+
private static final Logger log = LoggerFactory.make();
-
+
//this is being used from different threads, but doesn't need a
//synchronized map since for a given transaction, we have not concurrent access
protected final WeakIdentityHashMap<Object, Synchronization>
synchronizationPerTransaction = new WeakIdentityHashMap<Object, Synchronization>();
@@ -65,12 +64,12 @@
public void performWork(Work<?> work, TransactionContext transactionContext) {
final Class<?> entityType = HibernateHelper.getClassFromWork( work );
if ( factory.getDocumentBuilderIndexedEntity( entityType ) == null
- && factory.getDocumentBuilderContainedEntity( entityType ) == null ) {
- throw new SearchException( "Unable to perform work. Entity Class is not @Indexed
nor hosts @ContainedIn: " + entityType);
+ && factory.getDocumentBuilderContainedEntity( entityType ) == null ) {
+ throw new SearchException( "Unable to perform work. Entity Class is not @Indexed
nor hosts @ContainedIn: " + entityType );
}
if ( transactionContext.isTransactionInProgress() ) {
Object transactionIdentifier = transactionContext.getTransactionIdentifier();
- PostTransactionWorkQueueSynchronization txSync = (
PostTransactionWorkQueueSynchronization )
+ PostTransactionWorkQueueSynchronization txSync =
(PostTransactionWorkQueueSynchronization)
synchronizationPerTransaction.get( transactionIdentifier );
if ( txSync == null || txSync.isConsumed() ) {
txSync = new PostTransactionWorkQueueSynchronization(
@@ -84,8 +83,10 @@
else {
// this is a workaround: isTransactionInProgress should return "true"
// for correct configurations.
- log.warn( "It appears changes are being pushed to the index out of a transaction.
" +
- "Register the IndexWorkFlushEventListener listener on flush to correctly manage
Collections!" );
+ log.warn(
+ "It appears changes are being pushed to the index out of a transaction. "
+
+ "Register the IndexWorkFlushEventListener listener on flush to correctly
manage Collections!"
+ );
WorkQueue queue = new WorkQueue( 2 ); //one work can be split
queueingProcessor.add( work, queue );
queueingProcessor.prepareWorks( queue );
@@ -105,12 +106,11 @@
public void flushWorks(TransactionContext transactionContext) {
if ( transactionContext.isTransactionInProgress() ) {
Object transaction = transactionContext.getTransactionIdentifier();
- PostTransactionWorkQueueSynchronization txSync = (
PostTransactionWorkQueueSynchronization )
+ PostTransactionWorkQueueSynchronization txSync =
(PostTransactionWorkQueueSynchronization)
synchronizationPerTransaction.get( transaction );
if ( txSync != null && !txSync.isConsumed() ) {
txSync.flushWorks();
}
}
}
-
}