Class ServiceSpigot<Context,​Result>

  • Type Parameters:
    Context - Context type
    Result - Result type

    public final class ServiceSpigot<Context,​Result>
    extends java.lang.Object
    Class that outputs results from the given context, using the specified service type
    • Method Summary

      Modifier and Type Method Description
      @NonNull ServicePump<Result> forward()
      Forward the request through the original pipeline.
      @NonNull java.util.concurrent.CompletableFuture<ServicePump<Result>> forwardAsynchronously()
      Forward the request through the original pipeline.
      @NonNull Result getResult()
      Get the first result that is generated for the given context.
      void getResult​(@NonNull java.util.function.BiConsumer<Result,​java.lang.Throwable> consumer)
      Get the first result that is generated for the given context.
      @NonNull java.util.concurrent.CompletableFuture<Result> getResultAsynchronously()
      Get the first result that is generated for the given context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getResult

        public @NonNull Result getResult()
                                  throws java.lang.IllegalStateException,
                                         PipelineException
        Get the first result that is generated for the given context. This cannot return null. If nothing manages to produce a result, an exception will be thrown. If the pipeline has been constructed properly, this will never happen.
        Returns:
        Generated result
        Throws:
        java.lang.IllegalStateException - If no result was found. This only happens if the pipeline has not been constructed properly. The most likely cause is a faulty default implementation
        java.lang.IllegalStateException - If a SideEffectService returns null
        PipelineException - Any exceptions thrown during result retrieval from the implementations will be wrapped by PipelineException. Use Throwable.getCause() to get the exception that was thrown.
        PipelineException - Any exceptions thrown during filtering will be wrapped by PipelineException. Use Throwable.getCause() to get the exception that was thrown.
        See Also:
        PipelineException wraps exceptions thrown during filtering and result retrieval
      • getResult

        public void getResult​(@NonNull java.util.function.BiConsumer<Result,​java.lang.Throwable> consumer)
        Get the first result that is generated for the given context. If nothing manages to produce a result, an exception will be thrown. If the pipeline has been constructed properly, this will never happen. The exception passed to the consumer will be unwrapped, in the case that it's a PipelineException. Thus, the actual exception will be given instead of the wrapper.
        Parameters:
        consumer - Result consumer. If an exception was wrong, the result will be null, otherwise the exception will be non-null and the exception will be null.
        Throws:
        java.lang.IllegalStateException - If no result was found. This only happens if the pipeline has not been constructed properly. The most likely cause is a faulty default implementation
        java.lang.IllegalStateException - If a SideEffectService returns null
      • getResultAsynchronously

        public @NonNull java.util.concurrent.CompletableFuture<Result> getResultAsynchronously()
        Get the first result that is generated for the given context. This cannot return null. If nothing manages to produce a result, an exception will be thrown. If the pipeline has been constructed properly, this will never happen.
        Returns:
        Generated result
      • forward

        public @NonNull ServicePump<Result> forward()
        Forward the request through the original pipeline.
        Returns:
        New pump, for the result of this request
      • forwardAsynchronously

        public @NonNull java.util.concurrent.CompletableFuture<ServicePump<Result>> forwardAsynchronously()
        Forward the request through the original pipeline.
        Returns:
        New pump, for the result of this request