Package org.eclipse.jetty.util.thread
Class SerializedInvoker
java.lang.Object
org.eclipse.jetty.util.thread.SerializedInvoker
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 Summary
ConstructorDescriptionCreates a new instance whose name isanonymous
.SerializedInvoker
(Class<?> nameFrom) Creates a new instance whose name is derived from the given class.SerializedInvoker
(String name) Creates a new instance with the given name.SerializedInvoker
(String name, Executor executor) Creates a new instance with the given name andExecutor
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Arrange for a task to be invoked, mutually excluded from other tasks.Arrange for tasks to be invoked, mutually excluded from other tasks.protected void
void
Arrange for a task to be run, mutually excluded from other tasks.void
Arrange for tasks to be executed, mutually excluded from other tasks.toString()
-
Constructor Details
-
SerializedInvoker
public SerializedInvoker()Creates a new instance whose name isanonymous
. -
SerializedInvoker
Creates a new instance whose name is derived from the given class.- Parameters:
nameFrom
- the class to use as a name.
-
SerializedInvoker
Creates a new instance with the given name.- Parameters:
name
- the name.
-
SerializedInvoker
Creates a new instance with the given name andExecutor
.- Parameters:
name
- the nameexecutor
- theExecutor
-
-
Method Details
-
assertCurrentThreadInvoking
- Throws:
IllegalStateException
- when the current thread is not currently executing a task using this invoker
-
offer
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
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
Arrange for a task to be run, mutually excluded from other tasks. This is equivalent to directly running anyRunnable
returned fromoffer(Runnable)
- Parameters:
task
- The task to invoke
-
run
Arrange for tasks to be executed, mutually excluded from other tasks. This is equivalent to directly running anyRunnable
returned fromoffer(Runnable...)
- Parameters:
tasks
- The tasks to invoke
-
toString
-
onError
-