public class Scheduler extends Object
This class is used by the asynchronous protocol mode to asynchronously execute protocol operations. New commands can be scheduled for execution with the schedule method. The scheduler can be started and stopped with the start and stop methods. The scheduler uses a size limited queue to buffer scheduler commands. The maximum size of this queue can be set with the setThreshold method. To influence the behavior of the scheduler if new commands are enqueued and the queue is currently considered full, you can specify the throttle mode.
This class is guaranteed to be threadsafe.
| Constructor and Description |
|---|
Scheduler(Protocol protocol)
Creates and initializes a new Scheduler instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all scheduler commands from this scheduler.
|
long |
getThreshold()
Returns the maximum size of the scheduler command queue.
|
boolean |
getThrottle()
Indicates if the scheduler should automatically throttle threads that enqueue new scheduler commands.
|
boolean |
schedule(SchedulerCommand command,
SchedulerQueue.QueueEnd insertTo)
Schedules a new command for asynchronous execution.
|
void |
setThreshold(long threshold)
Sets the maximum size of the scheduler command queue.
|
void |
setThrottle(boolean throttle)
Specifies if the scheduler should automatically throttle
threads that enqueue new scheduler commands.
|
void |
start()
Starts this scheduler and the internal scheduler thread.
|
void |
stop()
Stops this scheduler and the internal scheduler thread.
|
public static final Logger logger
public Scheduler(Protocol protocol)
protocol - The protocol on which to execute the actual operations like
connect, disconnect, write or dispatchpublic void start()
This method must be called before scheduling new commands with the schedule method. Call stop to stop the internal thread when the scheduler is no longer needed. Note that this method starts the internal scheduler thread only once. This means that subsequent calls to this method have no effect.
public void stop()
This is the matching method for start. After calling this method, new commands will no longer be accepted by schedule and are ignored. This method blocks until the internal thread has processed the current content of the queue. Call clear before calling stop to exit the internal thread as soon as possible.
public long getThreshold()
To influence the behavior of the scheduler if new commands
are enqueued and the queue is currently considered full,
you can specify the throttle mode.
public void setThreshold(long threshold)
To influence the behavior of the scheduler if new commands are enqueued and the queue is currently considered full, you can specify the throttle mode.
threshold - The new maximum size of the scheduler command queuepublic boolean getThrottle()
If this method returns true and the queue is considered full when enqueuing new commands, the enqueuing thread is automatically throttled until there is room in the queue for the new command. In non-throttle mode, the thread is not blocked but older commands are removed from the queue.
public void setThrottle(boolean throttle)
If this method is passed true and the queue is considered full when enqueuing new commands, the enqueuing thread is automatically throttled until there is room in the queue for the new command. In non-throttle mode, the thread is not blocked but older commands are removed from the queue.
throttle - Pass true if the scheduler should automatically throttle
threads that enqueue new scheduler commands and false
otherwisepublic boolean schedule(SchedulerCommand command, SchedulerQueue.QueueEnd insertTo)
setThreshold(long)).command - The command to scheduleinsertTo - End of a queue to insert a command topublic void clear()
Copyright © 2023. All rights reserved.