public S lookup(String name) { final S service = services.get(name); if (service != null) return service; throw new IllegalArgumentException("An SPI class of type "+clazz.getName()+" with name '"+name+"' does not exist."+ " You need to add the corresponding JAR file supporting this SPI to your classpath."+ " The current classpath supports the following names: "+availableServices()); }
/** * Creates a new codec. * <p> * The provided name will be written into the index segment: in order to * for the segment to be read this class should be registered with Java's * SPI mechanism (registered in META-INF/ of your jar file, etc). * @param name must be all ascii alphanumeric, and less than 128 characters in length. */ protected Codec(String name) { NamedSPILoader.checkServiceName(name); this.name = name; }
/** * Validates that a service name meets the requirements of {@link NamedSPI} */ public static void checkServiceName(String name) { // based on harmony charset.java if (name.length() >= 128) { throw new IllegalArgumentException("Illegal service name: '" + name + "' is too long (must be < 128 chars)."); } for (int i = 0, len = name.length(); i < len; i++) { char c = name.charAt(i); if (!isLetterOrDigit(c)) { throw new IllegalArgumentException("Illegal service name: '" + name + "' must be simple ascii alphanumeric."); } } }
public NamedSPILoader(Class<S> clazz, ClassLoader classloader) { this.clazz = clazz; // if clazz' classloader is not a parent of the given one, we scan clazz's classloader, too: final ClassLoader clazzClassloader = clazz.getClassLoader(); if (classloader == null) { classloader = clazzClassloader; } if (clazzClassloader != null && !SPIClassIterator.isParentClassLoader(clazzClassloader, classloader)) { reload(clazzClassloader); } reload(classloader); }
/** looks up a format by name */ public static PostingsFormat forName(String name) { return Holder.getLoader().lookup(name); }
/** * Reloads the DocValues format list from the given {@link ClassLoader}. * Changes to the docvalues formats are visible after the method ends, all * iterators ({@link #availableDocValuesFormats()},...) stay consistent. * * <p><b>NOTE:</b> Only new docvalues formats are added, existing ones are * never removed or replaced. * * <p><em>This method is expensive and should only be called for discovery * of new docvalues formats on the given classpath/classloader!</em> */ public static void reloadDocValuesFormats(ClassLoader classloader) { Holder.getLoader().reload(classloader); } }
/** looks up a format by name */ public static DocValuesFormat forName(String name) { return Holder.getLoader().lookup(name); }
/** returns a list of all available codec names */ public static Set<String> availableCodecs() { return Holder.getLoader().availableServices(); }
/** * Reloads the codec list from the given {@link ClassLoader}. * Changes to the codecs are visible after the method ends, all * iterators ({@link #availableCodecs()},...) stay consistent. * * <p><b>NOTE:</b> Only new codecs are added, existing ones are * never removed or replaced. * * <p><em>This method is expensive and should only be called for discovery * of new codecs on the given classpath/classloader!</em> */ public static void reloadCodecs(ClassLoader classloader) { Holder.getLoader().reload(classloader); }
/** * Creates a new docvalues format. * <p> * The provided name will be written into the index segment in some configurations * (such as when using {@code PerFieldDocValuesFormat}): in such configurations, * for the segment to be read this class should be registered with Java's * SPI mechanism (registered in META-INF/ of your jar file, etc). * @param name must be all ascii alphanumeric, and less than 128 characters in length. */ protected DocValuesFormat(String name) { NamedSPILoader.checkServiceName(name); this.name = name; }
/** looks up a codec by name */ public static Codec forName(String name) { return Holder.getLoader().lookup(name); }
/** * Validates that a service name meets the requirements of {@link NamedSPI} */ public static void checkServiceName(String name) { // based on harmony charset.java if (name.length() >= 128) { throw new IllegalArgumentException("Illegal service name: '" + name + "' is too long (must be < 128 chars)."); } for (int i = 0, len = name.length(); i < len; i++) { char c = name.charAt(i); if (!isLetterOrDigit(c)) { throw new IllegalArgumentException("Illegal service name: '" + name + "' must be simple ascii alphanumeric."); } } }
/** returns a list of all available format names */ public static Set<String> availableDocValuesFormats() { return Holder.getLoader().availableServices(); }
/** * Reloads the postings format list from the given {@link ClassLoader}. * Changes to the postings formats are visible after the method ends, all * iterators ({@link #availablePostingsFormats()},...) stay consistent. * * <p><b>NOTE:</b> Only new postings formats are added, existing ones are * never removed or replaced. * * <p><em>This method is expensive and should only be called for discovery * of new postings formats on the given classpath/classloader!</em> */ public static void reloadPostingsFormats(ClassLoader classloader) { Holder.getLoader().reload(classloader); } }
/** * Creates a new postings format. * <p> * The provided name will be written into the index segment in some configurations * (such as when using {@link PerFieldPostingsFormat}): in such configurations, * for the segment to be read this class should be registered with Java's * SPI mechanism (registered in META-INF/ of your jar file, etc). * @param name must be all ascii alphanumeric, and less than 128 characters in length. */ protected PostingsFormat(String name) { // TODO: can we somehow detect name conflicts here? Two different classes trying to claim the same name? Otherwise you see confusing errors... NamedSPILoader.checkServiceName(name); this.name = name; }
/** looks up a format by name */ public static DocValuesFormat forName(String name) { return Holder.getLoader().lookup(name); }
/** * Validates that a service name meets the requirements of {@link NamedSPI} */ public static void checkServiceName(String name) { // based on harmony charset.java if (name.length() >= 128) { throw new IllegalArgumentException("Illegal service name: '" + name + "' is too long (must be < 128 chars)."); } for (int i = 0, len = name.length(); i < len; i++) { char c = name.charAt(i); if (!isLetterOrDigit(c)) { throw new IllegalArgumentException("Illegal service name: '" + name + "' must be simple ascii alphanumeric."); } } }
/** returns a list of all available format names */ public static Set<String> availablePostingsFormats() { return Holder.getLoader().availableServices(); }
public NamedSPILoader(Class<S> clazz, ClassLoader classloader) { this.clazz = clazz; // if clazz' classloader is not a parent of the given one, we scan clazz's classloader, too: final ClassLoader clazzClassloader = clazz.getClassLoader(); if (classloader == null) { classloader = clazzClassloader; } if (clazzClassloader != null && !SPIClassIterator.isParentClassLoader(clazzClassloader, classloader)) { reload(clazzClassloader); } reload(classloader); }
checkServiceName(name); services.put(name, service);