|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--autohit.vm.VMContext
A VM context. It will wrap a VM in a thread and do all the thread-safe kinda stuff. A context will handle successive VM runs, so you can use them in a thread pool.
BE SURE to .start() this Thread BEFORE any other threads access its methods (particularly execute()). Failure to heed this warning COULD result in a race condition... :-)
Field Summary | |
protected VM |
rVM
A runnable VM. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY |
Constructor Summary | |
VMContext()
Constructor. |
Method Summary | |
void |
blockTillExecute()
Wait until someone calls our execute() method. |
boolean |
execute(VM aVM)
Load and Execute a VM. |
int |
getState()
A simple request for state. |
boolean |
kill()
Kill this context. |
void |
run()
Run the context |
int |
verifyState()
Verify the state of the VM. |
boolean |
vmPause()
Pause the vm. |
boolean |
vmResume()
Resume the vm. |
boolean |
vmStop()
Stop the vm. |
Methods inherited from class java.lang.Thread |
activeCount,
checkAccess,
countStackFrames,
currentThread,
destroy,
dumpStack,
enumerate,
getContextClassLoader,
getName,
getPriority,
getThreadGroup,
interrupt,
interrupted,
isAlive,
isDaemon,
isInterrupted,
join,
join,
join,
resume,
setContextClassLoader,
setDaemon,
setName,
setPriority,
sleep,
sleep,
start,
stop,
stop,
suspend,
toString,
yield |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected VM rVM
Constructor Detail |
public VMContext()
Method Detail |
public boolean execute(VM aVM)
aVM
- A fully implimented derived-class of VM.VM
public boolean vmPause()
There is no rendezvous; the method will not block. All successive requests count as the same request until the context services it. There is no guarentee on the timing of the service. The Context will not check for requests until AFTER the current instruction is complete. So, if the vm is executing a long wait instruction, it could indeed be some time before the request is serviced.
If you need to make sure that the request worked, then use the verifyState() method to get the definative state of the VM/Context.
As for the return value, "success" merely means that the request was successfully posted and not that the action was completed.
One last thaught: this is not a robust OS implimentation of a thread context. You might want to restrict calls to vmPause() and vmResume() to a single external thread. Multiple threads might get confused if they don't cooperate...
VM
public boolean vmResume()
See the notes for the pause() method.
VM
public boolean vmStop()
See the notes for the pause() method.
VM
public boolean kill()
See the notes for the pause() method.
VM
public int verifyState()
(And, never EVER call this method from within THIS thread. You'll almost certainly deadlock it.)
The following describes each state:
STATE_NEW = VM is loaded bu not started STATE_RUNNING = VM is actively running. STATE_PAUSED = VM is paused. STATE_DONE = VM finished execution. This is rare, as the VM will be automatically unloaded when finished. STATE_NO_VM = No VM is loaded into this context.
VM
public int getState()
VM
public void run()
public void blockTillExecute()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |