public abstract class Task<TT> extends java.lang.Object implements java.lang.Runnable, EventSubscriber, Fiber.Worker
| Modifier and Type | Class and Description |
|---|---|
static class |
Task.Fork |
static class |
Task.Invoke<TT> |
static class |
Task.Spawn<TT> |
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
done |
java.lang.Object |
exitResult |
protected Fiber |
fiber
The stack manager in charge of rewinding and unwinding the stack when
Task.pause() is called.
|
int |
id
Task id, automatically generated
|
protected PauseReason |
pauseReason
The reason for pausing (duh) and performs the role of a await condition
in CCS.
|
protected java.util.concurrent.atomic.AtomicBoolean |
running
running = true when it is put on the schdulers run Q (by Task.resume()).
|
protected Scheduler |
scheduler
The object responsible for handing this task to a thread when the task is
runnable.
|
Timer |
timer |
| Constructor and Description |
|---|
Task() |
| Modifier and Type | Method and Description |
|---|---|
void |
checkKill() |
java.lang.String |
dump() |
boolean |
equals(java.lang.Object obj) |
static void |
errNotWoven() |
static void |
errNotWoven(Task t) |
static void |
errorExit(java.lang.Throwable ex)
Exit the task with a throwable indicating an error condition.
|
static void |
errorExit(java.lang.Throwable ex,
Fiber f) |
void |
execute() |
void |
execute(Fiber f) |
static void |
exit(java.lang.Object aExitValue)
Analogous to System.exit, except an Object can be used as the exit value
|
static void |
exit(java.lang.Object aExitValue,
Fiber f) |
static Task |
fork(Pausable.Fork body)
Wraps the given object or lambda expression in a Task and starts that task.
|
static Task |
getCurrentTask()
This is a placeholder that doesn't do anything useful.
|
java.lang.Thread |
getExecutionThread() |
PauseReason |
getPauseReason() |
Scheduler |
getScheduler() |
static int |
getStackDepth(Task task)
The generated code calls Fiber.upEx, which in turn calls this to find out
out where the current method is w.r.t the closest _runExecute method.
|
boolean |
getState() |
int |
getTid()
return the thread ID that the task is currently running on, valid only during execute
|
int |
hashCode() |
int |
id() |
static void |
idledown()
idledown the default scheduler
|
void |
informOnExit(Mailbox<ExitMsg<TT>> exit) |
static java.lang.Object |
invoke(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object... args)
Invoke a pausable method via reflection.
|
boolean |
isDone() |
ExitMsg<TT> |
join() |
ExitMsg<TT> |
joinb() |
void |
onEvent(EventPublisher ep,
Event e) |
static void |
pause(PauseReason pauseReason)
Ask the current task to pause with a reason object, that is responsible
for resuming the task when the reason (for pausing) is not valid any
more.
|
static void |
pause(PauseReason pauseReason,
Fiber f) |
void |
pinToThread() |
void |
prePin() |
boolean |
resume()
Add itself to scheduler if it is neither already running nor done.
|
void |
resumeOnScheduler(Scheduler s) |
void |
run()
Called by WorkerThread, it is the wrapper that performs pre and post
execute processing (in addition to calling the execute(fiber) method of
the task.
|
protected void |
setPauseReason(PauseReason pr) |
Task<TT> |
setScheduler(Scheduler s) |
protected void |
setTid(int tid) |
static void |
shutdown() |
static void |
sleep(long millis) |
static Task.Invoke |
spawn(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object... args) |
static <TT> Task.Spawn<TT> |
spawn(Pausable.Spawn<TT> body)
Wraps the given object or lambda expression in a Task and starts that task.
|
Task<TT> |
start()
Used to start the task; the task doesn't resume on its own.
|
java.lang.String |
toString() |
void |
unpinFromThread() |
static void |
yield()
Yield cooperatively to the next task waiting to use the thread.
|
static void |
yield(Fiber f) |
public final int id
protected Fiber fiber
protected PauseReason pauseReason
PauseReasonprotected java.util.concurrent.atomic.AtomicBoolean running
protected volatile boolean done
protected Scheduler scheduler
public volatile java.lang.Object exitResult
public Timer timer
public int id()
public Scheduler getScheduler()
public Task<TT> start()
public static int getStackDepth(Task task)
public void onEvent(EventPublisher ep, Event e)
onEvent in interface EventSubscriberpublic java.lang.Thread getExecutionThread()
public boolean resume()
public static Task getCurrentTask() throws Pausable
Pausablepublic static void exit(java.lang.Object aExitValue)
throws Pausable
Pausablepublic static void exit(java.lang.Object aExitValue,
Fiber f)
public static void errorExit(java.lang.Throwable ex)
throws Pausable
Pausablepublic static void errorExit(java.lang.Throwable ex,
Fiber f)
public static void errNotWoven()
public static void errNotWoven(Task t)
public static java.lang.Object invoke(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object... args)
throws Pausable,
java.lang.IllegalAccessException,
java.lang.IllegalArgumentException,
java.lang.reflect.InvocationTargetException
method - : The method to be invoked. (Implementation note: the corresponding woven
method is invoked instead).obj - : The object on which the method is invoked. Can be null if the method is
static.args - : Arguments to the methodPausablejava.lang.IllegalAccessExceptionjava.lang.IllegalArgumentExceptionjava.lang.reflect.InvocationTargetExceptionpublic static void sleep(long millis)
throws Pausable
millis - to sleep. Like thread.sleep, except it doesn't throw an interrupt, and it
doesn't hog the java thread.Pausablepublic static void shutdown()
public static void yield()
throws Pausable
Pausablepublic static void yield(Fiber f)
public static void pause(PauseReason pauseReason) throws Pausable
pauseReason - the reasonPausablepublic static void pause(PauseReason pauseReason, Fiber f)
public void execute()
throws Pausable,
java.lang.Exception
execute in interface Fiber.WorkerPausablejava.lang.Exceptionpublic void execute(Fiber f) throws java.lang.Exception
execute in interface Fiber.Workerjava.lang.Exceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String dump()
public void pinToThread()
public void unpinFromThread()
protected final void setPauseReason(PauseReason pr)
public final PauseReason getPauseReason()
public boolean isDone()
protected void setTid(int tid)
public int getTid()
public void run()
throws NotPausable
run in interface java.lang.RunnableNotPausablepublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void checkKill()
public boolean getState()
public static Task fork(Pausable.Fork body)
body - the lambda to delegate topublic static <TT> Task.Spawn<TT> spawn(Pausable.Spawn<TT> body)
body - the lambda to delegate topublic static Task.Invoke spawn(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object... args)
public static void idledown()
Scheduler.idledown()