Class ExecutableService

java.lang.Object
io.github.simplexdevelopment.scheduler.ExecutableService
All Implemented Interfaces:
Identifier, IService, Runnable
Direct Known Subclasses:
ServiceImpl

public abstract class ExecutableService extends Object implements IService
An abstract service class meant for easy implementation and creation of services.
  • Field Details

    • service_name

      private final String service_name
      The name of the service.
    • delay

      private final long delay
      How long the service should wait before executing the first time.
    • period

      private final long period
      How long the service should wait between executions.
    • repeating

      private final boolean repeating
      If the service should be executed once or continuously.
    • mayInterruptWhenRunning

      private final boolean mayInterruptWhenRunning
      If the service should be allowed to stop while executing.
    • parentPool

      private ServicePool parentPool
      The service's execution thread.
    • cancelled

      private boolean cancelled
      Whether the service has been cancelled or not.
  • Constructor Details

    • ExecutableService

      public ExecutableService(@NotNull @NotNull String service_name)
      Creates a new instance of an executable service. Each service is registered with a String, to allow for easy identification within the associated ServicePool.
      Parameters:
      service_name - A namespaced key which can be used to identify the service.
    • ExecutableService

      public ExecutableService(@Nullable @Nullable ServicePool parentPool, @NotNull @NotNull String service_name)
      Creates a new instance of an executable service. Each service is registered with a String, to allow for easy identification within the associated ServicePool.
      Parameters:
      parentPool - The ServicePool which this service is executing on.
      service_name - A namespaced key which can be used to identify the service.
    • ExecutableService

      public ExecutableService(@Nullable @Nullable ServicePool parentPool, @NotNull @NotNull String service_name, @Nullable @Nullable Long delay)
      Creates a new instance of an executable service. The timings are measured in ticks (20 ticks per second). You do not need to explicitly define a delay. Each service is registered with a String, to allow for easy identification within the associated ServicePool.
      Parameters:
      parentPool - The ServicePool which this service is executing on.
      service_name - A namespaced key which can be used to identify the service.
      delay - A specified amount of time (in ticks) to wait before the service runs.
    • ExecutableService

      public ExecutableService(@Nullable @Nullable ServicePool parentPool, @NotNull @NotNull String service_name, @NotNull @NotNull Long delay, @NotNull @NotNull Long period, @NotNull @NotNull Boolean repeating)
      Creates a new instance of an executable service. The timings are measured in ticks (20 ticks per second). You do not need to explicitly define a delay or a period, however if you have flagged repeating as true, and the period is null, then the period will automatically be set to 20 minutes. Each service is registered with a String, to allow for easy identification within the associated ServicePool.
      Parameters:
      parentPool - The ServicePool which this service is executing on.
      service_name - A namespaced key which can be used to identify the service.
      delay - A specified amount of time (in ticks) to wait before the service runs.
      period - How long the service should wait between service executions (in ticks).
      repeating - If the service should be scheduled for repeated executions or not.
    • ExecutableService

      public ExecutableService(@Nullable @Nullable ServicePool parentPool, @NotNull @NotNull String service_name, @Nullable @Nullable Long delay, @Nullable @Nullable Long period, @NotNull @NotNull Boolean repeating, @NotNull @NotNull Boolean mayInterruptWhenRunning)
      Creates a new instance of an executable service. The timings are measured in ticks (20 ticks per second). You do not need to explicitly define a delay or a period, however if you have flagged repeating as true, and the period is null, then the period will automatically be set to 20 minutes. Each service is registered with a String, to allow for easy identification within the associated ServicePool.
      Parameters:
      parentPool - The ServicePool which this service is executing on.
      service_name - A namespaced key which can be used to identify the service.
      delay - A specified amount of time (in ticks) to wait before the service runs.
      period - How long the service should wait between service executions (in ticks).
      repeating - If the service should be scheduled for repeated executions or not.
      mayInterruptWhenRunning - If the service can be cancelled during execution.
  • Method Details

    • getDelay

      public long getDelay()
      Specified by:
      getDelay in interface IService
      Returns:
      How long the service should wait before executing the first time.
    • getPeriod

      public long getPeriod()
      Specified by:
      getPeriod in interface IService
      Returns:
      How long the service should wait between subsequent executions.
    • isPeriodic

      public boolean isPeriodic()
      Specified by:
      isPeriodic in interface IService
      Returns:
      If the service should be scheduled for repeated executions or not.
    • isCancelled

      public boolean isCancelled()
      Cancels the execution of this service.
      Returns:
      true if the service was cancelled, false if not.
    • setCancelled

      public reactor.core.publisher.Mono<Void> setCancelled(boolean cancel)
      Cancels the execution of this service.
      Parameters:
      cancel - Whether the service should be cancelled or not.
    • cancel

      @Contract(pure=true) reactor.core.publisher.Mono<Void> cancel()
      Actual stop call, to ensure that the service actually #isCancelled().
    • getParentPool

      public reactor.core.publisher.Mono<ServicePool> getParentPool()
      Specified by:
      getParentPool in interface IService
      Returns:
      The ServicePool which this service is executing on.
    • getName

      public String getName()
      Specified by:
      getName in interface Identifier
      Returns:
      The name of the identifiable object in a readable format.
    • setParentPool

      public reactor.core.publisher.Mono<Void> setParentPool(ServicePool servicePool)
      Description copied from interface: IService
      Sets the parent pool for this service.
      Specified by:
      setParentPool in interface IService
      Parameters:
      servicePool - The service pool to attach this service to.
      Returns:
      An encapsulated Mono object representing the set operation.