Class ServicePipeline

java.lang.Object
cloud.commandframework.services.ServicePipeline

public final class ServicePipeline extends Object
Service pipeline
  • Method Details

    • builder

      public static @NonNull ServicePipelineBuilder builder()
      Returns:
      Builder instance
    • registerServiceType

      public <Context, Result> @NonNull ServicePipeline registerServiceType(@NonNull io.leangen.geantyref.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:

      
       @Nullable
       @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
    • registerServiceImplementation

      public <Context, Result> ServicePipeline registerServiceImplementation(@NonNull io.leangen.geantyref.TypeToken<? extends Service<Context,Result>> type, @NonNull Service<Context,Result> implementation, @NonNull Collection<Predicate<Context>> filters)
      Register a service implementation for a type that is recognized by the pipeline. It is important that a call to registerServiceType(TypeToken, Service) has been made beforehand, otherwise a IllegalArgumentException will be thrown
      Type Parameters:
      Context - Service context type
      Result - Service result type
      Parameters:
      type - Service type
      implementation - Implementation of the service
      filters - Filters that will be used to determine whether or not the service gets used
      Returns:
      ServicePipeline The service pipeline instance
    • registerServiceImplementation

      public <Context, Result> ServicePipeline registerServiceImplementation(@NonNull Class<? extends Service<Context,Result>> type, @NonNull Service<Context,Result> implementation, @NonNull Collection<Predicate<Context>> filters)
      Register a service implementation for a type that is recognized by the pipeline. It is important that a call to registerServiceType(TypeToken, Service) has been made beforehand, otherwise a IllegalArgumentException will be thrown
      Type Parameters:
      Context - Service context type
      Result - Service result type
      Parameters:
      type - Service type
      implementation - Implementation of the service
      filters - Filters that will be used to determine whether or not the service gets used
      Returns:
      ServicePipeline The service pipeline instance
    • 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<Type> getRecognizedTypes()
      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<io.leangen.geantyref.TypeToken<? extends S>> getImplementations(@NonNull io.leangen.geantyref.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