[hibernate-commits] Hibernate SVN: r19179 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/exception/impl and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Apr 6 16:34:27 EDT 2010


Author: sannegrinovero
Date: 2010-04-06 16:34:27 -0400 (Tue, 06 Apr 2010)
New Revision: 19179

Removed:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java
Modified:
   search/trunk/hibernate-search/src/main/docbook/en-US/modules/configuration.xml
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
Log:
HSEARCH-421 Exceptions happening in backend are unnoticed (Amin Mohammed-Coleman)

Modified: search/trunk/hibernate-search/src/main/docbook/en-US/modules/configuration.xml
===================================================================
--- search/trunk/hibernate-search/src/main/docbook/en-US/modules/configuration.xml	2010-04-06 18:29:09 UTC (rev 19178)
+++ search/trunk/hibernate-search/src/main/docbook/en-US/modules/configuration.xml	2010-04-06 20:34:27 UTC (rev 19179)
@@ -1160,4 +1160,46 @@
 
      
   </section>
+
+  <section>
+    <title>Exception Handling Configuration</title>
+
+    <para>Hibernate Search allows you to configure how exceptions are handled
+    during the indexing process. If no configuration is provided then
+    exceptions are logged to the log output by default. It is possible to
+    explicitly declare the exception logging mechanism as seen below:</para>
+
+    <para><programlisting>hibernate.search.error_handler log</programlisting>The
+    default exception handling occurs for both synchronous and asynchronous
+    indexing. Hibernate Search provides an easy mechanism to override the
+    default error handling implementation.</para>
+
+    <para>In order to provide your own implementation you must implement the
+    <code>ErrorHandler</code> interface, which provides <code>handle (
+    ErrorContext context )</code> method. The <code>ErrorContext</code>
+    provides a reference to the primary <code>LuceneWork</code> that failed, the
+    underlying exception and any subsequent <code>LuceneWork</code> that could
+    not be processed due to the primary exception.</para>
+
+    <para><programlisting>public interface ErrorContext  {
+   List&lt;LuceneWork&gt; getFailingOperations();
+   LuceneWork getOperationAtFault();
+   Throwable getThrowable();
+   boolean hasErrors();
+}</programlisting></para>
+
+    <para>The following provides an example implementation of
+    <code>ErrorHandler</code>:</para>
+
+    <para><programlisting>public class CustomErrorHandler implements ErrorHandler {
+   public void handle ( ErrorContext context ) {
+      ...
+      //publish error context to some internal error handling system
+      ...
+   }
+}</programlisting>To register this error handler with Hibernate Search you
+    must declare the <code>CustomErrorHandler</code> fully qualified classname
+    in the configuration properties:</para>
+    <para><programlisting>hibernate.search.error_handler CustomerErrorHandler</programlisting></para>
+  </section>
 </chapter>
\ No newline at end of file

Deleted: search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java	2010-04-06 18:29:09 UTC (rev 19178)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/exception/impl/RethrowErrorHandler.java	2010-04-06 20:34:27 UTC (rev 19179)
@@ -1,45 +0,0 @@
-/* $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
- */
-package org.hibernate.search.exception.impl;
-
-import org.hibernate.search.SearchException;
-import org.hibernate.search.exception.ErrorHandler;
-
-/**
- * This ErrorHandler will throw the exceptions it caught,
- * appending some context to the exception message.
- * 
- * @author Sanne Grinovero
- * @since 3.2
- */
-public class RethrowErrorHandler extends LogErrorHandler implements ErrorHandler {
-	
-	@Override
-	protected void logError(String errorMsg, Throwable exceptionThatOccurred) {
-		throw new SearchException( errorMsg, exceptionThatOccurred );
-	}
-
-}
-

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java	2010-04-06 18:29:09 UTC (rev 19178)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java	2010-04-06 20:34:27 UTC (rev 19179)
@@ -92,7 +92,6 @@
 import org.slf4j.Logger;
 import org.hibernate.search.exception.ErrorHandler;
 import org.hibernate.search.exception.impl.LogErrorHandler;
