GXPARSE hosted by SourceForge.net Logo

ca.gorman.xml.parse.toolkit
Class Coroutine

java.lang.Object
  extended by java.lang.Thread
      extended by ca.gorman.xml.parse.toolkit.Coroutine
All Implemented Interfaces:
Runnable

public class Coroutine
extends Thread

Extends Thread to support a coroutine thread that shares and exchanges control with a main thread. One of the two threads is always suspended. The active thread can suspend itself to initiate or continue and activity in the suspended thread. The main thread invokes yieldToCoroutine to suspend itself and allow the Coroutine thread to run.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Coroutine(Runnable runnable)
           Construct coroutine for a Runnable.
 
Method Summary
 void invokeMain(Runnable r)
           Run a command in the main thread and wait for the command to complete before control returns to the coroutine thread.
 void run()
           Begin operation, waiting for yieldToCoroutine to request output from the coroutine.
 void start()
           Start coroutine and wait for it to begin running.
 void yieldToCoroutine()
           Push a new level on callback stack and wait for callbacks from coroutine.
 void yieldToMain()
           Pop current level from callback stack and return control to main thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Coroutine

public Coroutine(Runnable runnable)

Construct coroutine for a Runnable.

Throws:
NullPointerException - if parameter is null
Method Detail

start

public void start()

Start coroutine and wait for it to begin running.

Overrides:
start in class Thread
Throws:
IllegalThreadStateException - when the coroutine thread is alive.

run

public void run()

Begin operation, waiting for yieldToCoroutine to request output from the coroutine.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
Throws:
IllegalStateException - when the method is invoked from outside the coroutine thread.

yieldToCoroutine

public void yieldToCoroutine()
                      throws ListenerException,
                             IOException

Push a new level on callback stack and wait for callbacks from coroutine.

Throws:
IllegalStateException - when the method is invoked from within the coroutine thread.
IllegalThreadStateException - when the coroutine thread is not alive.
ListenerException
IOException

invokeMain

public void invokeMain(Runnable r)

Run a command in the main thread and wait for the command to complete before control returns to the coroutine thread.

Throws:
NullPointerException - if parameter is null
IllegalStateException - when the method is invoked from outside the coroutine thread.

yieldToMain

public void yieldToMain()

Pop current level from callback stack and return control to main thread.

Throws:
AssertionError - when assertions are enabled and the method is invoked from outside the coroutine thread.

GXPARSE download

GXPARSE Generic XML Stream Parser API and supporting tools.   Release $Name: gxparse-sf-alpha-2_0 $
Copyright 2003-2004 Ian E. Gorman
Released under GNU Lesser General Public License