Class JobWorkerPool

java.lang.Object
org.graylog.scheduler.worker.JobWorkerPool
All Implemented Interfaces:
GracefulShutdownHook

public class JobWorkerPool extends Object implements GracefulShutdownHook
Worker pool to execute jobs.
  • Constructor Details

    • JobWorkerPool

      @Inject public JobWorkerPool(String name, int poolSize, Runnable shutdownCallback, GracefulShutdownService gracefulShutdownService, com.codahale.metrics.MetricRegistry metricRegistry)
  • Method Details

    • freeSlots

      public int freeSlots()
      Returns the number of free slots in the worker pool.
      Returns:
      numer of free slots
    • hasFreeSlots

      public boolean hasFreeSlots()
      Checks if there are free slots in the worker pool
      Returns:
      true if there are free slots, false otherwise
    • anySlotsUsed

      public boolean anySlotsUsed()
      Checks if there are any slots used in the worker pool
      Returns:
      true if there are slots used, false otherwise
    • execute

      public boolean execute(Runnable job)
      Exeute the given job in the worker pool if there are any free slots.
      Parameters:
      job - the job to execute
      Returns:
      true if the job could be executed, false otherwise
    • doGracefulShutdown

      public void doGracefulShutdown() throws Exception
      Description copied from interface: GracefulShutdownHook
      Execute shutdown tasks for the service that implements this interface.

      Warning:

      • This method is called from another thread so the class that implements GracefulShutdownHook must be thread-safe.
      • The server shutdown is waiting for this method call to complete. Blocking this method will block the server shutdown!
      Specified by:
      doGracefulShutdown in interface GracefulShutdownHook
      Throws:
      Exception