Class ServicePipeline

    • Method Detail

      • registerServiceType

        public <Context,​Result> @NonNull ServicePipeline registerServiceType​(@NonNull TypeToken<? extends Service<@NonNull Context,​@NonNull Result>> type,
                                                                                   @NonNull Service<@NonNull Context,​@NonNull Result> defaultImplementation)
        Register a service type so that it is recognized by the pipeline
        Type Parameters:
        Context - Service context type
        Result - Service result type
        Parameters:
        type - Service type
        defaultImplementation - Default implementation of the service. This must *always* be supplied and will be the last service implementation that the pipeline attempts to access. This will never be filtered out.
        Returns:
        ServicePipeline The service pipeline instance
      • registerMethods

        public <T> @NonNull ServicePipeline registerMethods​(@NonNull T instance)
                                                     throws Exception
        Scan a given class for methods annotated with ServiceImplementation and register them as service implementations.

        The methods should be of the form:

        
         {@literal @}Nullable
         {@literal @}ServiceImplementation(YourService.class)
         public YourResult handle(YourContext) {
              return result;
         }
         
        Type Parameters:
        T - Type of the instance
        Parameters:
        instance - Instance of the class to scan
        Returns:
        Service pipeline instance
        Throws:
        Exception - Any exceptions thrown during the registration process
      • pump

        public <Context> @NonNull ServicePump<Context> pump​(@NonNull Context context)
        Start traversing the pipeline by providing the context that will be used to generate the results
        Type Parameters:
        Context - Context type
        Parameters:
        context - Context
        Returns:
        Service pumper instance
      • getRecognizedTypes

        public @NonNull Collection<TypegetRecognizedTypes()
        Get a collection of all the recognised service types.
        Returns:
        Returns an Immutable collection of the service types registered.
      • getImplementations

        public <Context,​Result,​S extends Service<Context,​Result>> @NonNull Collection<TypeToken<? extends S>> getImplementations​(@NonNull TypeToken<S> type)
        Get a collection of all the TypeToken of all implementations for a given type.
        Type Parameters:
        Context - The context type.
        Result - The result type.
        S - The service type.
        Parameters:
        type - The TypeToken of the service to get implementations for.
        Returns:
        Returns an collection of the TypeTokens of the implementations for a given service. Iterator order matches the priority when pumping contexts through the pipeline