Class ServiceProvider


  • public abstract class ServiceProvider
    extends java.lang.Object
    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 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.
    • Constructor Detail

      • ServiceProvider

        protected ServiceProvider()
        Creates a new service provider. Only to be used by subclasses.
    • 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).
      • getUnitFormatService

        public abstract UnitFormatService getUnitFormatService()
        Returns the service to obtain a UnitFormat, or null if none.
        Returns:
        the service to obtain a UnitFormat, or null.
      • getQuantityFactory

        public abstract <Q extends Quantity<Q>> QuantityFactory<Q> getQuantityFactory​(java.lang.Class<Q> quantity)
        Return a factory for this Quantity.
        Parameters:
        quantity - the quantity
        Returns:
        the QuantityFactory
      • 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 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() .

        Returns:
        the ServiceProvider used.
        Throws:
        java.lang.IllegalStateException - if no ServiceProvider has been found.
        See Also:
        getPriority(), #setCurrent()