Class SerializedInvoker

java.lang.Object
org.eclipse.jetty.util.thread.SerializedInvoker

public class SerializedInvoker extends Object
Ensures serial invocation of submitted tasks.

The Invocable.InvocationType of the Runnable returned from this class is always Invocable.InvocationType.BLOCKING since a blocking task may be added to the queue at any time.

This class was inspired by the public domain class NonBlockingMutexExecutor

  • Constructor Details

    • SerializedInvoker

      public SerializedInvoker()
  • Method Details

    • offer

      public Runnable offer(Runnable task)
      Arrange for a task to be invoked, mutually excluded from other tasks.
      Parameters:
      task - The task to invoke
      Returns:
      A Runnable that must be called to invoke the passed task and possibly other tasks. Null if the task will be invoked by another caller.
    • deriveTaskName

      protected String deriveTaskName(Runnable task)
    • offer

      public Runnable offer(Runnable... tasks)
      Arrange for tasks to be invoked, mutually excluded from other tasks.
      Parameters:
      tasks - The tasks to invoke
      Returns:
      A Runnable that must be called to invoke the passed tasks and possibly other tasks. Null if the tasks will be invoked by another caller.
    • run

      public void run(Runnable task)
      Arrange for a task to be run, mutually excluded from other tasks. This is equivalent to directly running any Runnable returned from offer(Runnable)
      Parameters:
      task - The task to invoke
    • run

      public void run(Runnable... tasks)
      Arrange for tasks to be executed, mutually excluded from other tasks. This is equivalent to directly running any Runnable returned from offer(Runnable...)
      Parameters:
      tasks - The tasks to invoke
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • onError

      protected void onError(Runnable task, Throwable t)