Class ServiceManager
java.lang.Object
de.craftsblock.craftsnet.addon.services.ServiceManager
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 Summary
ConstructorsConstructorDescriptionServiceManager(CraftsNet craftsNet) Constructs a new ServiceManager and registers default service loaders. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisRegistered(ServiceLoader<?> loader) Checks if the givenServiceLoaderis registered.booleanisRegistered(Class<? extends ServiceLoader<?>> type) Checks if the given class representation of theServiceLoaderis registered.<T> booleanLoads a service provider for a specific service type using the provided service loader class.<T> voidregister(ServiceLoader<T> loader) Registers a service loader with the ServiceManager.<T> voidunregister(ServiceLoader<T> loader) Unregisters a service loader from the ServiceManager.
-
Constructor Details
-
ServiceManager
Constructs a new ServiceManager and registers default service loaders. Default service loaders can be added during instantiation to provide immediate functionality.- Parameters:
craftsNet- TheCraftsNetinstance for which theServiceManagerwas created.
-
-
Method Details
-
register
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
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
Checks if the givenServiceLoaderis registered. This class is a wrapper forisRegistered(Class).- Parameters:
loader- TheServiceLoaderto check.- Returns:
truewhen theServiceLoaderwas registered,falseotherwise.- Since:
- 3.2.1-SNAPSHOT
-
isRegistered
Checks if the given class representation of theServiceLoaderis registered.- Parameters:
type- The class representation of theServiceLoaderto check.- Returns:
truewhen theServiceLoaderwas registered,falseotherwise.- Since:
- 3.2.1-SNAPSHOT
-
load
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
spiusing the provided service loader classprovider. 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:
-