org.simpleflatmapper.util.ProducerServiceLoader Maven / Gradle / Ivy
package org.simpleflatmapper.util;
import java.util.Iterator;
import java.util.ServiceLoader;
public class ProducerServiceLoader {
@Deprecated
public static > void produceFromServiceLoader(Class producer, Consumer consumer) {
produceFromServiceLoader(ServiceLoader.load(producer), consumer);
}
public static > void produceFromServiceLoader(ServiceLoader serviceLoader, Consumer consumer) {
Iterator iterator = serviceLoader.iterator();
while(iterator.hasNext()) {
try {
iterator.next().produce(consumer);
} catch (Throwable e) {
System.err.println("Unexpected error on listing " + serviceLoader + " : " + e);
e.printStackTrace();
}
}
}
public interface Producer {
void produce(Consumer super T> consumer);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy