Package com.bc.ceres.core
Class DefaultServiceRegistry<T>
- java.lang.Object
-
- com.bc.ceres.core.DefaultServiceRegistry<T>
-
- All Implemented Interfaces:
ServiceRegistry<T>
public class DefaultServiceRegistry<T> extends Object implements ServiceRegistry<T>
-
-
Constructor Summary
Constructors Constructor Description DefaultServiceRegistry(Class<T> serviceType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ServiceRegistryListener<T> listener)
Adds a new registry listener.boolean
addService(T service)
Adds a new service to this registry.List<ServiceRegistryListener<T>>
getListeners()
T
getService(String className)
Gets a registered service instance for the given class name.Set<T>
getServices()
Gets all registered services.Class<T>
getServiceType()
Gets the service type.void
removeListener(ServiceRegistryListener<T> listener)
Removes an existing registry listener.boolean
removeService(T service)
Removes an existing service from this registry.
-
-
-
Method Detail
-
getServiceType
public Class<T> getServiceType()
Gets the service type. All services in this registry are instances of this type.- Specified by:
getServiceType
in interfaceServiceRegistry<T>
- Returns:
- The service type.
-
getServices
public Set<T> getServices()
Gets all registered services.- Specified by:
getServices
in interfaceServiceRegistry<T>
- Returns:
- A set of all services.
-
getService
public T getService(String className)
Gets a registered service instance for the given class name.- Specified by:
getService
in interfaceServiceRegistry<T>
- Parameters:
className
- The name of the service's class.- Returns:
- The service instance or
null
if no such exists.
-
addService
public boolean addService(T service)
Adds a new service to this registry. The method will automatically remove an already registered service of the same type. If the registry changes due to a call of this method, a change event will be fired.- Specified by:
addService
in interfaceServiceRegistry<T>
- Parameters:
service
- The service to be added.- Returns:
true
if the service has been added.
-
removeService
public boolean removeService(T service)
Removes an existing service from this registry. If the registry changes due to a call of this method, a change event will be fired.- Specified by:
removeService
in interfaceServiceRegistry<T>
- Parameters:
service
- The service to be removed.- Returns:
true
if the service has been removed.
-
getListeners
public List<ServiceRegistryListener<T>> getListeners()
- Specified by:
getListeners
in interfaceServiceRegistry<T>
- Returns:
- The list of registry listeners.
-
addListener
public void addListener(ServiceRegistryListener<T> listener)
Adds a new registry listener.- Specified by:
addListener
in interfaceServiceRegistry<T>
- Parameters:
listener
- The registry listener to be added.
-
removeListener
public void removeListener(ServiceRegistryListener<T> listener)
Removes an existing registry listener.- Specified by:
removeListener
in interfaceServiceRegistry<T>
- Parameters:
listener
- The registry listener to be removed.
-
-