Interface ServiceRegistry
public interface ServiceRegistry
Holds the implementations of the services through which the server delegates its behaviour.
A service is identified by an interface, for instance
CombatService. Several implementations may be registered for the same
service; the one with the highest ServicePriority is used, the first registered one
winning a tie.
- Since:
- 0.1.0
-
Method Summary
Modifier and TypeMethodDescription<T> Optional<T> Gets the implementation in use for a service, if any.<T> List<T> Gets every implementation registered for a service, for instance to delegate to the one a plugin replaced.<T> TGets the implementation in use for a service.default <T> voidRegisters an implementation of a service atServicePriority.NORMALpriority.<T> voidregister(Class<T> service, T implementation, Object owner, ServicePriority priority) Registers an implementation of a service.<T> booleanunregister(Class<T> service, T implementation) Removes one implementation of a service.voidunregisterAll(Object owner) Removes every implementation registered byowner, whatever the service.
-
Method Details
-
register
Registers an implementation of a service.- Type Parameters:
T- the service type- Parameters:
service- the service interfaceimplementation- the implementationowner- the owner of the registration, usually thePlugininstance; it is released byunregisterAll(Object)priority- the rank of this implementation- Throws:
IllegalArgumentException- ifimplementationdoes not implementservice- Since:
- 0.1.0
-
register
Registers an implementation of a service atServicePriority.NORMALpriority.- Type Parameters:
T- the service type- Parameters:
service- the service interfaceimplementation- the implementationowner- the owner of the registration, usually thePlugininstance- Throws:
IllegalArgumentException- ifimplementationdoes not implementservice- Since:
- 0.1.0
-
get
Gets the implementation in use for a service.- Type Parameters:
T- the service type- Parameters:
service- the service interface- Returns:
- the implementation with the highest priority
- Throws:
IllegalStateException- if no implementation is registered- Since:
- 0.1.0
-
find
-
findAll
Gets every implementation registered for a service, for instance to delegate to the one a plugin replaced.- Type Parameters:
T- the service type- Parameters:
service- the service interface- Returns:
- an immutable snapshot of the implementations, the one in use first
- Since:
- 0.1.0
-
unregister
Removes one implementation of a service.- Type Parameters:
T- the service type- Parameters:
service- the service interfaceimplementation- the implementation to remove- Returns:
trueif the implementation was registered- Since:
- 0.1.0
-
unregisterAll
Removes every implementation registered byowner, whatever the service.- Parameters:
owner- the owner given at registration- Since:
- 0.1.0
-