Package cloud.commandframework.services
Class ServicePipeline
java.lang.Object
cloud.commandframework.services.ServicePipeline
Service pipeline
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ServicePipelineBuilderbuilder()Create a newServicePipelineBuilder<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 theTypeTokenof all implementations for a given type.@NonNull Collection<Type>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 Collection<Predicate<Context>> filters) Register a service implementation for a type that is recognized by the pipeline.<Context,Result>
ServicePipelineregisterServiceImplementation(@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.<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 Details
-
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
Scan a given class for methods annotated withServiceImplementationand 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 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 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 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
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
Get a collection of all the recognised service types.- Returns:
- Returns an Immutable collection of the service types registered.
-
getImplementations
public <Context,Result, @NonNull Collection<io.leangen.geantyref.TypeToken<? extends S>> getImplementationsS extends Service<Context, Result>> (@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
-