org.erights.e.elib.vat
Class SWTRunner

java.lang.Object
  |
  +--org.erights.e.elib.vat.Runner
        |
        +--org.erights.e.elib.vat.SWTRunner
All Implemented Interfaces:
Runnable

final class SWTRunner
extends Runner
implements Runnable

A Runner executing in an SWT event loop.

XXX the orderlyShutdown feature got lost in the reorganization.

Author:
Mark S. Miller

Field Summary
private  Display myDisplay
          This Display must be created by the new RunnerThread.
private  Object myLock
          Used to wait until the RunnerThread actually creates and initializes myDisplay.
private  RunnerThread myThread
          The RunnerThread servicing this Runner's queue.
private static Object OUR_LOCK
          Guards mutable static state, ie, THE_DEFAULT
private static SWTRunner THE_DEFAULT
           
 
Fields inherited from class org.erights.e.elib.vat.Runner
myOptServingVat, myServingTicket
 
Constructor Summary
private SWTRunner(String optName)
          Makes an SWT Vat, and starts the thread that services its queue.
 
Method Summary
(package private)  void addDeadManSwitch(Object deadManSwitch)
          AWT doesn't shut down or merge, so do nothing.
(package private)  void disturbEvent(Throwable t)
          Performs a Thread.stop(t) on the thread executing the current event.
(package private)  Throwable enqueue(PendingEvent todo)
          Add todo to the queue my thread is servicing
(package private) static Runner getDefault()
          Returns the default SWTRunner -- the one managing the default Display.
(package private)  String getRunnerKind()
          What kind of Runner is this?
(package private)  boolean isCurrent()
          Is the current thread this Runner's thread (the thread servicing this Vat)?
(package private) static Runner make(String name)
          Makes an SWTRunner managing a non-default Display.
 void run()
          Called only by Thread.start().
(package private)  void setPriority(int newPriority)
          Requests a change of priority of the thread servicing this Runner.
 String toString()
          Suppressed: Returns a string representation of the object.
 
Methods inherited from class org.erights.e.elib.vat.Runner
getCurrentRunner, getOptCurrentRunner, getOptEStack, getOptServingVat, obtainRunner, obtainRunner, popEStackItem, pushEStackItem, requireCurrent, servingTicket, shorten
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OUR_LOCK

private static final Object OUR_LOCK
Guards mutable static state, ie, THE_DEFAULT


THE_DEFAULT

private static SWTRunner THE_DEFAULT

myThread

private final transient RunnerThread myThread
The RunnerThread servicing this Runner's queue.

If we ever go orthogonal again, myThread must not be checkpointed. Ie, it must be a DISALLOWED_FIELD or 'transient' or something.


myLock

private final Object myLock
Used to wait until the RunnerThread actually creates and initializes myDisplay.


myDisplay

private transient Display myDisplay
This Display must be created by the new RunnerThread.

Constructor Detail

SWTRunner

private SWTRunner(String optName)
Makes an SWT Vat, and starts the thread that services its queue.

The constructor doesn't return until myDisplay is initialized.

Parameters:
optName - is the name to give to the thread created.
Method Detail

getDefault

static Runner getDefault()
Returns the default SWTRunner -- the one managing the default Display.

The first time this is called, it will create the default SWTRunner. The first thing the runner's new thread does when it's scheduled is create a Display. If this is the first Display created in this jvm, then it will be the SWT default Display, so you should not create any Display objects before the first time this is called.


make

static Runner make(String name)
Makes an SWTRunner managing a non-default Display.

This should only be called once there is a default Display (as a result of getDefault()). Non-default Displays are not supported by SWT on all platforms.


toString

public String toString()
Description copied from class: Object
Suppressed: Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.

getRunnerKind

String getRunnerKind()
Description copied from class: Runner
What kind of Runner is this?

A kind of Runner determines which kind of "devices" (eg, AWT or SWT widgets) may be synchronously accessed from within this Runner

Specified by:
getRunnerKind in class Runner
Returns:
one of "awt", "swt", "dead", or "headless". If "headless", this makes an HeadlessRunner, which may later be redirected, so use with caution. This list may be extended over time.

enqueue

Throwable enqueue(PendingEvent todo)
Description copied from class: Runner
Add todo to the queue my thread is servicing

Specified by:
enqueue in class Runner

setPriority

void setPriority(int newPriority)
Description copied from class: Runner
Requests a change of priority of the thread servicing this Runner.

Specified by:
setPriority in class Runner

disturbEvent

void disturbEvent(Throwable t)
Description copied from class: Runner
Performs a Thread.stop(t) on the thread executing the current event.

Note that Thread.stop() does not stop the thread (obvious huh?), but rather causes that thread to experience a "spontaneously" thrown exception.

Specified by:
disturbEvent in class Runner

isCurrent

boolean isCurrent()
Description copied from class: Runner
Is the current thread this Runner's thread (the thread servicing this Vat)?

If it is, we say we are executing inside this Runner.

r.isCurrent() implies Runner.getCurrentRunner() == r.

Specified by:
isCurrent in class Runner

run

public void run()
Called only by Thread.start().

(XXX It's a modularity bug for this to be public.)

Specified by:
run in interface Runnable
See Also:
java.lang.Thread#run()

addDeadManSwitch

void addDeadManSwitch(Object deadManSwitch)
AWT doesn't shut down or merge, so do nothing.

Specified by:
addDeadManSwitch in class Runner


comments?