use of org.apache.lucene.analysis.util.ResourceLoaderAware in project lucene-solr by apache.
the class TestFactories method initialize.
/** tries to initialize a factory with no arguments */
private AbstractAnalysisFactory initialize(Class<? extends AbstractAnalysisFactory> factoryClazz) throws IOException {
Map<String, String> args = new HashMap<>();
args.put("luceneMatchVersion", Version.LATEST.toString());
Constructor<? extends AbstractAnalysisFactory> ctor;
try {
ctor = factoryClazz.getConstructor(Map.class);
} catch (Exception e) {
throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
}
AbstractAnalysisFactory factory = null;
try {
factory = ctor.newInstance(args);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// it's ok if we dont provide the right parameters to throw this
return null;
}
}
if (factory instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) factory).inform(new StringMockResourceLoader(""));
} catch (IOException ignored) {
// it's ok if the right files arent available or whatever to throw this
} catch (IllegalArgumentException ignored) {
// is this ok? I guess so
}
}
return factory;
}
use of org.apache.lucene.analysis.util.ResourceLoaderAware in project lucene-solr by apache.
the class TestFactories method initialize.
/** tries to initialize a factory with no arguments */
private AbstractAnalysisFactory initialize(Class<? extends AbstractAnalysisFactory> factoryClazz) throws IOException {
Map<String, String> args = new HashMap<>();
args.put("luceneMatchVersion", Version.LATEST.toString());
Constructor<? extends AbstractAnalysisFactory> ctor;
try {
ctor = factoryClazz.getConstructor(Map.class);
} catch (Exception e) {
throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
}
AbstractAnalysisFactory factory = null;
try {
factory = ctor.newInstance(args);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof IllegalArgumentException) {
// it's ok if we dont provide the right parameters to throw this
return null;
}
}
if (factory instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) factory).inform(new StringMockResourceLoader(""));
} catch (IOException ignored) {
// it's ok if the right files arent available or whatever to throw this
} catch (IllegalArgumentException ignored) {
// is this ok? I guess so
}
}
return factory;
}
use of org.apache.lucene.analysis.util.ResourceLoaderAware in project lucene-solr by apache.
the class ManagedIndexSchema method informResourceLoaderAwareObjectsInChain.
/**
* After creating a new FieldType, it may contain components that implement
* the ResourceLoaderAware interface, which need to be informed after they
* are loaded (as they depend on this callback to complete initialization work)
*/
protected void informResourceLoaderAwareObjectsInChain(TokenizerChain chain) {
CharFilterFactory[] charFilters = chain.getCharFilterFactories();
for (CharFilterFactory next : charFilters) {
if (next instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) next).inform(loader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
}
TokenizerFactory tokenizerFactory = chain.getTokenizerFactory();
if (tokenizerFactory instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) tokenizerFactory).inform(loader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
TokenFilterFactory[] filters = chain.getTokenFilterFactories();
for (TokenFilterFactory next : filters) {
if (next instanceof ResourceLoaderAware) {
try {
((ResourceLoaderAware) next).inform(loader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
}
}
use of org.apache.lucene.analysis.util.ResourceLoaderAware in project lucene-solr by apache.
the class SolrResourceLoader method inform.
/**
* Tell all {@link ResourceLoaderAware} instances about the loader
*/
public void inform(ResourceLoader loader) throws IOException {
// make a copy to avoid potential deadlock of a callback adding to the list
ResourceLoaderAware[] arr;
while (waitingForResources.size() > 0) {
synchronized (waitingForResources) {
arr = waitingForResources.toArray(new ResourceLoaderAware[waitingForResources.size()]);
waitingForResources.clear();
}
for (ResourceLoaderAware aware : arr) {
aware.inform(loader);
}
}
}
use of org.apache.lucene.analysis.util.ResourceLoaderAware in project lucene-solr by apache.
the class SolrResourceLoader method newAdminHandlerInstance.
public CoreAdminHandler newAdminHandlerInstance(final CoreContainer coreContainer, String cname, String... subpackages) {
Class<? extends CoreAdminHandler> clazz = findClass(cname, CoreAdminHandler.class, subpackages);
if (clazz == null) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Can not find class: " + cname + " in " + classLoader);
}
CoreAdminHandler obj = null;
try {
Constructor<? extends CoreAdminHandler> ctor = clazz.getConstructor(CoreContainer.class);
obj = ctor.newInstance(coreContainer);
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error instantiating class: '" + clazz.getName() + "'", e);
}
if (!live) {
// which core are we talking about ?
if (obj instanceof ResourceLoaderAware) {
assertAwareCompatibility(ResourceLoaderAware.class, obj);
waitingForResources.add((ResourceLoaderAware) obj);
}
}
return obj;
}
Aggregations