All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ph.com.nightowlstudios.core.Edge Maven / Gradle / Ivy

There is a newer version: 6.21.1
Show newest version
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