Package javax.measure.spi
Class ServiceProvider
java.lang.Object
javax.measure.spi.ServiceProvider
Service Provider for Units of Measurement services.
All the methods in this class are safe to use by multiple concurrent threads.
- Since:
- 1.0
- Version:
- 1.0, August 8, 2016
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Object
Synchronization lock for searching or setting the service providers.private static ServiceProvider[]
All service providers found, sorted in preference order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List
<ServiceProvider> Returns the list of available service providers.static ServiceProvider
current()
Returns the currentServiceProvider
.int
This method allows to define a priority for a registered ServiceProvider instance.private static ServiceProvider[]
Gets allServiceProvider
.abstract <Q extends Quantity<Q>>
QuantityFactory<Q> getQuantityFactory
(Class<Q> quantity) Return a factory for thisQuantity
.abstract SystemOfUnitsService
Returns the service to obtain aSystemOfUnits
, ornull
if none.abstract UnitFormatService
Returns the service to obtain aUnitFormat
, ornull
if none.static ServiceProvider
setCurrent
(ServiceProvider provider) Replaces the currentServiceProvider
.
-
Field Details
-
LOCK
Synchronization lock for searching or setting the service providers. -
providers
All service providers found, sorted in preference order. Array content shall never been changed after initialization; if we want to change the array content, a new array shall be created.
-
-
Constructor Details
-
ServiceProvider
protected ServiceProvider()Creates a new service provider. Only to be used by subclasses.
-
-
Method Details
-
getPriority
public int getPriority()This method allows to define a priority for a registered ServiceProvider instance. When multiple providers are registered in the system the provider with the highest priority value is taken.- Returns:
- the provider's priority (default is 0).
-
getSystemOfUnitsService
Returns the service to obtain aSystemOfUnits
, ornull
if none.- Returns:
- the service to obtain a
SystemOfUnits
, ornull
.
-
getUnitFormatService
Returns the service to obtain aUnitFormat
, ornull
if none.- Returns:
- the service to obtain a
UnitFormat
, ornull
.
-
getQuantityFactory
Return a factory for thisQuantity
.- Parameters:
quantity
- the quantity- Returns:
- the
QuantityFactory
-
getProviders
Gets allServiceProvider
. This method loads the provider when first needed. -
available
Returns the list of available service providers.- Returns:
- all available service providers.
-
current
Returns the currentServiceProvider
. If necessary theServiceProvider
will be lazily loaded.If there are no providers available, an IllegalStateException is thrown, otherwise the provider with the highest priority is used or the one explicitly designated via
invalid reference
setCurrent()
- Returns:
- the
ServiceProvider
used. - Throws:
IllegalStateException
- if noServiceProvider
has been found.- See Also:
-
setCurrent
Replaces the currentServiceProvider
.- Parameters:
provider
- the newServiceProvider
- Returns:
- the removed provider, or null.
-