Package javax.measure.spi
Class ServiceProvider
- java.lang.Object
-
- javax.measure.spi.ServiceProvider
-
public abstract class ServiceProvider extends java.lang.ObjectService 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
Fields Modifier and Type Field Description private static java.lang.ObjectLOCKSynchronization lock for searching or setting the service providers.private static ServiceProvider[]providersAll service providers found, sorted in preference order.
-
Constructor Summary
Constructors Modifier Constructor Description protectedServiceProvider()Creates a new service provider.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static java.util.List<ServiceProvider>available()Returns the list of available service providers.static ServiceProvidercurrent()Returns the currentServiceProvider.intgetPriority()This method allows to define a priority for a registered ServiceProvider instance.private static ServiceProvider[]getProviders()Gets allServiceProvider.abstract <Q extends Quantity<Q>>
QuantityFactory<Q>getQuantityFactory(java.lang.Class<Q> quantity)Return a factory for thisQuantity.abstract SystemOfUnitsServicegetSystemOfUnitsService()Returns the service to obtain aSystemOfUnits, ornullif none.abstract UnitFormatServicegetUnitFormatService()Returns the service to obtain aUnitFormat, ornullif none.static ServiceProvidersetCurrent(ServiceProvider provider)Replaces the currentServiceProvider.
-
-
-
Field Detail
-
LOCK
private static final java.lang.Object LOCK
Synchronization lock for searching or setting the service providers.
-
providers
private static volatile ServiceProvider[] 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.
-
-
Method Detail
-
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
public abstract SystemOfUnitsService getSystemOfUnitsService()
Returns the service to obtain aSystemOfUnits, ornullif none.- Returns:
- the service to obtain a
SystemOfUnits, ornull.
-
getUnitFormatService
public abstract UnitFormatService getUnitFormatService()
Returns the service to obtain aUnitFormat, ornullif none.- Returns:
- the service to obtain a
UnitFormat, ornull.
-
getQuantityFactory
public abstract <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(java.lang.Class<Q> quantity)
Return a factory for thisQuantity.- Parameters:
quantity- the quantity- Returns:
- the
QuantityFactory
-
getProviders
private static ServiceProvider[] getProviders()
Gets allServiceProvider. This method loads the provider when first needed.
-
available
public static java.util.List<ServiceProvider> available()
Returns the list of available service providers.- Returns:
- all available service providers.
-
current
public static ServiceProvider current()
Returns the currentServiceProvider. If necessary theServiceProviderwill 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
setCurrent().- Returns:
- the
ServiceProviderused. - Throws:
java.lang.IllegalStateException- if noServiceProviderhas been found.- See Also:
getPriority(),#setCurrent()
-
setCurrent
public static ServiceProvider setCurrent(ServiceProvider provider)
Replaces the currentServiceProvider.- Parameters:
provider- the newServiceProvider- Returns:
- the removed provider, or null.
-
-