org.qi4j.api.service.qualifier
Class ServiceQualifier
java.lang.Object
org.qi4j.api.service.qualifier.ServiceQualifier
public abstract class ServiceQualifier
- extends Object
This class helps you select a particular service
from a list. Provide a Selector which does the actual
selection from the list. A common case is to select
based on identity of the service, which you can do this way:
new ServiceQualifier(services, ServiceQualifier.withId("someId"))
Many selectors can be combined by using firstOf. Example:
new ServiceQualifier(services, firstOf(withTags("sometag"), firstActive(), first()))
This will pick a service that has the tag "sometag", or if none is found take the first active one. If no
service is active, then the first service will be picked.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ServiceQualifier
public ServiceQualifier()
firstService
public static <T> T firstService(Specification<ServiceReference<?>> qualifier,
Iterable<ServiceReference<T>> services)
withId
public static Specification<ServiceReference<?>> withId(String anId)
whereMetaInfoIs
public static Specification<ServiceReference<?>> whereMetaInfoIs(Object metaInfo)
whereActive
public static Specification<ServiceReference<?>> whereActive()
whereAvailable
public static Specification<ServiceReference<?>> whereAvailable()
withTags
public static Specification<ServiceReference<?>> withTags(String... tags)
qualifies
public abstract boolean qualifies(ServiceReference<?> service)