APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.common

public final Class SequentialScheduler

extends Object
Class Inheritance
Imports
java.util.concurrent.Executor, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.Lock, .ReentrantLock

A scheduler of ( repeatable ) tasks that MUST be run sequentially.

This class can be used as a synchronization aid that assists a number of parties in running a task in a mutually exclusive fashion.

To run the task, a party invokes runOrSchedule. To permanently prevent the task from subsequent runs, the party invokes stop.

The parties can, but do not have to, operate in different threads.

The task can be either synchronous ( completes when its run method returns ), or asynchronous ( completed when its DeferredCompleter is explicitly completed ).

The next run of the task will not begin until the previous run has finished.

The task may invoke runOrSchedule itself, which may be a normal situation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
SequentialScheduler.CompleteRestartableTask

A simple and self-contained task that completes once its run method returns.

public abstract static class
SequentialScheduler.DeferredCompleter

An interface to signal the completion of a RestartableTask.

public static class
SequentialScheduler.LockingRestartableTask

A task that runs its main loop within a block protected by a lock to provide memory visibility between runs.

public static interface
private class
SequentialScheduler.SchedulableTask

An auxiliary task that starts the restartable task: restartableTask.run(completer).

private class
SequentialScheduler.TryEndDeferredCompleter

The only concrete DeferredCompleter implementation.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private final SequentialScheduler.DeferredCompleter
private static final int
private static final int
private final SequentialScheduler.RestartableTask
private final SequentialScheduler.SchedulableTask
private final AtomicInteger
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isStopped()

Tells whether, or not, this scheduler has been permanently stopped.

public static SequentialScheduler

Returns:

a new SequentialScheduler that executes the provided mainLoop from within a LockingRestartableTask.
lockingScheduler
(Runnable
The main loop of the new sequential scheduler
mainLoop
)

Returns a new SequentialScheduler that executes the provided mainLoop from within a LockingRestartableTask.

public void
runOrSchedule()

Runs or schedules the task to be run.

public void
runOrSchedule(Executor
An executor in which to execute the task, if the task needs to be executed.
executor
)

Executes or schedules the task to be executed in the provided executor.

private void
public void
stop()

Stops this scheduler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AGAINback to summary
private static final int AGAIN
BEGINback to summary
private static final int BEGIN
completerback to summary
private final SequentialScheduler.DeferredCompleter completer
ENDback to summary
private static final int END
OFFLOADback to summary
private static final int OFFLOAD
restartableTaskback to summary
private final SequentialScheduler.RestartableTask restartableTask
schedulableTaskback to summary
private final SequentialScheduler.SchedulableTask schedulableTask
stateback to summary
private final AtomicInteger state
STOPback to summary
private static final int STOP

Constructor Detail

SequentialSchedulerback to summary
public SequentialScheduler(SequentialScheduler.RestartableTask restartableTask)

Method Detail

isStoppedback to summary
public boolean isStopped()

Tells whether, or not, this scheduler has been permanently stopped.

Should be used from inside the task to poll the status of the scheduler, pretty much the same way as it is done for threads:

if (!Thread.currentThread().isInterrupted()) {
        ...
    }
lockingSchedulerback to summary
public static SequentialScheduler lockingScheduler(Runnable mainLoop)

Returns a new SequentialScheduler that executes the provided mainLoop from within a LockingRestartableTask.

API Note

This is equivalent to calling new SequentialScheduler(new LockingRestartableTask(mainLoop)) The main loop must not perform any blocking operation.

Parameters
mainLoop:Runnable

The main loop of the new sequential scheduler

Returns:SequentialScheduler

a new SequentialScheduler that executes the provided mainLoop from within a LockingRestartableTask.

runOrScheduleback to summary
public void runOrSchedule()

Runs or schedules the task to be run.

Implementation Specification

The recursion which is possible here must be bounded:

this.runOrSchedule()
        completer.complete()
            this.runOrSchedule()
                ...

Implementation Note

The recursion in this implementation has the maximum depth of 1.

runOrScheduleback to summary
public void runOrSchedule(Executor executor)

Executes or schedules the task to be executed in the provided executor.

This method can be used when potential executing from a calling thread is not desirable.

API Note

The given executor can be null in which case calling runOrSchedule(null) is strictly equivalent to calling runOrSchedule().

Parameters
executor:Executor

An executor in which to execute the task, if the task needs to be executed.

runOrScheduleback to summary
private void runOrSchedule(SequentialScheduler.SchedulableTask task, Executor executor)
stopback to summary
public void stop()

Stops this scheduler. Subsequent invocations of runOrSchedule are effectively no-ops.

If the task has already begun, this invocation will not affect it, unless the task itself uses isStopped() method to check the state of the handler.

jdk.internal.net.http.common back to summary

public abstract Class SequentialScheduler.CompleteRestartableTask

extends Object
implements RestartableTask
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask
All Implemented Interfaces
jdk.internal.net.http.common.SequentialScheduler.RestartableTask
Known Direct Subclasses
jdk.internal.net.http.common.SequentialScheduler.LockingRestartableTask, jdk.internal.net.http.common.SSLFlowDelegate.Writer.WriterDownstreamPusher, jdk.internal.net.http.websocket.TransportImpl.SendTask, jdk.internal.net.http.websocket.TransportImpl.ReceiveTask, jdk.internal.net.http.websocket.WebSocketImpl.ReceiveTask, jdk.internal.net.http.BufferingSubscriber.DownstreamSubscription.PushDemandedTask, jdk.internal.net.http.PullPublisher.Subscription.PullTask

A simple and self-contained task that completes once its run method returns.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
protected abstract void
run()

The body of the task.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CompleteRestartableTaskback to summary
public CompleteRestartableTask()

Method Detail

runback to summary
public final void run(SequentialScheduler.DeferredCompleter taskCompleter)

Implements jdk.internal.net.http.common.SequentialScheduler.RestartableTask.run.

Doc from jdk.internal.net.http.common.SequentialScheduler.RestartableTask.run.

The body of the task.

Annotations
@Override
runback to summary
protected abstract void run()

The body of the task.

jdk.internal.net.http.common back to summary

public abstract Class SequentialScheduler.DeferredCompleter

extends Object
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.common.SequentialScheduler.DeferredCompleter
Known Direct Subclasses
jdk.internal.net.http.common.SequentialScheduler.TryEndDeferredCompleter

An interface to signal the completion of a RestartableTask.

The invocation of complete completes the task. The invocation of complete may restart the task, if an attempt has previously been made to run the task while it was already running.

API Note

DeferredCompleter is useful when a task is not necessary complete when its run method returns, but will complete at a later time, and maybe in different thread. This type exists for readability purposes at use-sites only.

Constructor Summary

AccessConstructor and Description
private
DeferredCompleter()

Extensible from this (outer) class ONLY.

Method Summary

Modifier and TypeMethod and Description
public abstract void
complete()

Completes the task.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DeferredCompleterback to summary
private DeferredCompleter()

Extensible from this (outer) class ONLY.

Method Detail

completeback to summary
public abstract void complete()

Completes the task. Must be called once, and once only.

jdk.internal.net.http.common back to summary

public final Class SequentialScheduler.LockingRestartableTask

extends CompleteRestartableTask
Class Inheritance

A task that runs its main loop within a block protected by a lock to provide memory visibility between runs. Since the main loop can't run concurrently, the lock shouldn't be contended and no deadlock should ever be possible.

Field Summary

Modifier and TypeField and Description
private final Lock
private final Runnable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask:
run

Field Detail

lockback to summary
private final Lock lock
mainLoopback to summary
private final Runnable mainLoop

Constructor Detail

LockingRestartableTaskback to summary
public LockingRestartableTask(Runnable mainLoop)

Method Detail

runback to summary
protected void run()

Implements abstract jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask.run.

Doc from jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask.run.

The body of the task.

Annotations
@Override
jdk.internal.net.http.common back to summary

public Interface SequentialScheduler.RestartableTask

Known Direct Implementers
jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask, jdk.internal.net.http.SocketTube.SocketFlowTask
Annotations
@FunctionalInterface

A restartable task.

Method Summary

Modifier and TypeMethod and Description
public void
run(SequentialScheduler.DeferredCompleter
A completer that must be invoked once, and only once, when this task is logically finished
taskCompleter
)

The body of the task.

Method Detail

runback to summary
public void run(SequentialScheduler.DeferredCompleter taskCompleter)

The body of the task.

Parameters
taskCompleter:SequentialScheduler.DeferredCompleter

A completer that must be invoked once, and only once, when this task is logically finished

jdk.internal.net.http.common back to summary

private final Class SequentialScheduler.SchedulableTask

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.common.SequentialScheduler.SchedulableTask
All Implemented Interfaces
java.lang.Runnable

An auxiliary task that starts the restartable task: restartableTask.run(completer).

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SchedulableTaskback to summary
private SchedulableTask()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
jdk.internal.net.http.common back to summary

private Class SequentialScheduler.TryEndDeferredCompleter

extends DeferredCompleter
Class Inheritance

The only concrete DeferredCompleter implementation.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void

Constructor Detail

TryEndDeferredCompleterback to summary
private TryEndDeferredCompleter()

Method Detail

completeback to summary
public void complete()

Implements abstract jdk.internal.net.http.common.SequentialScheduler.DeferredCompleter.complete.

Doc from jdk.internal.net.http.common.SequentialScheduler.DeferredCompleter.complete.

Completes the task. Must be called once, and once only.

Annotations
@Override