org.freecompany.util.services
Class ServiceDiscovery

java.lang.Object
  extended by org.freecompany.util.services.ServiceDiscovery

public class ServiceDiscovery
extends java.lang.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 ServiceInterface:

ServiceInterface service = ServiceDiscovery.getInstance().findService( ServiceInterface.class);


Field Summary
protected static java.util.Map<java.lang.String,ServiceInfo> cache
           
 
Constructor Summary
ServiceDiscovery()
           
 
Method Summary
static void disableCaching()
          Disables ServiceInfo caching within this helper.
static void enableCaching()
          Enables ServiceInfo caching within this helper.
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.
static ServiceInfo getInstance(java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected static java.util.Map<java.lang.String,ServiceInfo> cache
Constructor Detail

ServiceDiscovery

public ServiceDiscovery()
Method Detail

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.


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.


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(java.lang.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.