Interface ServicesManager

All Known Implementing Classes:
SimpleServicesManager

public interface ServicesManager
Manages services and service providers. Services are an interface specifying a list of methods that a provider must implement. Providers are implementations of these services. A provider can be queried from the services manager in order to use a service (if one is available). If multiple plugins register a service, then the service with the highest priority takes precedence.
  • Method Details

    • register

      <T> void register(@NotNull Class<T> service, @NotNull T provider, @NotNull Plugin plugin, @NotNull ServicePriority priority)
      Register a provider of a service.
      Type Parameters:
      T - Provider
      Parameters:
      service - service class
      provider - provider to register
      plugin - plugin with the provider
      priority - priority of the provider
    • unregisterAll

      void unregisterAll(@NotNull Plugin plugin)
      Unregister all the providers registered by a particular plugin.
      Parameters:
      plugin - The plugin
    • unregister

      void unregister(@NotNull Class<?> service, @NotNull Object provider)
      Unregister a particular provider for a particular service.
      Parameters:
      service - The service interface
      provider - The service provider implementation
    • unregister

      void unregister(@NotNull Object provider)
      Unregister a particular provider.
      Parameters:
      provider - The service provider implementation
    • load

      @Nullable <T> T load(@NotNull Class<T> service)
      Queries for a provider. This may return null if no provider has been registered for a service. The highest priority provider is returned.
      Type Parameters:
      T - The service interface
      Parameters:
      service - The service interface
      Returns:
      provider or null
    • getRegistration

      @Nullable <T> RegisteredServiceProvider<T> getRegistration(@NotNull Class<T> service)
      Queries for a provider registration. This may return null if no provider has been registered for a service.
      Type Parameters:
      T - The service interface
      Parameters:
      service - The service interface
      Returns:
      provider registration or null
    • getRegistrations

      @NotNull List<RegisteredServiceProvider<?>> getRegistrations(@NotNull Plugin plugin)
      Get registrations of providers for a plugin.
      Parameters:
      plugin - The plugin
      Returns:
      provider registrations
    • getRegistrations

      @NotNull <T> Collection<RegisteredServiceProvider<T>> getRegistrations(@NotNull Class<T> service)
      Get registrations of providers for a service. The returned list is unmodifiable.
      Type Parameters:
      T - The service interface
      Parameters:
      service - The service interface
      Returns:
      list of registrations
    • getKnownServices

      @NotNull Collection<Class<?>> getKnownServices()
      Get a list of known services. A service is known if it has registered providers for it.
      Returns:
      list of known services
    • isProvidedFor

      <T> boolean isProvidedFor(@NotNull Class<T> service)
      Returns whether a provider has been registered for a service. Do not check this first only to call load(service) later, as that would be a non-thread safe situation.
      Type Parameters:
      T - service
      Parameters:
      service - service to check
      Returns:
      whether there has been a registered provider