1package com.runehive.game.task;
3import java.util.Optional;
11public abstract class Task {
26 private Optional<Object>
key = Optional.empty();
48 this.creationStackTrace = Thread.currentThread().getStackTrace();
49 this.uuid = UUID.randomUUID();
50 this.taskCreationTime = System.currentTimeMillis();
54 return uuid.toString();
82 StringBuilder sb =
new StringBuilder();
84 sb.append(ste.toString()).append(
"\n");
113 public synchronized final void cancel() {
121 public synchronized final void cancel(
boolean logout) {
149 key = Optional.ofNullable(newKey);
final long taskCreationTime
The time the task was created.
StackTraceElement[] creationStackTrace
The creation stack trace because jire likes to guess.
final synchronized void process()
synchronized final void cancel()
Cancels all subsequent executions.
int counter
A counter that determines when execution should take place.
synchronized void setRunning(boolean running)
String getCreationStackTraceStr()
boolean running
If registration has taken place.
boolean canRun()
Determines if the task can be ran.
Optional< Long > getRunStartTime()
Long getElapsedTimeFromRunStartTime()
abstract void execute()
A function representing the unit of work that will be carried out.
Task attach(Object newKey)
Attaches a new key.
Optional< Long > runStartTime
The time the task started task.run(), if null the task has not ran yet.
Task(boolean instant, int delay)
Creates a new Task.
void setDelay(int delay)
Sets the cyclic delay.
void onSchedule()
A function executed on registration.
Optional< Object > getAttachment()
boolean canSchedule()
A function executed on registration.
synchronized final void cancel(boolean logout)
Cancels all subsequent executions.
void onException(Exception e)
A function executed on thrown exceptions.
final boolean instant
If execution happens instantly upon being scheduled.
final UUID uuid
Unique task UUID which helps us identify if any tasks will lock up.
void onLoop()
A function executed when iterated over.
void onCancel(boolean logout)
A function executed on cancellation.
Task(int delay)
Creates a new Task that doesn't execute instantly.
long getTaskCreationTime()
int delay
The cyclic delay.
Optional< Object > key
An optional attachment.