Package org.glassfish.hk2.api
Interface IterableProvider<T>
-
- Type Parameters:
T
- The type of this IterableProvider
- All Superinterfaces:
java.lang.Iterable<T>
,javax.inject.Provider<T>
- All Known Implementing Classes:
IterableProviderImpl
public interface IterableProvider<T> extends javax.inject.Provider<T>, java.lang.Iterable<T>
This object can be injected rather thanProvider
when it is desired to iterate over more than one returned instance of the type. This interface also has several methods which allow the user to further narrow down the selected services at runtime. It can also provide anIterable
ofServiceHandle
for finer control of the lifecycle of services foundThe iterator returned will be in ranked order (with DescriptorRank as primary key, largest rank first and ServiceID as secondary key, smallest id first)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ServiceHandle<T>
getHandle()
Rather than getting the service directly with get (in which case the returned service cannot be disposed of) this method will instead return a service handle for the current best service.int
getSize()
Returns the size of the iterator that would be returnedjava.lang.Iterable<ServiceHandle<T>>
handleIterator()
This version of iterator returns an iterator of ServiceHandles rather than returning the services (which then have no way to be properly destroyed)IterableProvider<T>
named(java.lang.String name)
Returns an IterableProvider that is further qualified with the given name<U> IterableProvider<U>
ofType(java.lang.reflect.Type type)
Returns an IterableProvider that is of the given type.IterableProvider<T>
qualifiedWith(java.lang.annotation.Annotation... qualifiers)
A set of qualifiers to further restrict this iterator to.
-
-
-
Method Detail
-
getHandle
ServiceHandle<T> getHandle()
Rather than getting the service directly with get (in which case the returned service cannot be disposed of) this method will instead return a service handle for the current best service.- Returns:
- A ServiceHandle for the service, or null if there is currently no service definition available
-
getSize
int getSize()
Returns the size of the iterator that would be returned- Returns:
- the size of the iterator that would be chosen
-
named
IterableProvider<T> named(java.lang.String name)
Returns an IterableProvider that is further qualified with the given name- Parameters:
name
- The value field of the Named annotation parameter. Must not be null- Returns:
- An iterable provider further qualified with the given name
-
ofType
<U> IterableProvider<U> ofType(java.lang.reflect.Type type)
Returns an IterableProvider that is of the given type. This type must be one of the type safe contracts of the original iterator- Parameters:
type
- The type to restrict the returned iterator to- Returns:
- An iterator restricted to only providing the given type
-
qualifiedWith
IterableProvider<T> qualifiedWith(java.lang.annotation.Annotation... qualifiers)
A set of qualifiers to further restrict this iterator to.- Parameters:
qualifiers
- The qualifiers to further restrict this iterator to- Returns:
- An iterator restricted with the given qualifiers
-
handleIterator
java.lang.Iterable<ServiceHandle<T>> handleIterator()
This version of iterator returns an iterator of ServiceHandles rather than returning the services (which then have no way to be properly destroyed)- Returns:
- An iterator of ServiceHandles for the set of services represtended by this IterableProvider
-
-