org.qi4j.api.service
Interface ServiceFinder

All Known Subinterfaces:
Module

public interface ServiceFinder

Interface used to query for ServiceReferences. Each ServiceFinder is obtained from a specific Module, and the lookup rules are the following:

  1. First look in the same Module as the ServiceFinder
  2. Then look in the same Layer as the ServiceFinder. Any Services declared with Visibility Layer and Application should be included
  3. Then look in the used Layers. Any Services declared with Visibility Application should be included
Both native Qi4j services and imported services are considered, with preference to native services.


Method Summary
<T> ServiceReference<T>
findService(java.lang.Class<T> serviceType)
          Find a ServiceReference that implements the given type.
<T> ServiceReference<T>
findService(java.lang.reflect.Type serviceType)
          Find a ServiceReference that implements the given type.
<T> java.lang.Iterable<ServiceReference<T>>
findServices(java.lang.Class<T> serviceType)
          Find ServiceReferences that implements the given type.
<T> java.lang.Iterable<ServiceReference<T>>
findServices(java.lang.reflect.Type serviceType)
          Find ServiceReferences that implements the given type.
 

Method Detail

findService

<T> ServiceReference<T> findService(java.lang.Class<T> serviceType)
                                throws NoSuchServiceException
Find a ServiceReference that implements the given type.

Parameters:
serviceType - the type that the Service must implement
Returns:
a ServiceReference if one is found
Throws:
NoSuchServiceException - if no service of serviceType is found

findService

<T> ServiceReference<T> findService(java.lang.reflect.Type serviceType)
                                throws NoSuchServiceException
Find a ServiceReference that implements the given type.

Parameters:
serviceType - the type that the Service must implement
Returns:
a ServiceReference if one is found
Throws:
NoSuchServiceException - if no service of serviceType is found

findServices

<T> java.lang.Iterable<ServiceReference<T>> findServices(java.lang.Class<T> serviceType)
Find ServiceReferences that implements the given type.

The order of the references is such that Services more local to the querying Module is earlier in the list.

Parameters:
serviceType - the type that the Services must implement
Returns:
an iterable of ServiceReferences for the given type. It is empty if none exist

findServices

<T> java.lang.Iterable<ServiceReference<T>> findServices(java.lang.reflect.Type serviceType)
Find ServiceReferences that implements the given type.

The order of the references is such that Services more local to the querying Module is earlier in the list.

Parameters:
serviceType - the type that the Services must implement
Returns:
an iterable of ServiceReferences for the given type. It is empty if none exist