package io.vertx.servicediscovery.impl;
import io.vertx.servicediscovery.Record;
import io.vertx.servicediscovery.spi.ServiceType;
import java.util.Iterator;
import java.util.Objects;
import java.util.ServiceLoader;
public class ServiceTypes {
public synchronized static ServiceType get(Record record) {
load();
String type = record.getType();
Objects.requireNonNull(type);
ServiceType found = get(type);
if (found != null) {
return found;
} else {
throw new IllegalArgumentException("Unsupported service type " + type);
}
}
private synchronized static void load() {
if (types == null || !types.iterator().hasNext()) {
types = ServiceLoader.load(ServiceType.class);
}
}
public synchronized static Iterator<ServiceType> all() {
load();
return types.iterator();
}
private static ServiceLoader<ServiceType> types;
public synchronized static ServiceType get(String type) {
load();
for (ServiceType next : types) {
if (next.name().equalsIgnoreCase(type)) {
return next;
}
}
return null;
}
}