Search in sources :

Example 1 with ResourceLoaderAware

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;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) AbstractAnalysisFactory(org.apache.lucene.analysis.util.AbstractAnalysisFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ResourceLoaderAware

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;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) AbstractAnalysisFactory(org.apache.lucene.analysis.util.AbstractAnalysisFactory) HashMap(java.util.HashMap) Map(java.util.Map) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Example 3 with ResourceLoaderAware

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);
            }
        }
    }
}
Also used : TokenizerFactory(org.apache.lucene.analysis.util.TokenizerFactory) CharFilterFactory(org.apache.lucene.analysis.util.CharFilterFactory) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory)

Example 4 with ResourceLoaderAware

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);
        }
    }
}
Also used : ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware)

Example 5 with ResourceLoaderAware

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;
}
Also used : CoreAdminHandler(org.apache.solr.handler.admin.CoreAdminHandler) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) SolrException(org.apache.solr.common.SolrException) NoInitialContextException(javax.naming.NoInitialContextException) NamingException(javax.naming.NamingException) SolrException(org.apache.solr.common.SolrException) CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException)

Aggregations

ResourceLoaderAware (org.apache.lucene.analysis.util.ResourceLoaderAware)14 HashMap (java.util.HashMap)7 IOException (java.io.IOException)6 SolrException (org.apache.solr.common.SolrException)5 TokenFilterFactory (org.apache.lucene.analysis.util.TokenFilterFactory)4 TokenizerFactory (org.apache.lucene.analysis.util.TokenizerFactory)4 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 AbstractAnalysisFactory (org.apache.lucene.analysis.util.AbstractAnalysisFactory)3 CharFilterFactory (org.apache.lucene.analysis.util.CharFilterFactory)3 ClasspathResourceLoader (org.apache.lucene.analysis.util.ClasspathResourceLoader)3 JsonArray (com.google.gson.JsonArray)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 LinkedList (java.util.LinkedList)2 NamingException (javax.naming.NamingException)2 NoInitialContextException (javax.naming.NoInitialContextException)2 StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1