Interface Service<Context,Result>

Type Parameters:
Context - Context type, this will be the input that is used to generate the response
Result - Response type, this is what is produced by the service ("provided")
All Superinterfaces:
Function<@NonNull Context,@Nullable Result>
All Known Subinterfaces:
ConsumerService<Context>, PartialResultService<Context,Result,Chunked>, SideEffectService<Context>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Service<Context,Result> extends Function<@NonNull Context,@Nullable Result>
A service is anything that can take in a context, and produce a response. Most service implementations will be side effect free, although some service implementations will have side effects. Those that do, should be clearly labeled
  • Method Summary

    Modifier and Type
    Method
    Description
    default @Nullable Result
    apply(@NonNull Context context)
     
    @Nullable Result
    handle(@NonNull Context context)
    Provide a response for the given context.
    default @Nullable ExecutionOrder
    Get the execution order of the service.

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • Method Details

    • handle

      @Nullable Result handle(@NonNull Context context) throws Exception
      Provide a response for the given context. If the service implementation cannot provide a response for the given context, it should return null
      Parameters:
      context - Context used in the generation of the response
      Returns:
      Response. If the response isn't null, the next service in the service chain will get to act on the context. Otherwise the execution halts, and the provided response is the final response.
      Throws:
      Exception - Any exception that occurs during the handling can be thrown, and will be wrapped by a PipelineException
    • apply

      default @Nullable Result apply(@NonNull Context context)
      Specified by:
      apply in interface Function<Context,Result>
    • order

      default @Nullable ExecutionOrder order()
      Get the execution order of the service. This should not be overridden, unless you know what you are doing
      Returns:
      Execution order