ph.com.nightowlstudios.core.Edge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edge Show documentation
Show all versions of edge Show documentation
A simple library for building REST API using Vertx.
package ph.com.nightowlstudios.core;
import io.vertx.core.Vertx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ph.com.nightowlstudios.service.Service;
import ph.com.nightowlstudios.service.ServiceBus;
import java.util.HashSet;
import java.util.Set;
/**
* @author Joseph Harvey Angeles - yev
* @since 4/4/21
**/
public class Edge {
private static final Logger logger = LoggerFactory.getLogger(Edge.class);
private static final Set registeredServices = new HashSet<>();
private Edge() {}
public static ServiceBus serviceBus(Class serviceClass) {
if (registeredServices.contains(serviceClass.getName())) {
return new ServiceBus<>(serviceClass);
}
throw runtimeError(serviceClass);
}
public static ServiceBus serviceBus(Vertx vertx, Class serviceClass) {
if (registeredServices.contains(serviceClass.getName())) {
return new ServiceBus<>(vertx, serviceClass);
}
throw runtimeError(serviceClass);
}
static RuntimeException runtimeError(Class> serviceClass) {
logger.error("Unknown {} service. Make sure the service has been registered.", serviceClass.getName());
return new RuntimeException("Unknown Service");
}
static void registerService(Class> serviceClass) {
registeredServices.add(serviceClass.getName());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy