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()
      Creates a new instance whose name is anonymous.
    • SerializedInvoker

      public SerializedInvoker(Class<?> nameFrom)
      Creates a new instance whose name is derived from the given class.
      Parameters:
      nameFrom - the class to use as a name.
    • SerializedInvoker

      public SerializedInvoker(String name)
      Creates a new instance with the given name.
      Parameters:
      name - the name.
    • SerializedInvoker

      public SerializedInvoker(String name, Executor executor)
      Creates a new instance with the given name and Executor.
      Parameters:
      name - the name
      executor - the Executor
  • Method Details

    • assertCurrentThreadInvoking

      public void assertCurrentThreadInvoking() throws IllegalStateException
      Throws:
      IllegalStateException - when the current thread is not currently executing a task using this invoker
    • 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.
    • 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)