Class ServiceManager

java.lang.Object
de.craftsblock.craftsnet.addon.services.ServiceManager

public class ServiceManager extends Object
The ServiceManager class represents a manager responsible for handling various service loaders in a system. It manages the registration, unregistration, and loading of service providers through the use of ServiceLoader instances.
Since:
3.0.0-SNAPSHOT
  • Constructor Details

    • ServiceManager

      public ServiceManager(CraftsNet craftsNet)
      Constructs a new ServiceManager and registers default service loaders. Default service loaders can be added during instantiation to provide immediate functionality.
      Parameters:
      craftsNet - The CraftsNet instance for which the ServiceManager was created.
  • Method Details

    • register

      public <T> void register(ServiceLoader<T> loader)
      Registers a service loader with the ServiceManager.
      Type Parameters:
      T - The type of service handled by the service loader.
      Parameters:
      loader - The service loader to be registered.
    • unregister

      public <T> void unregister(ServiceLoader<T> loader)
      Unregisters a service loader from the ServiceManager.
      Type Parameters:
      T - The type of service handled by the service loader.
      Parameters:
      loader - The service loader to be unregistered.
    • isRegistered

      public boolean isRegistered(ServiceLoader<?> loader)
      Checks if the given ServiceLoader is registered. This class is a wrapper for isRegistered(Class).
      Parameters:
      loader - The ServiceLoader to check.
      Returns:
      true when the ServiceLoader was registered, false otherwise.
      Since:
      3.2.1-SNAPSHOT
    • isRegistered

      public boolean isRegistered(Class<? extends ServiceLoader<?>> type)
      Checks if the given class representation of the ServiceLoader is registered.
      Parameters:
      type - The class representation of the ServiceLoader to check.
      Returns:
      true when the ServiceLoader was registered, false otherwise.
      Since:
      3.2.1-SNAPSHOT
    • load

      public <T> boolean load(Class<T> spi, Class<?> provider)
      Loads a service provider for a specific service type using the provided service loader class.

      This method attempts to load a service provider for the specified service type spi using the provided service loader class provider. It checks for existing providers, including superclass and interface providers, and then initializes and loads the service provider instances through the corresponding service loaders.

      Type Parameters:
      T - The type of service handled by the service loader.
      Parameters:
      spi - The service type interface/class.
      provider - The service loader class responsible for loading the service provider.
      Returns:
      true if the service provider is successfully loaded, false otherwise.
      Throws:
      RuntimeException - If any exception occurs during the instantiation or loading of the service provider. This includes NoSuchMethodException, InvocationTargetException, InstantiationException, and IllegalAccessException.
      See Also: