info.aduna.lang.service
Class ServiceRegistry<K,S>

java.lang.Object
  extended by info.aduna.lang.service.ServiceRegistry<K,S>
Direct Known Subclasses:
FileFormatServiceRegistry, LoaderRegistry

public abstract class ServiceRegistry<K,S>
extends Object

A registry that stores services by some key. Upon initialization, the registry searches for service description files at META-INF/services/<service class name> and initializes itself accordingly.

Author:
Arjohn Kampman
See Also:
ServiceRegistry

Field Summary
protected  org.slf4j.Logger logger
           
protected  Map<K,S> services
           
 
Constructor Summary
protected ServiceRegistry(Class<S> serviceClass)
           
 
Method Summary
 S add(S service)
          Adds a service to the registry.
 S get(K key)
          Gets the service for the specified key, if any.
 Collection<S> getAll()
          Gets all registered services.
protected abstract  K getKey(S service)
          Gets the key for the specified service.
 Set<K> getKeys()
          Gets the set of registered keys.
 boolean has(K key)
          Checks whether a service for the specified key is available.
 void remove(S service)
          Removes a service from the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.slf4j.Logger logger

services

protected Map<K,S> services
Constructor Detail

ServiceRegistry

protected ServiceRegistry(Class<S> serviceClass)
Method Detail

add

public S add(S service)
Adds a service to the registry. Any service that is currently registered for the same key (as specified by getKey(Object)) will be replaced with the new service.

Parameters:
service - The service that should be added to the registry.
Returns:
The previous service that was registered for the same key, or null if there was no such service.

remove

public void remove(S service)
Removes a service from the registry.

Parameters:
service - The service be removed from the registry.

get

public S get(K key)
Gets the service for the specified key, if any.

Parameters:
key - The key identifying which service to get.
Returns:
The service for the specified key, or null if no such service is avaiable.

has

public boolean has(K key)
Checks whether a service for the specified key is available.

Parameters:
key - The key identifying which service to search for.
Returns:
true if a service for the specific key is available, false otherwise.

getAll

public Collection<S> getAll()
Gets all registered services.

Returns:
An unmodifiable collection containing all registered servivces.

getKeys

public Set<K> getKeys()
Gets the set of registered keys.

Returns:
An unmodifiable set containing all registered keys.

getKey

protected abstract K getKey(S service)
Gets the key for the specified service.

Parameters:
service - The service to get the key for.
Returns:
The key for the specified service.


Copyright © 1997-2008 Aduna. All Rights Reserved.