Skip to content

Commit

Permalink
HSEARCH-472 Formatting, removing wrong import
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Sep 26, 2013
1 parent 110a756 commit e4abca3
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 84 deletions.
Expand Up @@ -24,12 +24,13 @@
package org.hibernate.search;

/**
* represents a FullTextFilter that is about to be applied
* Represents a {@code FullTextFilter} that is about to be applied.
* Used to inject parameters
*
* @author Emmanuel Bernard
*/
public interface FullTextFilter {
FullTextFilter setParameter(String name, Object value);

Object getParameter(String name);
}
Expand Up @@ -27,14 +27,12 @@
import org.hibernate.search.spi.ServiceProvider;

/**
* The ServiceManager is used to manage uniqueness of services
* and runtime discovery of new implementation.
* The {@code ServiceManager} is used to manage uniqueness of services and runtime discovery of service implementations.
* <p/>
* Uniqueness is meant in the scope of the SearchFactory, as there is a single ServiceManager instance
* in the SearchFactory.
* Uniqueness is meant in the scope of the {@code SearchFactory}, as there is a single {@code ServiceManager} instance
* per {@code SearchFactory}.
* <p/>
* Any service requested should be released using (@link #releaseService} when it's not needed anymore
* to allow for a cleanup phase.
* Any service requested should be released using {@link #releaseService(Class)} when it's not needed anymore.
*/
public interface ServiceManager {

Expand Down
Expand Up @@ -40,11 +40,6 @@ public class DefaultMutableEntityIndexBinding<T> implements MutableEntityIndexBi
private final IndexManager[] indexManagers;
private final EntityIndexingInterceptor entityIndexingInterceptor;

/**
* @param shardingStrategy
* @param similarityInstance
* @param providers
*/
public DefaultMutableEntityIndexBinding(
IndexShardingStrategy shardingStrategy,
Similarity similarityInstance,
Expand Down
Expand Up @@ -20,9 +20,13 @@
*/
package org.hibernate.search.engine.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Set;

import org.apache.lucene.document.Document;
import org.apache.lucene.search.Similarity;
import org.apache.poi.ss.formula.functions.T;
import org.hibernate.search.cfg.spi.IndexManagerFactory;
import org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity;
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
Expand All @@ -34,11 +38,6 @@
import org.hibernate.search.store.IndexShardingStrategy;
import org.hibernate.search.store.ShardIdentifierProvider;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Set;

/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
*/
Expand All @@ -55,11 +54,6 @@ public class DynamicShardingEntityIndexBinding<T> implements MutableEntityIndexB
private final EntityIndexingInterceptor entityIndexingInterceptor;
private IndexManagerFactory indexManagerFactory;

/**
* @param shardingStrategy
* @param similarityInstance
* @param providers
*/
public DynamicShardingEntityIndexBinding(
ShardIdentifierProvider shardIdentityProvider,
Similarity similarityInstance,
Expand Down Expand Up @@ -160,7 +154,10 @@ public IndexManager[] getIndexManagersForAllShards() {
@Override
public IndexManager getIndexManagerForAddition(Class<?> entity, Serializable id, String idInString, Document document) {
String shard = shardIdentityProvider.getShardIdentifier( entity, id, idInString, document );
return indexManagerHolder.getOrCreateLateIndexManager( getProviderName( shard ), DynamicShardingEntityIndexBinding.this );
return indexManagerHolder.getOrCreateLateIndexManager(
getProviderName( shard ),
DynamicShardingEntityIndexBinding.this
);
}

@Override
Expand All @@ -172,7 +169,12 @@ public IndexManager[] getIndexManagersForDeletion(Class<?> entity, Serializable
private IndexManager[] getIndexManagersFromShards(String[] shards) {
ArrayList<IndexManager> managers = new ArrayList<IndexManager>( shards.length );
for ( String shard : shards ) {
managers.add( indexManagerHolder.getOrCreateLateIndexManager( getProviderName( shard ), DynamicShardingEntityIndexBinding.this ) );
managers.add(
indexManagerHolder.getOrCreateLateIndexManager(
getProviderName( shard ),
DynamicShardingEntityIndexBinding.this
)
);
}
return managers.toArray( new IndexManager[shards.length] );
}
Expand Down
Expand Up @@ -36,7 +36,7 @@
import java.util.Properties;

/**
* Build the expected {@link EntityIndexBinder} depending in the configuration
* Build the expected {@link EntityIndexBinding} depending in the configuration
*
* @author Emmanuel Bernard <emmanuel@hibernate.org>
*/
Expand Down
Expand Up @@ -21,13 +21,16 @@
package org.hibernate.search.engine.impl;

import org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity;
import org.hibernate.search.engine.spi.EntityIndexBinder;
import org.hibernate.search.engine.spi.EntityIndexBinding;

/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
*/
public interface MutableEntityIndexBinding<T> extends EntityIndexBinder {

public interface MutableEntityIndexBinding<T> extends EntityIndexBinding {
/**
* Allows to set the document builder for this {@code EntityIndexBinding}.
*
* @param documentBuilder the new document builder instance
*/
void setDocumentBuilderIndexedEntity(DocumentBuilderIndexedEntity<T> documentBuilder);

}
Expand Up @@ -39,9 +39,9 @@
import org.hibernate.search.engine.impl.EntityIndexBindingFactory;
import org.hibernate.search.engine.impl.MutableEntityIndexBinding;
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
import org.hibernate.search.indexes.spi.IndexManager;
import org.hibernate.search.indexes.interceptor.DefaultEntityInterceptor;
import org.hibernate.search.indexes.interceptor.EntityIndexingInterceptor;
import org.hibernate.search.indexes.spi.IndexManager;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.spi.internals.SearchFactoryImplementorWithShareableState;
import org.hibernate.search.store.IndexShardingStrategy;
Expand Down Expand Up @@ -69,23 +69,23 @@
* @author Sanne Grinovero
*/
public class IndexManagerHolder {
public static final String DYNAMIC_SHARDING = "dynamic";

private static final Log log = LoggerFactory.make();
private static final String SHARDING_STRATEGY = "sharding_strategy";
private static final String NBR_OF_SHARDS = SHARDING_STRATEGY + ".nbr_of_shards";
public static final String DYNAMIC_SHARDING = "dynamic";
private static final String SHARD_IDENTITY_PROVIDER = SHARDING_STRATEGY + ".shard_identity_provider";

private final Map<String, IndexManager> indexManagersRegistry = new ConcurrentHashMap<String, IndexManager>();

//I currently think it's easier to not hide sharding implementations in a custom
//IndexManager to make it easier to explicitly a)detect duplicates b)start-stop
//additional Managers as needed from a dynamic sharding implementation, without having
//to embed the sharding logic in a manager itself.
//so now we have a real 1:1 relation between Managers and indexes, and the signature for
//#getReader() will always return a single "naive" IndexReader.
//So we get better caching too, as the changed indexes change cache keys on a fine-grained basis
//(for both fieldCaches and cached filters)
// I currently think it's easier to not hide sharding implementations in a custom
// IndexManager to make it easier to explicitly a)detect duplicates b)start-stop
// additional Managers as needed from a dynamic sharding implementation, without having
// to embed the sharding logic in a manager itself.
// so now we have a real 1:1 relation between Managers and indexes, and the signature for
// #getReader() will always return a single "naive" IndexReader.
// So we get better caching too, as the changed indexes change cache keys on a fine-grained basis
// (for both fieldCaches and cached filters)
public synchronized MutableEntityIndexBinding buildEntityIndexBinding(
XClass entity,
Class mappedClass,
Expand All @@ -107,7 +107,7 @@ public synchronized MutableEntityIndexBinding buildEntityIndexBinding(
similarityInstance = ClassLoaderHelper.instanceFromName(
Similarity.class,
similarityClassName,
DirectoryProviderFactory.class,
DirectoryProviderFactory.class.getClassLoader(),
"Similarity class for index " + directoryProviderName
);
}
Expand All @@ -126,8 +126,10 @@ public synchronized MutableEntityIndexBinding buildEntityIndexBinding(
Properties indexProp = indexProps[index];
IndexManager indexManager = indexManagersRegistry.get( providerName );
if ( indexManager == null ) {
indexManager = doGetOrCreateIndexManager( providerName, mappedClass, similarityInstance,
indexProp, cfg.getIndexManagerFactory(), context );
indexManager = getOrCreateIndexManager(
providerName, mappedClass, similarityInstance,
indexProp, cfg.getIndexManagerFactory(), context
);
}
else {
indexManager.addContainedEntity( mappedClass );
Expand Down Expand Up @@ -157,21 +159,25 @@ else if ( indexProps.length == 1 ) {
}
shardingStrategy = ClassLoaderHelper.instanceFromName(
IndexShardingStrategy.class,
shardingStrategyName, DirectoryProviderFactory.class, "IndexShardingStrategy"
shardingStrategyName,
DirectoryProviderFactory.class.getClassLoader(),
"IndexShardingStrategy"
);
}
if ( shardingStrategy != null ) {
shardingStrategy.initialize(
new MaskedProperty( indexProps[0], SHARDING_STRATEGY ), providers
new MaskedProperty( indexProps[0], SHARDING_STRATEGY ), providers
);
}

ShardIdentifierProvider shardIdentifierProvider = null;
String shardIdentityProviderName = indexProps[0].getProperty( SHARD_IDENTITY_PROVIDER );
if ( isDynamicSharding ) {
shardIdentifierProvider = ClassLoaderHelper.instanceFromName(
ShardIdentifierProvider.class,
shardIdentityProviderName, DirectoryProviderFactory.class, "ShardIdentifierProvider"
ShardIdentifierProvider.class,
shardIdentityProviderName,
DirectoryProviderFactory.class.getClassLoader(),
"ShardIdentifierProvider"
);
//TODO should we filter the properties? Would it be useful to get the indexBase / name to
//TODO implement a ls on the dir?
Expand Down Expand Up @@ -216,7 +222,12 @@ else if ( indexProps.length == 1 ) {
* Clients of this method should first optimistically check the indexManagersRegistry, which might already contain the needed IndexManager,
* to avoid contention on this synchronized method during dynamic reconfiguration at runtime.
*/
private synchronized IndexManager doGetOrCreateIndexManager(String providerName, Class<?> mappedClass, Similarity similarityInstance, Properties indexProp, IndexManagerFactory indexManagerFactory, WorkerBuildContext context) {
private synchronized IndexManager getOrCreateIndexManager(String providerName,
Class<?> mappedClass,
Similarity similarityInstance,
Properties indexProp,
IndexManagerFactory indexManagerFactory,
WorkerBuildContext context) {
IndexManager indexManager = indexManagersRegistry.get( providerName );
if ( indexManager == null ) {
indexManager = createIndexManager( providerName, indexProp, context, indexManagerFactory );
Expand All @@ -229,13 +240,13 @@ private synchronized IndexManager doGetOrCreateIndexManager(String providerName,
return indexManager;
}

public IndexManager getOrCreateLateIndexManager(String providerName, DynamicShardingEntityIndexBinding entityIndexBinder) {
public IndexManager getOrCreateLateIndexManager(String providerName, DynamicShardingEntityIndexBinding entityIndexBinding) {
IndexManager indexManager = indexManagersRegistry.get( providerName );
if ( indexManager != null ) {
indexManager.addContainedEntity( entityIndexBinder.getDocumentBuilder().getBeanClass() );
indexManager.addContainedEntity( entityIndexBinding.getDocumentBuilder().getBeanClass() );
return indexManager;
}
SearchFactoryImplementor searchFactory = entityIndexBinder.getSearchFactory();
SearchFactoryImplementor searchFactory = entityIndexBinding.getSearchFactory();
WorkerBuildContext context;
//known implementations of SearchFactory passed are MutableSearchFactory and ImmutableSearchFactory
if ( WorkerBuildContext.class.isAssignableFrom( searchFactory.getClass() ) ) {
Expand All @@ -244,11 +255,12 @@ public IndexManager getOrCreateLateIndexManager(String providerName, DynamicShar
else {
throw log.assertionFailureCannotCastToWorkerBuilderContext( searchFactory.getClass() );
}
indexManager = doGetOrCreateIndexManager(
indexManager = getOrCreateIndexManager(
providerName,
entityIndexBinder.getDocumentBuilder().getBeanClass(),
entityIndexBinder.getSimilarity(), entityIndexBinder.getProperties(),
entityIndexBinder.getIndexManagerFactory(),
entityIndexBinding.getDocumentBuilder().getBeanClass(),
entityIndexBinding.getSimilarity(),
entityIndexBinding.getProperties(),
entityIndexBinding.getIndexManagerFactory(),
context
);
indexManager.setSearchFactory( searchFactory );
Expand Down Expand Up @@ -282,12 +294,13 @@ private Class<? extends EntityIndexingInterceptor> getInterceptorClassFromHierar

/**
* Specifies a custom similarity on an index
*
* @param newSimilarity
* @param manager
*/
private void setSimilarity(Similarity newSimilarity, IndexManager manager) {
Similarity similarity = manager.getSimilarity();
if ( similarity != null && ! similarity.getClass().equals( newSimilarity.getClass() ) ) {
if ( similarity != null && !similarity.getClass().equals( newSimilarity.getClass() ) ) {
throw new SearchException(
"Multiple entities are sharing the same index but are declaring an " +
"inconsistent Similarity. When overriding default Similarity make sure that all types sharing a same index " +
Expand Down Expand Up @@ -317,6 +330,7 @@ private IndexManager createIndexManager(String indexName, Properties indexProps,

/**
* Extracts the index name used for the entity from it's annotations
*
* @return the index name
*/
private static String getDirectoryProviderName(XClass clazz, SearchConfiguration cfg) {
Expand Down Expand Up @@ -396,6 +410,7 @@ public Collection<IndexManager> getIndexManagers() {
/**
* Useful for MutableSearchFactory, this haves all managed IndexManagers
* switch over to the new SearchFactory.
*
* @param factory the new SearchFactory to set on each IndexManager.
*/
public void setActiveSearchFactory(SearchFactoryImplementorWithShareableState factory) {
Expand All @@ -416,6 +431,7 @@ public synchronized void stop() {

/**
* @param targetIndexName the name of the IndexManager to look up
*
* @return the IndexManager, or null if it doesn't exist
*/
public IndexManager getIndexManager(String targetIndexName) {
Expand Down

0 comments on commit e4abca3

Please sign in to comment.