Class DefaultServiceRegistry
java.lang.Object
eu.cloudnetservice.driver.registry.DefaultServiceRegistry
- All Implemented Interfaces:
ServiceRegistry
@Singleton
@Provides(ServiceRegistry.class)
public class DefaultServiceRegistry
extends Object
implements ServiceRegistry
Represents the default service registry implementation.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final recordA registered entry in the service registry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.common.collect.Multimap<Class<?>, DefaultServiceRegistry.RegistryEntry<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> booleanhasProvider(@NonNull Class<T> clazz, @NonNull String name) Checks if a provider with the given name is registered for the given service.@NonNull Collection<Class<?>> Get all services for which a provider was registered previously.<T> TGet the provider for the given service with the given name from this registry.<T> @NonNull Collection<T> Get all registered providers for the given service.<T,E extends T>
@NonNull ServiceRegistryregisterProvider(@NonNull Class<T> service, @NonNull String name, E provider) Registers the given provider for the given service to this service registry.Unregisters all previously registered providers for all services from this registry.unregisterAll(@NonNull ClassLoader classLoader) Unregisters all providers for any service from this registry whose classes were loaded by the given class loader.<T,E extends T>
@NonNull ServiceRegistryunregisterProvider(@NonNull Class<T> service, E provider) Unregisters the given provider instance from the registered services of the given service class.<T,E extends T>
@NonNull ServiceRegistryunregisterProvider(@NonNull Class<T> service, @NonNull Class<E> provider) Unregisters all providers for the given service which are an instance of the given class.unregisterProvider(@NonNull Class<T> service, @NonNull String name) Unregisters the provider with the given name from the given service if registered previously.unregisterProviders(@NonNull Class<T> service) Removes all previously registered providers for the given service.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.registry.ServiceRegistry
firstProvider
-
Field Details
-
providers
protected final com.google.common.collect.Multimap<Class<?>,DefaultServiceRegistry.RegistryEntry<?>> providers
-
-
Constructor Details
-
DefaultServiceRegistry
-
-
Method Details
-
registerProvider
@NonNull public <T,E extends T> @NonNull ServiceRegistry registerProvider(@NonNull @NonNull Class<T> service, @NonNull @NonNull String name, @NonNull E provider) Registers the given provider for the given service to this service registry. After registration the given provider will be the first provider of the given service and retrievable with the given name.If multiple services with the same name are registered the first one will be returned which was registered to this registry.
- Specified by:
registerProviderin interfaceServiceRegistry- Type Parameters:
T- the service class type to register the service to.E- the provider (or service implementation) class type.- Parameters:
service- the service class to register the implementation to.name- the name of the provider to register.provider- the provider (and service implementation) to register.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterProvider
@NonNull public <T,E extends T> @NonNull ServiceRegistry unregisterProvider(@NonNull @NonNull Class<T> service, @NonNull @NonNull Class<E> provider) Unregisters all providers for the given service which are an instance of the given class.- Specified by:
unregisterProviderin interfaceServiceRegistry- Type Parameters:
T- the type of the service.E- the type of the providers.- Parameters:
service- the service to unregister the providers from.provider- the class of the providers to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterProvider
@NonNull public <T,E extends T> @NonNull ServiceRegistry unregisterProvider(@NonNull @NonNull Class<T> service, @NonNull E provider) Unregisters the given provider instance from the registered services of the given service class.- Specified by:
unregisterProviderin interfaceServiceRegistry- Type Parameters:
T- the type of the service.E- the type of the providers.- Parameters:
service- the service to unregister the provider from.provider- the provider instance to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
hasProvider
Checks if a provider with the given name is registered for the given service.- Specified by:
hasProviderin interfaceServiceRegistry- Type Parameters:
T- the type of the service.- Parameters:
clazz- the service to check the providers of.name- the name of the service to check for.- Returns:
- true if this registry has a provider with the given name for the service, false otherwise.
-
unregisterProvider
@NonNull public <T> @NonNull ServiceRegistry unregisterProvider(@NonNull @NonNull Class<T> service, @NonNull @NonNull String name) Unregisters the provider with the given name from the given service if registered previously.- Specified by:
unregisterProviderin interfaceServiceRegistry- Type Parameters:
T- the type of the service.- Parameters:
service- the service to unregister the provider from.name- the name of the provider to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterProviders
@NonNull public <T> @NonNull ServiceRegistry unregisterProviders(@NonNull @NonNull Class<T> service) Removes all previously registered providers for the given service.- Specified by:
unregisterProvidersin interfaceServiceRegistry- Type Parameters:
T- the type of the service.- Parameters:
service- the service to unregisters the providers of.- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterAll
Unregisters all previously registered providers for all services from this registry.- Specified by:
unregisterAllin interfaceServiceRegistry- Returns:
- the same instance as used to call the method, for chaining.
-
unregisterAll
Unregisters all providers for any service from this registry whose classes were loaded by the given class loader.- Specified by:
unregisterAllin interfaceServiceRegistry- Parameters:
classLoader- the class loader of the providers to unregister.- Returns:
- the same instance as used to call the method, for chaining.
-
providedServices
Get all services for which a provider was registered previously.- Specified by:
providedServicesin interfaceServiceRegistry- Returns:
- all services for which a provider was registered previously.
-
provider
Get the provider for the given service with the given name from this registry. This method returns null if no such provider was registered previously.This method will return the first provider registered with the given name if multiple providers with the same name for the given service were registered.
- Specified by:
providerin interfaceServiceRegistry- Type Parameters:
T- the type of the service.- Parameters:
service- the service of the provider.name- the name of the provider to get.- Returns:
- the provider for the given service with the given name, null if no such provider was registered.
-
providers
Get all registered providers for the given service. This method returns an empty collection if no providers are registered for the given service but never null.- Specified by:
providersin interfaceServiceRegistry- Type Parameters:
T- the type of the service.- Parameters:
service- the service to get all registered providers of.- Returns:
- all registered providers for the service or an empty collection if no providers were registered for it.
-