org.simpleflatmapper.util.ProducerServiceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-util Show documentation
Show all versions of sfm-util Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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);
}
}