Package cloud.commandframework.services
Class ServicePipeline
- java.lang.Object
-
- cloud.commandframework.services.ServicePipeline
-
public final class ServicePipeline extends java.lang.ObjectService pipeline
-
-
Method Summary
Modifier and Type Method Description static @NonNull ServicePipelineBuilderbuilder()Create a newServicePipelineBuilder<Context,Result,S extends Service<Context,Result>>
@NonNull java.util.Collection<io.leangen.geantyref.TypeToken<? extends S>>getImplementations(@NonNull io.leangen.geantyref.TypeToken<S> type)Get a collection of all theTypeTokenof all implementations for a given type.@NonNull java.util.Collection<java.lang.reflect.Type>getRecognizedTypes()Get a collection of all the recognised service types.<Context> @NonNull ServicePump<Context>pump(@NonNull Context context)Start traversing the pipeline by providing the context that will be used to generate the results<T> @NonNull ServicePipelineregisterMethods(@NonNull T instance)Scan a given class for methods annotated withServiceImplementationand register them as service implementations.<Context,Result>
ServicePipelineregisterServiceImplementation(@NonNull io.leangen.geantyref.TypeToken<? extends Service<Context,Result>> type, @NonNull Service<Context,Result> implementation, @NonNull java.util.Collection<java.util.function.Predicate<Context>> filters)Register a service implementation for a type that is recognized by the pipeline.<Context,Result>
ServicePipelineregisterServiceImplementation(@NonNull java.lang.Class<? extends Service<Context,Result>> type, @NonNull Service<Context,Result> implementation, @NonNull java.util.Collection<java.util.function.Predicate<Context>> filters)Register a service implementation for a type that is recognized by the pipeline.<Context,Result>
@NonNull ServicePipelineregisterServiceType(@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
-
-
-
Method Detail
-
builder
public static @NonNull ServicePipelineBuilder builder()
Create a newServicePipelineBuilder- 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 typeResult- Service result type- Parameters:
type- Service typedefaultImplementation- 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 java.lang.Exception
Scan a given class for methods annotated withServiceImplementationand 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:
java.lang.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 java.util.Collection<java.util.function.Predicate<Context>> filters)
Register a service implementation for a type that is recognized by the pipeline. It is important that a call toregisterServiceType(TypeToken, Service)has been made beforehand, otherwise aIllegalArgumentExceptionwill be thrown- Type Parameters:
Context- Service context typeResult- Service result type- Parameters:
type- Service typeimplementation- Implementation of the servicefilters- 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 java.lang.Class<? extends Service<Context,Result>> type, @NonNull Service<Context,Result> implementation, @NonNull java.util.Collection<java.util.function.Predicate<Context>> filters)
Register a service implementation for a type that is recognized by the pipeline. It is important that a call toregisterServiceType(TypeToken, Service)has been made beforehand, otherwise aIllegalArgumentExceptionwill be thrown- Type Parameters:
Context- Service context typeResult- Service result type- Parameters:
type- Service typeimplementation- Implementation of the servicefilters- 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 java.util.Collection<java.lang.reflect.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 java.util.Collection<io.leangen.geantyref.TypeToken<? extends S>> getImplementations(@NonNull io.leangen.geantyref.TypeToken<S> type)
Get a collection of all theTypeTokenof all implementations for a given type.- Type Parameters:
Context- The context type.Result- The result type.S- The service type.- Parameters:
type- TheTypeTokenof 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
-
-