public abstract class ServiceProvider
extends java.lang.Object
All the methods in this class are safe to use by multiple concurrent threads.
Modifier and Type | Field and Description |
---|---|
private static java.lang.Object |
LOCK
Synchronization lock for searching or setting the service providers.
|
private static ServiceProvider[] |
providers
All service providers found, sorted in preference order.
|
Modifier | Constructor and Description |
---|---|
protected |
ServiceProvider()
Creates a new service provider.
|
Modifier and Type | Method and Description |
---|---|
static java.util.List<ServiceProvider> |
available()
Returns the list of available service providers.
|
static ServiceProvider |
current()
Returns the current
ServiceProvider . |
int |
getPriority()
This method allows to define a priority for a registered ServiceProvider instance.
|
private static ServiceProvider[] |
getProviders()
Gets all
ServiceProvider . |
abstract <Q extends Quantity<Q>> |
getQuantityFactory(java.lang.Class<Q> quantity)
Return a factory for this
Quantity . |
abstract SystemOfUnitsService |
getSystemOfUnitsService()
Returns the service to obtain a
SystemOfUnits , or null if none. |
abstract UnitFormatService |
getUnitFormatService()
Returns the service to obtain a
UnitFormat , or null if none. |
static ServiceProvider |
setCurrent(ServiceProvider provider)
Replaces the current
ServiceProvider . |
private static final java.lang.Object LOCK
private static volatile ServiceProvider[] providers
protected ServiceProvider()
public int getPriority()
public abstract SystemOfUnitsService getSystemOfUnitsService()
SystemOfUnits
, or null
if none.SystemOfUnits
, or null
.public abstract UnitFormatService getUnitFormatService()
UnitFormat
, or null
if none.UnitFormat
, or null
.public abstract <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory(java.lang.Class<Q> quantity)
Quantity
.quantity
- the quantityQuantityFactory
private static ServiceProvider[] getProviders()
ServiceProvider
. This method loads the provider when first needed.public static java.util.List<ServiceProvider> available()
public static ServiceProvider current()
ServiceProvider
. If necessary the ServiceProvider
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 setCurrent()
.
ServiceProvider
used.java.lang.IllegalStateException
- if no ServiceProvider
has been found.getPriority()
,
#setCurrent()
public static ServiceProvider setCurrent(ServiceProvider provider)
ServiceProvider
.provider
- the new ServiceProvider