public interface ManagedTaskContext
extends sirius.kernel.async.TaskContextAdapter
Managed tasks are started via ManagedTasks.createManagedTaskSetup(String)
. The subsequently started task is
given an instance of ManagedTaskContext to interact with the execution system.
ManagedTask
Modifier and Type | Method and Description |
---|---|
void |
addTiming(String counter,
long millis)
Increments the given performance counter by one and supplies a loop duration in milliseconds.
|
void |
error(Object message)
Adds an error to the task log.
|
void |
fork(String category,
Runnable runnable)
Forks a sub task in the given executor (category).
|
List<TaskLogEntry> |
getLastLogs()
Returns the latest log entries.
|
List<sirius.kernel.commons.Tuple<String,String>> |
getTimings()
Returns a list of all recorded performance counters.
|
void |
inc(String counter)
Increments the given performance counter by one.
|
boolean |
isErroneous()
Determines if the current task is erroneous
|
void |
logLimited(Object message)
Logs the given message unless the method is called to frequently.
|
void |
setLogWriter(Writer writer)
Installs a writer into the running context which is supplied with all logged messages.
|
void |
sleepMillis(long millis)
Blocks the current task for the given number of milliseconds.
|
void |
waitForForkedTasks()
Blocks the current thread until all forked tasks have completed.
|
void |
warn(Object message)
Adds a warning to the task log.
|
void logLimited(Object message)
This method has an internal rate limit and can therefore be used by loops etc. to report the progress every now and then.
A caller can rely on the rate limit and therefore can invoke this method as often as desired. Howerver one must not rely on any message to be shown.
message
- the message to add to the logs.List<TaskLogEntry> getLastLogs()
The log is limited to a sane number of entries to pevent excessive memory usage.
void setLogWriter(@Nullable Writer writer)
writer
- the writer to print all logged messages tovoid inc(String counter)
counter
- the counter to incrementvoid addTiming(String counter, long millis)
The avarage value will be computed for the given counter and gives the user a rough estimate what the current task is doing.
counter
- the counter to incrementmillis
- the current duration for the block being countedList<sirius.kernel.commons.Tuple<String,String>> getTimings()
The first part of the tuple will be the name of the counter. The second will contain the counter value along with the avarage duration (if supplied).
void warn(Object message)
message
- the message to logvoid error(Object message)
message
- the message to logvoid sleepMillis(long millis)
millis
- the number of milliseconds to blockvoid fork(String category, Runnable runnable)
category
- the category / executor to run the subtask in. Note that a deadlock can be created if the sub
task is run in the same execute as the managed task as the managed task will wait until all sub
tasks are finished!runnable
- the runnable to executevoid waitForForkedTasks()
boolean isErroneous()
Copyright © 2018. All rights reserved.