Class ServiceTaskRegistry

java.lang.Object
me.totalfreedom.data.ServiceTaskRegistry

public class ServiceTaskRegistry extends Object
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 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.
See Also:
  • Constructor Details

    • ServiceTaskRegistry

      public ServiceTaskRegistry()
      Creates a new instance of the registry and initializes the service and task lists to new empty ArrayLists.
  • 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 using startService(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 using startTask(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 use stopService(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 use stopTask(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

      public <T extends Service> void registerService(ServiceSubscription<T> service)
      Registers a service with the registry.
      Services must be registered using ServiceSubscriptions, which can be easily obtained through the SubscriptionProvider utility 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

      public <T extends Task> void registerTask(TaskSubscription<T> task)
      Registers a task with the registry.
      Tasks must be registered using TaskSubscriptions, which can be easily obtained through the SubscriptionProvider utility 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

      public void startService(Class<? extends Service> clazz)
      Starts a service using the specified Service class.
      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

      @Nullable public <T extends Service> @Nullable ServiceSubscription<T> getService(Class<T> clazz)
      Gets a ServiceSubscription from 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 ServiceSubscription for the specified class, or null if it could not be found.
      See Also:
    • stopService

      public void stopService(Class<? extends Service> clazz)
      Stops a service using the specified Service class.
      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

      public void startTask(Class<? extends Task> clazz)
      Starts a task using the specified Task class.
      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

      public <T extends Task> TaskSubscription<T> getTask(Class<T> clazz)
      Gets a TaskSubscription from 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 TaskSubscription for the specified class, or null if it could not be found.
      See Also:
    • stopTask

      public void stopTask(Class<? extends Task> clazz)
      Stops a task using the specified Task class.
      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

      public void unregisterService(Class<? extends Service> clazz)
      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

      public void unregisterTask(Class<? extends Task> clazz)
      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: