Package me.totalfreedom.data
Class ServiceTaskRegistry
java.lang.Object
me.totalfreedom.data.ServiceTaskRegistry
A registry for all services and tasks registered with Patchwork.
This class is not thread-safe, and should only be accessed from the main server thread.
Services are tickable tasks which execute every single game tick. They are registered using
Tasks are runnable tasks which execute at the provided times in the
ServiceSubscriptions and TaskSubscriptions can both be easily obtained using the
This class is not thread-safe, and should only be accessed from the main server thread.
Services are tickable tasks which execute every single game tick. They are registered using
registerService(ServiceSubscription) and can be started using startService(Class).
Tasks are runnable tasks which execute at the provided times in the
Task and
TaskSubscription classes. These define whether the Task is repeating, delayed, or just a one-time task. Tasks
are registered using registerTask(TaskSubscription) and can be started using startTask(Class).
ServiceSubscriptions and TaskSubscriptions can both be easily obtained using the
SubscriptionProvider utility class.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of the registry and initializes the service and task lists to new emptyArrayLists. -
Method Summary
Modifier and TypeMethodDescription<T extends Service>
@Nullable ServiceSubscription<T>getService(Class<T> clazz) Gets aServiceSubscriptionfrom the registry using the specified class.<T extends Task>
TaskSubscription<T>Gets aTaskSubscriptionfrom the registry using the specified class.<T extends Service>
voidregisterService(ServiceSubscription<T> service) Registers a service with the registry.<T extends Task>
voidregisterTask(TaskSubscription<T> task) Registers a task with the registry.voidStarts all services registered with the registry.voidStarts all tasks registered with the registry.voidstartService(Class<? extends Service> clazz) Starts a service using the specifiedServiceclass.voidStarts a task using the specifiedTaskclass.voidStops all services registered with the registry.voidStops all tasks registered with the registry.voidstopService(Class<? extends Service> clazz) Stops a service using the specifiedServiceclass.voidStops a task using the specifiedTaskclass.voidunregisterService(Class<? extends Service> clazz) Unregisters a service from the registry.voidunregisterTask(Class<? extends Task> clazz) Unregisters a task from the registry.
-
Constructor Details
-
ServiceTaskRegistry
public ServiceTaskRegistry()Creates a new instance of the registry and initializes the service and task lists to new emptyArrayLists.
-
-
Method Details
-
startAllServices
public void startAllServices()Starts all services registered with the registry.
This method should be avoided, due to the fact that modules may have registered their services after this method has already been called. In this case, it is preferred to start each service usingstartService(Class).
However, Patchwork calls this method when the server is starting up, as Patchwork is the central resource manager for registered tasks and services. Patchwork will call this method on the first server tick, so unless you are registering services AND starting them POST WORLD, you do not need to worry about starting your services. -
startAllTasks
public void startAllTasks()Starts all tasks registered with the registry.
This method should be avoided, due to the fact that modules may have registered their tasks after this method has already been called. In this case, it is preferred to start each task usingstartTask(Class).
However, Patchwork calls this method when the server is starting up, as Patchwork is the central resource manager for registered tasks and services. Patchwork will call this method on the first server tick, so unless you are registering tasks AND starting them POST WORLD, you do not need to worry about starting your tasks. -
stopAllServices
public void stopAllServices()Stops all services registered with the registry.
This method should be avoided, due to the fact that modules should be handling their own registrations. It is preferred to usestopService(Class)for each service you would like to stop.
However, Patchwork calls this method when the server is shutting down, or when Patchwork is being disabled, as Patchwork is the central resource manager for registered tasks and services. Unless you are modifying service states while the server is running, you do not need to worry about disabling or unregistering your services. -
stopAllTasks
public void stopAllTasks()Stops all tasks registered with the registry.
This method should be avoided, due to the fact that modules should be handling their own registrations. It is preferred to usestopTask(Class)for each task you would like to stop.
However, Patchwork calls this method when the server is shutting down, or when Patchwork is being disabled, as Patchwork is the central resource manager for registered tasks and services. Unless you are modifying task states while the server is running, you do not need to worry about disabling or unregistering your tasks. -
registerService
Registers a service with the registry.
Services must be registered using ServiceSubscriptions, which can be easily obtained through theSubscriptionProviderutility class.- Type Parameters:
T- A generic type for type inference of the service being registered.- Parameters:
service- The service you are trying to register.
-
registerTask
Registers a task with the registry.
Tasks must be registered using TaskSubscriptions, which can be easily obtained through theSubscriptionProviderutility class.- Type Parameters:
T- A generic type for type inference of the task being registered.- Parameters:
task- The task you are trying to register.
-
startService
Starts a service using the specifiedServiceclass.
The service should already be registered with the registry as a ServiceSubscription.- Parameters:
clazz- The class of the service you are trying to start.- See Also:
-
getService
Gets aServiceSubscriptionfrom the registry using the specified class.
The class should be the service class you are trying to locate, not the class for the subscription itself.
The service should have been registered previously as a ServiceSubscription.- Type Parameters:
T- A generic type for type inference of the service requested.- Parameters:
clazz- The class of the service you are trying to locate.- Returns:
- The
ServiceSubscriptionfor the specified class, or null if it could not be found. - See Also:
-
stopService
Stops a service using the specifiedServiceclass.
The service should already be registered with the registry as a ServiceSubscription.- Parameters:
clazz- The class of the service you are trying to stop.- See Also:
-
startTask
Starts a task using the specifiedTaskclass.
The task should already be registered with the registry as a TaskSubscription.- Parameters:
clazz- The class of the task you are trying to start.- See Also:
-
getTask
Gets aTaskSubscriptionfrom the registry using the specified class.
The class should be the task class you are trying to locate, not the class for the subscription itself.
The task should have been registered previously as a TaskSubscription.- Type Parameters:
T- A generic type for type inference of the task requested.- Parameters:
clazz- The class of the task you are trying to locate.- Returns:
- The
TaskSubscriptionfor the specified class, or null if it could not be found. - See Also:
-
stopTask
Stops a task using the specifiedTaskclass.
The task should already be registered with the registry as a TaskSubscription.- Parameters:
clazz- The class of the task you are trying to stop.- See Also:
-
unregisterService
Unregisters a service from the registry.
The service should have been registered previously as a ServiceSubscription.- Parameters:
clazz- The service you are trying to unregister.- See Also:
-
unregisterTask
Unregisters a task from the registry.
The task should have been registered previously as a TaskSubscription.- Parameters:
clazz- The task you are trying to unregister.- See Also:
-