Package io.wcm.sling.commons.caservice
Interface ContextAwareServiceCollectionResolver<S extends ContextAwareService,D>
-
- Type Parameters:
S
- Service interface or classD
- Decorator class that is calculated once for each item of the service objects collection.
- All Superinterfaces:
java.lang.AutoCloseable
@ProviderType public interface ContextAwareServiceCollectionResolver<S extends ContextAwareService,D> extends java.lang.AutoCloseable
Resolves the best-matching context-aware service implementation. This is based on a pre-populated collection of service objects in the correct order, so this collection resolver only filters the list by respecting the resource context and configured service/bundle properties. The services in the collections are expected to be sorted by ranking (highest to lowest).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
It is recommended to close the collection resolver instance when the using OSGi component is deactivated.S
resolve(@Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves the best-matching service implementation for the given resource context.@NotNull java.util.stream.Stream<S>
resolveAll(@Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves all matching service implementations for the given resource context wrapped in it's decorator.@NotNull java.util.stream.Stream<D>
resolveAllDecorated(@Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves all matching service implementations for the given resource context each one wrapped in it's decorator.D
resolveDecorated(@Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves the best-matching service implementation for the given resource context.
-
-
-
Method Detail
-
resolve
@Nullable S resolve(@Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves the best-matching service implementation for the given resource context. Only implementations which accept the given context resource path (via the service properties defined inContextAwareService
) are considered as candidates. If multiple candidates exist the implementation with the highest service ranking is returned.- Parameters:
adaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.- Returns:
- Service implementation or null if no match found.
-
resolveAll
@NotNull @NotNull java.util.stream.Stream<S> resolveAll(@Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves all matching service implementations for the given resource context wrapped in it's decorator. Only implementations which accept the given context resource path (via the service properties defined inContextAwareService
) are considered as candidates. The candidates are returned ordered descending by their service ranking.- Parameters:
adaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.- Returns:
- All matching services
-
resolveDecorated
@Nullable D resolveDecorated(@Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves the best-matching service implementation for the given resource context. Only implementations which accept the given context resource path (via the service properties defined inContextAwareService
) are considered as candidates. If multiple candidates exist the implementation with the highest service ranking is returned.- Parameters:
adaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.- Returns:
- Decorated service implementation or null if no match found.
-
resolveAllDecorated
@NotNull @NotNull java.util.stream.Stream<D> resolveAllDecorated(@Nullable @Nullable org.apache.sling.api.adapter.Adaptable adaptable)
Resolves all matching service implementations for the given resource context each one wrapped in it's decorator. Only implementations which accept the given context resource path (via the service properties defined inContextAwareService
) are considered as candidates. The candidates are returned ordered descending by their service ranking.- Parameters:
adaptable
- Adaptable which is either aResource
orSlingHttpServletRequest
. A resource instance is used directly for matching, in case of request the associated resource is used. May be null if no context is available.- Returns:
- All matching decorated services
-
close
void close()
It is recommended to close the collection resolver instance when the using OSGi component is deactivated. Internally, the implementation uses a cache to keep used service reference. Calling the close methods will invalidate this cache an unget all service references.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-