49
49
import org .elasticsearch .indices .breaker .CircuitBreakerService ;
50
50
import org .elasticsearch .indices .fielddata .cache .IndicesFieldDataCache ;
51
51
import org .elasticsearch .indices .mapper .MapperRegistry ;
52
+ import org .elasticsearch .plugins .IndexStorePlugin ;
52
53
import org .elasticsearch .script .ScriptService ;
53
54
import org .elasticsearch .threadpool .ThreadPool ;
54
55
74
75
* {@link #addSimilarity(String, TriFunction)} while existing Providers can be referenced through Settings under the
75
76
* {@link IndexModule#SIMILARITY_SETTINGS_PREFIX} prefix along with the "type" value. For example, to reference the
76
77
* {@link BM25Similarity}, the configuration {@code "index.similarity.my_similarity.type : "BM25"} can be used.</li>
77
- * <li>{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link #addIndexStore(String, Function) }</li>
78
+ * <li>{@link IndexStore} - Custom {@link IndexStore} instances can be registered via {@link IndexStorePlugin }</li>
78
79
* <li>{@link IndexEventListener} - Custom {@link IndexEventListener} instances can be registered via
79
80
* {@link #addIndexEventListener(IndexEventListener)}</li>
80
81
* <li>Settings update listener - Custom settings update listener can be registered via
@@ -109,7 +110,7 @@ public final class IndexModule {
109
110
private SetOnce <IndexSearcherWrapperFactory > indexSearcherWrapper = new SetOnce <>();
110
111
private final Set <IndexEventListener > indexEventListeners = new HashSet <>();
111
112
private final Map <String , TriFunction <Settings , Version , ScriptService , Similarity >> similarities = new HashMap <>();
112
- private final Map <String , Function <IndexSettings , IndexStore >> storeTypes = new HashMap <>() ;
113
+ private final Map <String , Function <IndexSettings , IndexStore >> indexStoreFactories ;
113
114
private final SetOnce <BiFunction <IndexSettings , IndicesQueryCache , QueryCache >> forceQueryCacheProvider = new SetOnce <>();
114
115
private final List <SearchOperationListener > searchOperationListeners = new ArrayList <>();
115
116
private final List <IndexingOperationListener > indexOperationListeners = new ArrayList <>();
@@ -119,16 +120,22 @@ public final class IndexModule {
119
120
* Construct the index module for the index with the specified index settings. The index module contains extension points for plugins
120
121
* via {@link org.elasticsearch.plugins.PluginsService#onIndexModule(IndexModule)}.
121
122
*
122
- * @param indexSettings the index settings
123
- * @param analysisRegistry the analysis registry
124
- * @param engineFactory the engine factory
123
+ * @param indexSettings the index settings
124
+ * @param analysisRegistry the analysis registry
125
+ * @param engineFactory the engine factory
126
+ * @param indexStoreFactories the available store types
125
127
*/
126
- public IndexModule (final IndexSettings indexSettings , final AnalysisRegistry analysisRegistry , final EngineFactory engineFactory ) {
128
+ public IndexModule (
129
+ final IndexSettings indexSettings ,
130
+ final AnalysisRegistry analysisRegistry ,
131
+ final EngineFactory engineFactory ,
132
+ final Map <String , Function <IndexSettings , IndexStore >> indexStoreFactories ) {
127
133
this .indexSettings = indexSettings ;
128
134
this .analysisRegistry = analysisRegistry ;
129
135
this .engineFactory = Objects .requireNonNull (engineFactory );
130
136
this .searchOperationListeners .add (new SearchSlowLog (indexSettings ));
131
137
this .indexOperationListeners .add (new IndexingSlowLog (indexSettings ));
138
+ this .indexStoreFactories = Collections .unmodifiableMap (indexStoreFactories );
132
139
}
133
140
134
141
/**
@@ -245,25 +252,6 @@ public void addIndexOperationListener(IndexingOperationListener listener) {
245
252
this .indexOperationListeners .add (listener );
246
253
}
247
254
248
- /**
249
- * Adds an {@link IndexStore} type to this index module. Typically stores are registered with a reference to
250
- * it's constructor:
251
- * <pre>
252
- * indexModule.addIndexStore("my_store_type", MyStore::new);
253
- * </pre>
254
- *
255
- * @param type the type to register
256
- * @param provider the instance provider / factory method
257
- */
258
- public void addIndexStore (String type , Function <IndexSettings , IndexStore > provider ) {
259
- ensureNotFrozen ();
260
- if (storeTypes .containsKey (type )) {
261
- throw new IllegalArgumentException ("key [" + type +"] already registered" );
262
- }
263
- storeTypes .put (type , provider );
264
- }
265
-
266
-
267
255
/**
268
256
* Registers the given {@link Similarity} with the given name.
269
257
* The function takes as parameters:<ul>
@@ -360,7 +348,7 @@ public IndexService newIndexService(
360
348
if (Strings .isEmpty (storeType ) || isBuiltinType (storeType )) {
361
349
store = new IndexStore (indexSettings );
362
350
} else {
363
- Function <IndexSettings , IndexStore > factory = storeTypes .get (storeType );
351
+ Function <IndexSettings , IndexStore > factory = indexStoreFactories .get (storeType );
364
352
if (factory == null ) {
365
353
throw new IllegalArgumentException ("Unknown store type [" + storeType + "]" );
366
354
}
0 commit comments