Interface ServiceHolder<T>

Type Parameters:
T - the service type

@AvailableSince("1.0") public interface ServiceHolder<T>
Generic priority-based service registry supporting multiple implementations.

Allows registration of multiple service instances with different priorities, automatically selecting the highest-priority service for get().

Since:
1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Predefined priority levels from lowest to highest.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns the highest-priority registered service.
    Returns all registered services ordered by priority (highest first).
    default boolean
    Checks if any service is currently registered.
    void
    register(T service, int priority)
    Registers a service with the specified integer priority.
    default void
    register(T service, ServiceHolder.Priority priority)
    Registers a service with the specified enum priority.
    void
    unregister(T service)
    Removes the specified service from the registry.
  • Method Details

    • register

      default void register(T service, ServiceHolder.Priority priority)
      Registers a service with the specified enum priority.

      Delegates to register(Object, int) using the priority's ordinal value.

      Parameters:
      service - the service instance to register
      priority - the priority level
    • register

      void register(T service, int priority)
      Registers a service with the specified integer priority.

      Higher priority values take precedence. If multiple services have the same priority, the first registered service wins.

      Parameters:
      service - the service instance to register
      priority - the priority value (higher = more priority)
    • unregister

      void unregister(T service)
      Removes the specified service from the registry.
      Parameters:
      service - the service instance to unregister
    • get

      T get()
      Returns the highest-priority registered service.

      If multiple services have the same highest priority, returns the first registered.

      Returns:
      the highest-priority service, or null if none registered
    • getAll

      List<T> getAll()
      Returns all registered services ordered by priority (highest first).
      Returns:
      list of all services in priority order
    • isLoaded

      default boolean isLoaded()
      Checks if any service is currently registered.
      Returns:
      true if at least one service is registered, false otherwise