Constructor and Description |
---|
PrioritizedTicker(Executor executor,
int portNumber) |
Modifier and Type | Method and Description |
---|---|
Executor |
getExecutor()
Get the underlying Executor.
|
void |
queueTimedJob(java.lang.Runnable job,
long offset)
Run a job after a given delay.
|
void |
queueTimedJob(java.lang.Runnable runner,
java.lang.String name,
long offset,
boolean runOnTickerAnyway,
boolean noDupes)
Queue a job at a specific time (offset in milliseconds from "now").
|
void |
queueTimedJobAbsolute(java.lang.Runnable runner,
java.lang.String name,
long time,
boolean runOnTickerAnyway,
boolean noDupes)
Queue a job at a specific time (absolute time in milliseconds).
|
void |
removeQueuedJob(java.lang.Runnable runnable)
Remove a queued job.
|
void |
run() |
protected void |
sleep(long sleepTime) |
void |
start() |
public PrioritizedTicker(Executor executor, int portNumber)
public void start()
public void run()
run
in interface java.lang.Runnable
protected void sleep(long sleepTime) throws java.lang.InterruptedException
java.lang.InterruptedException
public void queueTimedJob(java.lang.Runnable job, long offset)
Ticker
queueTimedJob
in interface Ticker
job
- The Runnable to execute.offset
- The delay in milliseconds.public void queueTimedJob(java.lang.Runnable runner, java.lang.String name, long offset, boolean runOnTickerAnyway, boolean noDupes)
queueTimedJob
in interface Ticker
runner
- The job to run. FastRunnable's get run directly on the PacketSender thread.name
- The name of the job, the thread running it will temporarily take this name,
assuming it is run on a separate thread.offset
- The time at which to run the job in milliseconds after
System.currentTimeMillis().runOnTickerAnyway
- If false, run jobs with offset <=0 on the ticker, to preserve
their thread priorities; if true, jobs to run immediately through the executor (which
normally will also preserve thread priorities, but may need to call back via
runOnTickerAnyway=true if it needs to increase the thread priority).noDupes
- Don't run this job if it is already scheduled. Relatively expensive, O(n)
with queued jobs. Necessary for Announcer to ensure that we don't get exponentially
increasing numbers of announcement check jobs queued, while ensuring that we do always
have one queued within the given period.public void queueTimedJobAbsolute(java.lang.Runnable runner, java.lang.String name, long time, boolean runOnTickerAnyway, boolean noDupes)
queueTimedJobAbsolute
in interface Ticker
time
- The time at which to run the job. @see System.currentTimeMillis()name
- The name of the thread to run it.runOnTickerAnyway
- If true, start the job from the Ticker thread even if we could pass
it directly through to the Executor. This is needed for increasing thread priorities, since
the Ticker runs at a high priority, and for some tests.noDupes
- If true, ignore the job if it is already queued. Implies runOnTickerAnyway.
WARNING: This does not guarantee that we don't run multiple copies of the job
simultaneously! You must ensure adequate locking. Worse, if the job takes an unexpectedly
long time, you could end up with many copies of the job running simultaneously.public Executor getExecutor()
Ticker
getExecutor
in interface Ticker
public void removeQueuedJob(java.lang.Runnable runnable)
Ticker
removeQueuedJob
in interface Ticker