-import org.hibernate.search.exception.impl.RethrowErrorHandler;
 
 /**
  * @author Emmanuel Bernard
@@ -702,26 +701,11 @@
 		boolean sync = BatchedQueueingProcessor.isConfiguredAsSync( configuration );
 		String errorHandlerClassName = configuration.getProperty( Environment.ERROR_HANDLER );
 		if ( StringHelper.isEmpty( errorHandlerClassName ) ) {
-			// default error handler depends on sync/async:
-			if ( sync ) {
-				return new RethrowErrorHandler();
-			}
-			else {
-				return new LogErrorHandler();
-			}
+			return new LogErrorHandler();
 		}
 		else if ( errorHandlerClassName.trim().equals( "log" ) ) {
 			return new LogErrorHandler();
 		}
-		else if ( errorHandlerClassName.trim().equals( "rethrow" ) ) {
-			if ( ! sync ) {
-				// RethrowErrorHandler won't work when backend is async:
-				throw new SearchException( "The \"rethrow\" ErrorHandler is not compatible with aync backend" );
-			}
-			else {
-				return new RethrowErrorHandler();
-			}
-		}
 		else {
 			return PluginLoader.instanceFromName( ErrorHandler.class, errorHandlerClassName,
 				SearchFactoryImpl.class, "Error Handler" );

Deleted: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java	2010-04-06 18:29:09 UTC (rev 19178)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/RethrowErrorHandlingTest.java	2010-04-06 20:34:27 UTC (rev 19179)
@@ -1,82 +0,0 @@
-/* $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
- */
-package org.hibernate.search.test.errorhandling;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.hibernate.search.Environment;
-import org.hibernate.search.SearchException;
-import org.hibernate.search.backend.BackendQueueProcessorFactory;
-import org.hibernate.search.backend.LuceneWork;
-import org.hibernate.search.exception.ErrorHandler;
-import org.hibernate.search.exception.impl.RethrowErrorHandler;
-import org.hibernate.search.impl.SearchFactoryImpl;
-
-/**
- * Verifies the RethrowErrorHandler is able to propagate exceptions back to the
- * committing thread.	
- * 
- * @author Sanne Grinovero
- */
-public class RethrowErrorHandlingTest extends LuceneErrorHandlingTest {
-	
-	@Override
-	public void testErrorHandling(){
-		SearchFactoryImpl searchFactoryImpl = getSearchFactoryImpl();
-		ErrorHandler errorHandler = searchFactoryImpl.getErrorHandler();
-		Assert.assertTrue( errorHandler instanceof RethrowErrorHandler );
-		BackendQueueProcessorFactory queueProcessorFactory = searchFactoryImpl.getBackendQueueProcessorFactory();
-		List<LuceneWork> queue = new ArrayList<LuceneWork>();
-		queue.add( new HarmlessWork( "firstWork" ) );
-		queue.add( new HarmlessWork( "secondWork" ) );
-		Runnable processor = queueProcessorFactory.getProcessor( queue );
-		workcounter.set( 0 ); // reset work counter
-		processor.run();
-		Assert.assertEquals( 2, workcounter.get() );
-		
-		workcounter.set( 0 ); // reset work counter
-		queue.add( new FailingWork( "firstFailure" ) );
-		queue.add( new HarmlessWork( "thirdWork" ) );
-		queue.add( new HarmlessWork( "fourthWork" ) );
-		processor = queueProcessorFactory.getProcessor( queue );
-		try {
-			processor.run();
-			Assert.fail( "should have thrown a SearchException" );
-		}
-		catch (SearchException se) {
-			//expected
-		}
-	}
-	
-	protected void configure(org.hibernate.cfg.Configuration cfg) {
-		super.configure( cfg );
-		cfg.setProperty( Environment.ERROR_HANDLER, "rethrow" );
-	}
-
-}
-



More information about the hibernate-commits mailing list