[hibernate-commits] Hibernate SVN: r20203 - in search/trunk/hibernate-search: src/main/java/org/hibernate/search and 6 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Aug 20 06:59:45 EDT 2010
Author: hardy.ferentschik
Date: 2010-08-20 06:59:44 -0400 (Fri, 20 Aug 2010)
New Revision: 20203
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControl.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControlMBean.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexControlMBeanTest.java
Removed:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrl.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrlMBean.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
Modified:
search/trunk/hibernate-search/pom.xml
search/trunk/hibernate-search/src/main/java/org/hibernate/search/ProjectionConstants.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/batchlucene/LuceneBatchBackend.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/spi/SearchFactoryIntegrator.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
Log:
HSEARCH-278 Renamed IndexCtrl to IndexControl and marked IndexControlMBean as experimental. Introduced @experimental in order to have a more formal way to mark something as such
Modified: search/trunk/hibernate-search/pom.xml
===================================================================
--- search/trunk/hibernate-search/pom.xml 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/pom.xml 2010-08-20 10:59:44 UTC (rev 20203)
@@ -226,6 +226,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
+ <tags>
+ <tag>
+ <name>experimental</name>
+ <placement>a</placement>
+ <head>Experimental</head>
+ </tag>
+ </tags>
<docfilessubdirs>true</docfilessubdirs>
<stylesheetfile>${basedir}/src/main/javadoc/stylesheet.css</stylesheetfile>
<links>
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/ProjectionConstants.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/ProjectionConstants.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/ProjectionConstants.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -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;
@@ -58,10 +57,11 @@
public String ID = "__HSearch_id";
/**
- * Lucene Document id
- * Experimental: If you use this feature, please speak up in the forum
+ * Lucene Document id.
* <p/>
* Expert: Lucene document id can change overtime between 2 different IndexReader opening.
+ *
+ * @experimental If you use this constant/feature, please speak up in the forum
*/
public String DOCUMENT_ID = "__HSearch_DocumentId";
Modified: 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 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/UpdatableBackendQueueProcessorFactory.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * 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;
import java.util.Set;
@@ -6,10 +29,10 @@
import org.hibernate.search.store.DirectoryProvider;
/**
- * Experimental
- * Allow a BackendQueueProcessorFactory to be notified of DiurectoryProvider changes
+ * Allow a BackendQueueProcessorFactory to be notified of {@code DirectoryProvider} changes.
*
* @author Emmanuel Bernard
+ * @experimental This API is experimental
*/
public interface UpdatableBackendQueueProcessorFactory extends BackendQueueProcessorFactory {
/**
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/batchlucene/LuceneBatchBackend.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/batchlucene/LuceneBatchBackend.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/batchlucene/LuceneBatchBackend.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -43,11 +43,12 @@
import org.hibernate.search.store.IndexShardingStrategy;
/**
- * First EXPERIMENTAL BatchBackend; this is not meant to be used as a regular
+ * This is not meant to be used as a regular
* backend, only to apply batch changes to the index. Several threads
* are used to make changes to each index, so order of Work processing is not guaranteed.
*
* @author Sanne Grinovero
+ * @experimental First {@code BatchBackend}
*/
public class LuceneBatchBackend implements BatchBackend {
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -74,7 +74,7 @@
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.filter.MRUFilterCachingStrategy;
import org.hibernate.search.filter.ShardSensitiveOnlyFilter;
-import org.hibernate.search.jmx.IndexCtrl;
+import org.hibernate.search.jmx.IndexControl;
import org.hibernate.search.jmx.JMXRegistrar;
import org.hibernate.search.reader.ReaderProvider;
import org.hibernate.search.reader.ReaderProviderFactory;
@@ -168,8 +168,8 @@
// if we have a JNDI bound SessionFactory we can also enable the index control bean
if ( StringHelper.isNotEmpty( configurationProperties.getProperty( "hibernate.session_factory_name" ) ) ) {
- IndexCtrl indexCtrlBean = new IndexCtrl( configurationProperties );
- JMXRegistrar.registerMBean( indexCtrlBean, IndexCtrl.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ IndexControl indexCtrlBean = new IndexControl( configurationProperties );
+ JMXRegistrar.registerMBean( indexCtrlBean, IndexControl.INDEX_CTRL_MBEAN_OBJECT_NAME );
}
}
Copied: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControl.java (from rev 20181, search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrl.java)
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControl.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControl.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -0,0 +1,155 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * 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.jmx;
+
+import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.hibernate.CacheMode;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.util.JNDIHelper;
+import org.hibernate.util.ReflectHelper;
+
+
+/**
+ * Implementation of the {@code IndexControlMBean} JMX attributes and operations.
+ *
+ * @author Hardy Ferentschik
+ */
+public class IndexControl implements IndexControlMBean {
+ private static final String HIBERNATE_JNDI_PREFIX = "hibernate.jndi.";
+
+ private final Properties jndiProperties;
+ private final String sessionFactoryJndiName;
+
+ private int batchSize = 25;
+ private int numberOfObjectLoadingThreads = 2;
+ private int numberOfFetchingThreads = 4;
+
+ public IndexControl(Properties props) {
+ this.sessionFactoryJndiName = props.getProperty( "hibernate.session_factory_name" );
+ this.jndiProperties = JNDIHelper.getJndiProperties( props, HIBERNATE_JNDI_PREFIX );
+ }
+
+ public void setBatchSize(int batchSize) {
+ this.batchSize = batchSize;
+ }
+
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ public void setNumberOfObjectLoadingThreads(int numberOfThreads) {
+ this.numberOfObjectLoadingThreads = numberOfThreads;
+ }
+
+ public int getNumberOfObjectLoadingThreads() {
+ return numberOfObjectLoadingThreads;
+ }
+
+ public void setNumberOfFetchingThreads(int numberOfThreads) {
+ this.numberOfFetchingThreads = numberOfThreads;
+ }
+
+ public int getNumberOfFetchingThreads() {
+ return numberOfFetchingThreads;
+ }
+
+ public void index(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+
+ SessionFactory factory = getSessionFactory();
+ Session session = factory.openSession();
+ FullTextSession fulltextSession = Search.getFullTextSession( session );
+ try {
+ fulltextSession.createIndexer( clazz )
+ .batchSizeToLoadObjects( batchSize )
+ .cacheMode( CacheMode.NORMAL )
+ .threadsToLoadObjects( numberOfObjectLoadingThreads )
+ .threadsForSubsequentFetching( numberOfFetchingThreads )
+ .startAndWait();
+ }
+ catch ( InterruptedException e ) {
+ throw new RuntimeException( "Unable to complete indexing" );
+ }
+ session.close();
+ }
+
+ public void optimize(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+
+ SessionFactory factory = getSessionFactory();
+ Session session = factory.openSession();
+ FullTextSession fullTextSession = Search.getFullTextSession( session );
+ fullTextSession.beginTransaction();
+ fullTextSession.getSearchFactory().optimize( clazz );
+ fullTextSession.getTransaction().commit();
+ session.close();
+ }
+
+ public void purge(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+
+ SessionFactory factory = getSessionFactory();
+ Session session = factory.openSession();
+ FullTextSession fullTextSession = Search.getFullTextSession( session );
+ fullTextSession.beginTransaction();
+ fullTextSession.purgeAll( clazz );
+ fullTextSession.getTransaction().commit();
+ session.close();
+ }
+
+ private Class<?> getEntityClass(String entity) {
+ Class<?> clazz;
+ try {
+ clazz = ReflectHelper.classForName( entity, IndexControl.class );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new IllegalArgumentException( entity + "not a indexed entity" );
+ }
+ return clazz;
+ }
+
+ private SessionFactory getSessionFactory() {
+ try {
+ Context initialContext;
+ if ( jndiProperties.isEmpty() ) {
+ initialContext = new InitialContext();
+ }
+ else {
+ initialContext = new InitialContext( jndiProperties );
+ }
+ return ( SessionFactory ) initialContext.lookup( sessionFactoryJndiName );
+ }
+ catch ( Exception e ) {
+ throw new UnsupportedOperationException(
+ "In order for this operation to work the SessionFactory must be bound to JNDI"
+ );
+ }
+ }
+}
\ No newline at end of file
Copied: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControlMBean.java (from rev 20181, search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrlMBean.java)
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControlMBean.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexControlMBean.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -0,0 +1,109 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * 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.jmx;
+
+/**
+ * Defines the Hibernate Search exposed JMX attributes and operations for index creation and purging.
+ *
+ * @experimental This MBean is experimental
+ * @author Hardy Ferentschik
+ */
+public interface IndexControlMBean {
+
+ public static final String INDEX_CTRL_MBEAN_OBJECT_NAME = "org.hibernate.search.jmx:type=IndexControlMBean";
+
+ /**
+ * Sets the batch size for the mass indexer.
+ *
+ * @param batchSize the new batch size
+ */
+ void setBatchSize(int batchSize);
+
+ /**
+ * @return the current batch size for (mass) indexing
+ */
+ int getBatchSize();
+
+ /**
+ * @param numberOfThreads the number of threads used for object loading during mass indexing.
+ */
+ void setNumberOfObjectLoadingThreads(int numberOfThreads);
+
+ /**
+ * @return the current number of threads during mass indexing
+ */
+ int getNumberOfObjectLoadingThreads();
+
+ /**
+ * @param numberOfThreads the number of threads used for collections fetching during mass indexing
+ */
+ void setNumberOfFetchingThreads(int numberOfThreads);
+
+ /**
+ * @return the current number of threads used for collection fetching
+ */
+ int getNumberOfFetchingThreads();
+
+ /**
+ * Index the specified entity using the mass indexer.
+ * <p><b>Note:<br/>
+ * This method is only available if the Hibernate {@code SessionFactory}
+ * is available via JNDI.
+ * </p>
+ *
+ * @param entity The fqc of the entity to index
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
+ */
+ void index(String entity);
+
+ /**
+ * Optimizes the index for the specified entity.
+ * <p><b>Note:<br/>
+ * This method is only available if the Hibernate {@code SessionFactory}
+ * is available via JNDI.
+ * </p>
+ *
+ * @param entity The fqc of the entity to index
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
+ */
+ void optimize(String entity);
+
+ /**
+ * Purge the index of the specified entity.
+ * <p><b>Note:<br/>
+ * This method is only available if the Hibernate {@code SessionFactory}
+ * is available via JNDI.
+ * </p>
+ *
+ * @param entity The fqc of the entity to index
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
+ */
+ void purge(String entity);
+}
\ No newline at end of file
Deleted: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrl.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrl.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -1,155 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * 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.jmx;
-
-import java.util.Properties;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import org.hibernate.CacheMode;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.Search;
-import org.hibernate.search.util.JNDIHelper;
-import org.hibernate.util.ReflectHelper;
-
-
-/**
- * Implementation of the {@code IndexCtrlMBean} JMX attributes and operations.
- *
- * @author Hardy Ferentschik
- */
-public class IndexCtrl implements IndexCtrlMBean {
- private static final String HIBERNATE_JNDI_PREFIX = "hibernate.jndi.";
-
- private final Properties jndiProperties;
- private final String sessionFactoryJndiName;
-
- private int batchSize = 25;
- private int numberOfObjectLoadingThreads = 2;
- private int numberOfFetchingThreads = 4;
-
- public IndexCtrl(Properties props) {
- this.sessionFactoryJndiName = props.getProperty( "hibernate.session_factory_name" );
- this.jndiProperties = JNDIHelper.getJndiProperties( props, HIBERNATE_JNDI_PREFIX );
- }
-
- public void setBatchSize(int batchSize) {
- this.batchSize = batchSize;
- }
-
- public int getBatchSize() {
- return batchSize;
- }
-
- public void setNumberOfObjectLoadingThreads(int numberOfThreads) {
- this.numberOfObjectLoadingThreads = numberOfThreads;
- }
-
- public int getNumberOfObjectLoadingThreads() {
- return numberOfObjectLoadingThreads;
- }
-
- public void setNumberOfFetchingThreads(int numberOfThreads) {
- this.numberOfFetchingThreads = numberOfThreads;
- }
-
- public int getNumberOfFetchingThreads() {
- return numberOfFetchingThreads;
- }
-
- public void index(String entity) {
- Class<?> clazz = getEntityClass( entity );
-
- SessionFactory factory = getSessionFactory();
- Session session = factory.openSession();
- FullTextSession fulltextSession = Search.getFullTextSession( session );
- try {
- fulltextSession.createIndexer( clazz )
- .batchSizeToLoadObjects( batchSize )
- .cacheMode( CacheMode.NORMAL )
- .threadsToLoadObjects( numberOfObjectLoadingThreads )
- .threadsForSubsequentFetching( numberOfFetchingThreads )
- .startAndWait();
- }
- catch ( InterruptedException e ) {
- throw new RuntimeException( "Unable to complete indexing" );
- }
- session.close();
- }
-
- public void optimize(String entity) {
- Class<?> clazz = getEntityClass( entity );
-
- SessionFactory factory = getSessionFactory();
- Session session = factory.openSession();
- FullTextSession fullTextSession = Search.getFullTextSession( session );
- fullTextSession.beginTransaction();
- fullTextSession.getSearchFactory().optimize( clazz );
- fullTextSession.getTransaction().commit();
- session.close();
- }
-
- public void purge(String entity) {
- Class<?> clazz = getEntityClass( entity );
-
- SessionFactory factory = getSessionFactory();
- Session session = factory.openSession();
- FullTextSession fullTextSession = Search.getFullTextSession( session );
- fullTextSession.beginTransaction();
- fullTextSession.purgeAll( clazz );
- fullTextSession.getTransaction().commit();
- session.close();
- }
-
- private Class<?> getEntityClass(String entity) {
- Class<?> clazz;
- try {
- clazz = ReflectHelper.classForName( entity, IndexCtrl.class );
- }
- catch ( ClassNotFoundException e ) {
- throw new IllegalArgumentException( entity + "not a indexed entity" );
- }
- return clazz;
- }
-
- private SessionFactory getSessionFactory() {
- try {
- Context initialContext;
- if ( jndiProperties.isEmpty() ) {
- initialContext = new InitialContext();
- }
- else {
- initialContext = new InitialContext( jndiProperties );
- }
- return ( SessionFactory ) initialContext.lookup( sessionFactoryJndiName );
- }
- catch ( Exception e ) {
- throw new UnsupportedOperationException(
- "In order for this operation to work the SessionFactory must be bound to JNDI"
- );
- }
- }
-}
\ No newline at end of file
Deleted: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrlMBean.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrlMBean.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/IndexCtrlMBean.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -1,108 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * 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.jmx;
-
-/**
- * Defines the Hibernate Search exposed JMX attributes and operations for index creation and purging.
- *
- * @author Hardy Ferentschik
- */
-public interface IndexCtrlMBean {
-
- public static final String INDEX_CTRL_MBEAN_OBJECT_NAME = "org.hibernate.search.jmx:type=IndexCtrlMBean";
-
- /**
- * Sets the batch size for the mass indexer.
- *
- * @param batchSize the new batch size
- */
- void setBatchSize(int batchSize);
-
- /**
- * @return the current batch size for (mass) indexing
- */
- int getBatchSize();
-
- /**
- * @param numberOfThreads the number of threads used for object loading during mass indexing.
- */
- void setNumberOfObjectLoadingThreads(int numberOfThreads);
-
- /**
- * @return the current number of threads during mass indexing
- */
- int getNumberOfObjectLoadingThreads();
-
- /**
- * @param numberOfThreads the number of threads used for collections fetching during mass indexing
- */
- void setNumberOfFetchingThreads(int numberOfThreads);
-
- /**
- * @return the current number of threads used for collection fetching
- */
- int getNumberOfFetchingThreads();
-
- /**
- * Index the specified entity using the mass indexer.
- * <p><b>Note:<br/>
- * This method is only available if the Hibernate {@code SessionFactory}
- * is available via JNDI.
- * </p>
- *
- * @param entity The fqc of the entity to index
- *
- * @throws IllegalArgumentException in case the entity name is not valid
- * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
- */
- void index(String entity);
-
- /**
- * Optimizes the index for the specified entity.
- * <p><b>Note:<br/>
- * This method is only available if the Hibernate {@code SessionFactory}
- * is available via JNDI.
- * </p>
- *
- * @param entity The fqc of the entity to index
- *
- * @throws IllegalArgumentException in case the entity name is not valid
- * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
- */
- void optimize(String entity);
-
- /**
- * Purge the index of the specified entity.
- * <p><b>Note:<br/>
- * This method is only available if the Hibernate {@code SessionFactory}
- * is available via JNDI.
- * </p>
- *
- * @param entity The fqc of the entity to index
- *
- * @throws IllegalArgumentException in case the entity name is not valid
- * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
- */
- void purge(String entity);
-}
\ No newline at end of file
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/spi/SearchFactoryIntegrator.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/spi/SearchFactoryIntegrator.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/spi/SearchFactoryIntegrator.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -1,3 +1,26 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * 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.spi;
import org.hibernate.search.SearchFactory;
@@ -14,6 +37,7 @@
* It also allows modification of some of the search factory internals:
* - today allow addition of new indexed classes.
*
+ * @experimental
* @author Emmanuel Bernard
*/
public interface SearchFactoryIntegrator extends SearchFactory {
Copied: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexControlMBeanTest.java (from rev 20181, search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java)
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexControlMBeanTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexControlMBeanTest.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -0,0 +1,165 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * 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.test.jmx;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.Set;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.jmx.IndexControlMBean;
+import org.hibernate.search.jmx.StatisticsInfoMBean;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class IndexControlMBeanTest extends SearchTestCase {
+ MBeanServer mbeanServer;
+ ObjectName statisticsBeanObjectName;
+ ObjectName indexBeanObjectName;
+
+ public void testIndexCtrlMBeanRegistered() throws Exception {
+ assertTrue(
+ "With the right property set the Search MBean should be registered",
+ mbeanServer.isRegistered( indexBeanObjectName )
+ );
+ }
+
+ public void testAttributesAndOperations() throws Exception {
+ MBeanInfo info = mbeanServer.getMBeanInfo( indexBeanObjectName );
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ assertEquals( "Wrong number of attributes", 3, attributes.length );
+ Set<String> attributeNames = new HashSet<String>();
+ attributeNames.add( "NumberOfObjectLoadingThreads" );
+ attributeNames.add( "NumberOfFetchingThreads" );
+ attributeNames.add( "BatchSize" );
+ for ( MBeanAttributeInfo attribute : attributes ) {
+ assertTrue( attributeNames.contains( attribute.getName() ) );
+ }
+
+ MBeanOperationInfo[] operations = info.getOperations();
+ assertEquals( "Wrong number of operations", 3, operations.length );
+ Set<String> operationNames = new HashSet<String>();
+ operationNames.add( "index" );
+ operationNames.add( "purge" );
+ operationNames.add( "optimize" );
+ for ( MBeanOperationInfo operation : operations ) {
+ assertTrue( operationNames.contains( operation.getName() ) );
+ }
+ }
+
+ public void testIndexAndPurge() throws Exception {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ Counter counter = new Counter();
+ s.save( counter );
+ tx.commit();
+ s.close();
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 0 ); // manual indexing!
+
+ mbeanServer.invoke(
+ indexBeanObjectName,
+ "index",
+ new String[] { Counter.class.getName() },
+ new String[] { String.class.getName() }
+ );
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 1 );
+
+ mbeanServer.invoke(
+ indexBeanObjectName,
+ "purge",
+ new String[] { Counter.class.getName() },
+ new String[] { String.class.getName() }
+ );
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 0 );
+ }
+
+ protected void setUp() throws Exception {
+ setCfg( null ); // force a rebuild of the configuration
+ super.setUp();
+ mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ statisticsBeanObjectName = new ObjectName( StatisticsInfoMBean.STATISTICS_MBEAN_OBJECT_NAME );
+ indexBeanObjectName = new ObjectName( IndexControlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if ( mbeanServer.isRegistered( statisticsBeanObjectName ) ) {
+ mbeanServer.unregisterMBean( statisticsBeanObjectName );
+ }
+ if ( mbeanServer.isRegistered( indexBeanObjectName ) ) {
+ mbeanServer.unregisterMBean( indexBeanObjectName );
+ }
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ File targetDir = getTargetDir();
+ File simpleJndiDir = new File( targetDir, "simpleJndi" );
+ simpleJndiDir.mkdir();
+
+ cfg.setProperty( "hibernate.session_factory_name", "java:comp/SessionFactory" );
+ cfg.setProperty( "hibernate.jndi.class", "org.osjava.sj.SimpleContextFactory" );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.root", simpleJndiDir.getAbsolutePath() );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.jndi.shared", "true" );
+
+ cfg.setProperty( "hibernate.search.indexing_strategy", "manual" );
+ cfg.setProperty( Environment.JMX_ENABLED, "true" );
+ }
+
+ @Override
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class<?>[] { Counter.class };
+ }
+
+ private void assertNumberOfIndexedEntities(String entity, int count)
+ throws InstanceNotFoundException, MBeanException, ReflectionException {
+ assertEquals(
+ "wrong number of indexed entities", count,
+ mbeanServer.invoke(
+ statisticsBeanObjectName,
+ "getNumberOfIndexedEntities",
+ new String[] { entity },
+ new String[] { String.class.getName() }
+ )
+ );
+ }
+}
\ No newline at end of file
Deleted: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -1,165 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * 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.test.jmx;
-
-import java.io.File;
-import java.lang.management.ManagementFactory;
-import java.util.HashSet;
-import java.util.Set;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.search.Environment;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.Search;
-import org.hibernate.search.jmx.IndexCtrlMBean;
-import org.hibernate.search.jmx.StatisticsInfoMBean;
-import org.hibernate.search.test.SearchTestCase;
-
-/**
- * @author Hardy Ferentschik
- */
-public class IndexCtrlMBeanTest extends SearchTestCase {
- MBeanServer mbeanServer;
- ObjectName statisticsBeanObjectName;
- ObjectName indexBeanObjectName;
-
- public void testIndexCtrlMBeanRegistered() throws Exception {
- assertTrue(
- "With the right property set the Search MBean should be registered",
- mbeanServer.isRegistered( indexBeanObjectName )
- );
- }
-
- public void testAttributesAndOperations() throws Exception {
- MBeanInfo info = mbeanServer.getMBeanInfo( indexBeanObjectName );
- MBeanAttributeInfo[] attributes = info.getAttributes();
- assertEquals( "Wrong number of attributes", 3, attributes.length );
- Set<String> attributeNames = new HashSet<String>();
- attributeNames.add( "NumberOfObjectLoadingThreads" );
- attributeNames.add( "NumberOfFetchingThreads" );
- attributeNames.add( "BatchSize" );
- for ( MBeanAttributeInfo attribute : attributes ) {
- assertTrue( attributeNames.contains( attribute.getName() ) );
- }
-
- MBeanOperationInfo[] operations = info.getOperations();
- assertEquals( "Wrong number of operations", 3, operations.length );
- Set<String> operationNames = new HashSet<String>();
- operationNames.add( "index" );
- operationNames.add( "purge" );
- operationNames.add( "optimize" );
- for ( MBeanOperationInfo operation : operations ) {
- assertTrue( operationNames.contains( operation.getName() ) );
- }
- }
-
- public void testIndexAndPurge() throws Exception {
- FullTextSession s = Search.getFullTextSession( openSession() );
- Transaction tx = s.beginTransaction();
- Counter counter = new Counter();
- s.save( counter );
- tx.commit();
- s.close();
-
- assertNumberOfIndexedEntities( Counter.class.getName(), 0 ); // manual indexing!
-
- mbeanServer.invoke(
- indexBeanObjectName,
- "index",
- new String[] { Counter.class.getName() },
- new String[] { String.class.getName() }
- );
-
- assertNumberOfIndexedEntities( Counter.class.getName(), 1 );
-
- mbeanServer.invoke(
- indexBeanObjectName,
- "purge",
- new String[] { Counter.class.getName() },
- new String[] { String.class.getName() }
- );
-
- assertNumberOfIndexedEntities( Counter.class.getName(), 0 );
- }
-
- protected void setUp() throws Exception {
- setCfg( null ); // force a rebuild of the configuration
- super.setUp();
- mbeanServer = ManagementFactory.getPlatformMBeanServer();
- statisticsBeanObjectName = new ObjectName( StatisticsInfoMBean.STATISTICS_MBEAN_OBJECT_NAME );
- indexBeanObjectName = new ObjectName( IndexCtrlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- if ( mbeanServer.isRegistered( statisticsBeanObjectName ) ) {
- mbeanServer.unregisterMBean( statisticsBeanObjectName );
- }
- if ( mbeanServer.isRegistered( indexBeanObjectName ) ) {
- mbeanServer.unregisterMBean( indexBeanObjectName );
- }
- }
-
- protected void configure(Configuration cfg) {
- super.configure( cfg );
- File targetDir = getTargetDir();
- File simpleJndiDir = new File( targetDir, "simpleJndi" );
- simpleJndiDir.mkdir();
-
- cfg.setProperty( "hibernate.session_factory_name", "java:comp/SessionFactory" );
- cfg.setProperty( "hibernate.jndi.class", "org.osjava.sj.SimpleContextFactory" );
- cfg.setProperty( "hibernate.jndi.org.osjava.sj.root", simpleJndiDir.getAbsolutePath() );
- cfg.setProperty( "hibernate.jndi.org.osjava.sj.jndi.shared", "true" );
-
- cfg.setProperty( "hibernate.search.indexing_strategy", "manual" );
- cfg.setProperty( Environment.JMX_ENABLED, "true" );
- }
-
- @Override
- protected Class<?>[] getAnnotatedClasses() {
- return new Class<?>[] { Counter.class };
- }
-
- private void assertNumberOfIndexedEntities(String entity, int count)
- throws InstanceNotFoundException, MBeanException, ReflectionException {
- assertEquals(
- "wrong number of indexed entities", count,
- mbeanServer.invoke(
- statisticsBeanObjectName,
- "getNumberOfIndexedEntities",
- new String[] { entity },
- new String[] { String.class.getName() }
- )
- );
- }
-}
\ No newline at end of file
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java 2010-08-20 05:23:28 UTC (rev 20202)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java 2010-08-20 10:59:44 UTC (rev 20203)
@@ -30,7 +30,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
-import org.hibernate.search.jmx.IndexCtrlMBean;
+import org.hibernate.search.jmx.IndexControlMBean;
import org.hibernate.search.jmx.StatisticsInfoMBean;
import org.hibernate.search.test.SearchTestCase;
@@ -49,7 +49,7 @@
mbeanServer.isRegistered( name )
);
- name = new ObjectName( IndexCtrlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ name = new ObjectName( IndexControlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
assertFalse(
"Without '" + Environment.JMX_ENABLED + "' set the index control MBean should not be registered",
mbeanServer.isRegistered( name )
@@ -77,7 +77,7 @@
if ( mbeanServer.isRegistered( statisticsBeanObjectName ) ) {
mbeanServer.unregisterMBean( statisticsBeanObjectName );
}
- ObjectName indexBeanObjectName = new ObjectName( IndexCtrlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ ObjectName indexBeanObjectName = new ObjectName( IndexControlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
if ( mbeanServer.isRegistered( indexBeanObjectName ) ) {
mbeanServer.unregisterMBean( indexBeanObjectName );
}
More information about the hibernate-commits
mailing list