|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jsim.coroutine.Coroutine
public class Coroutine
This Coroutine class provides a more restricted form of interleaved execution than threads. In particular, only one coroutine can be in the running state at any one time. This reduces concurrency, but also simplifies synchronization problems. For certain domains such as simulation, this restricted concurrency is all that is needed. This coroutine package schedules couroutines to run in time order.
Field Summary | |
---|---|
java.lang.Thread |
life
Coroutine activity is via a thread. |
java.lang.String |
name
Name of coroutine. |
static int |
NORM_PRIORITY
Normal priority level. |
protected static java.util.logging.Logger |
trc
Time ordered list of future coroutine activations. |
Constructor Summary | |
---|---|
Coroutine(java.lang.String name)
Construct a coroutine. |
|
Coroutine(java.lang.String name,
double startTime)
%%%%%%%%%%%%%%%%%%%%%% *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constructor for testing only. |
|
Coroutine(java.lang.String name,
java.lang.Runnable runObj)
Construct a coroutine. |
Method Summary | |
---|---|
static void |
DebugPQ()
|
void |
end()
Terminate the coroutine. |
static double |
getTime()
Get the current time (i.e., now). |
boolean |
initiateJoin(java.util.HashMap<java.lang.Integer,Coroutine> hmap,
java.lang.Integer key)
Remove from hashmap and put on activation list. |
static boolean |
isTerminal()
Determine whether all coroutines have terminated. |
protected void |
joinGroup(java.util.LinkedList<Coroutine> group)
Join a special group of coroutines (e.g., those that actively move in an animation). |
protected Coroutine |
kickOut(java.util.LinkedList<Coroutine> queue)
Remove from queue and put on activation list. |
static void |
main(java.lang.String[] args)
Main method for testing purposes only. |
void |
pause(double delay)
Pause execution of coroutine for delay units of time. |
void |
preempt()
Pause execution of coroutine for delay units of time. |
void |
run()
The run method simulates a G/G/1 queue (example only). |
void |
setActTime(double coTime)
|
void |
setState(int state)
Sets the state of this coroutine |
static void |
start()
Transfer from main to first coroutine. |
java.lang.Object |
waitForJoin(java.util.HashMap<java.lang.Integer,Coroutine> hmap,
java.lang.Integer key,
Coroutine cor)
y * Indefinate wait in a hashmap. |
protected void |
waitIn(java.util.LinkedList<Coroutine> queue)
Indefinite wait in a queue. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NORM_PRIORITY
protected static java.util.logging.Logger trc
public java.lang.Thread life
public final java.lang.String name
Constructor Detail |
---|
public Coroutine(java.lang.String name, java.lang.Runnable runObj)
runObj
- Runnable objectname
- Name of coroutine.public Coroutine(java.lang.String name)
name
- Name of coroutine.public Coroutine(java.lang.String name, double startTime)
name
- Name of coroutine.startTime
- Starting time of coroutine.Method Detail |
---|
public void setState(int state)
state
- the new stateprotected void joinGroup(java.util.LinkedList<Coroutine> group)
group
- Outside list for group.public static boolean isTerminal()
public void run()
run
in interface java.lang.Runnable
public static double getTime()
protected void waitIn(java.util.LinkedList<Coroutine> queue)
queue
- Waiting queue.public java.lang.Object waitForJoin(java.util.HashMap<java.lang.Integer,Coroutine> hmap, java.lang.Integer key, Coroutine cor)
hMap
- Waiting hashmap.key
- Key object for hashmap.cor
- Coroutine to wait in hashmap.public boolean initiateJoin(java.util.HashMap<java.lang.Integer,Coroutine> hmap, java.lang.Integer key)
hmap
- Waiting hashmap.key
- Key object for hashmap.protected Coroutine kickOut(java.util.LinkedList<Coroutine> queue)
queue
- Waiting queue.
public void pause(double delay)
delay
- Delay time.public void end()
public void preempt()
public static void start()
public static void DebugPQ()
public void setActTime(double coTime)
public static void main(java.lang.String[] args)
args
- Command-line arguments.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |