org.freecompany.util.services

Class ServiceDiscovery

public class ServiceDiscovery extends Object

The discovery class provides factory methods for creating instances of service information objects and a caching mechanism. All methods of this class are thread safe.

These service objects can be used to find concrete implementations of service provider interfaces. The service discovery factory also provides caching for these information objects.

For example, to find the first known concrete provider for the interface {@code ServiceInterface}:

{@code ServiceInterface service = ServiceDiscovery.getInstance().findService( ServiceInterface.class);}

Field Summary
protected static Map<String,ServiceInfo>cache
Method Summary
static voiddisableCaching()
Disables ServiceInfo caching within this helper.
static voidenableCaching()
Enables ServiceInfo caching within this helper.
static ServiceInfogetInstance()
Returns a ServiceInfo instance that can access service providers specified as a system property or through the class path using the standard JAR services mechanism.
static ServiceInfogetInstance(String system)
Returns a ServiceInfo instance that can access service providers set as a system wide preference, specified as a system property, or through the class path using the standard JAR services mechanism.

Field Detail

cache

protected static Map<String,ServiceInfo> cache

Method Detail

disableCaching

public static void disableCaching()
Disables ServiceInfo caching within this helper. With caching disabled, a new ServiceInfo instance is created for each getInstance call, which may require reparsing properties files.

Caching is disabled by default.

enableCaching

public static void enableCaching()
Enables ServiceInfo caching within this helper. With caching enabled, ServiceInfo instances are cached for each system identifier to eliminate the need to reparse configuration properties.

Caching is disabled by default.

getInstance

public static ServiceInfo getInstance()
Returns a ServiceInfo instance that can access service providers specified as a system property or through the class path using the standard JAR services mechanism.

Returns: a ServiceInfo object that can be used to locate service providers.

getInstance

public static ServiceInfo getInstance(String system)
Returns a ServiceInfo instance that can access service providers set as a system wide preference, specified as a system property, or through the class path using the standard JAR services mechanism.

Returns: a ServiceInfo object that can be used to locate service providers.