org.erights.e.elib.base
Class Ejector

java.lang.Object
  |
  +--org.erights.e.elib.base.Ejector
All Implemented Interfaces:
OneArgFunc, Runnable

public class Ejector
extends Object
implements OneArgFunc, Runnable

Untamed: An Ejector implements a non-local exit construct that can return a value. It works with an EscapeExpr to cause an escape to take place. When used directly from java, a typical pattern is:


      Ejector ejector = new Ejector();
      //cause ejector to be appropriately accessible from the try
      //block
      try {
          //blah blah blah
          if (we need to exit) {
              ejector.run(result);
          }
          //blah blah blah
      } catch (Ejection ej) {
          Object result = ejector.result(ej);
      } finally {
          ejector.disable();
      }
 

Author:
Mark S. Miller

Field Summary
private  Ejection myEjection
           
private  boolean myIsEnabled
           
private  String myName
           
private  Object myResult
           
 
Constructor Summary
Ejector(String optName)
          Enabled:
 
Method Summary
 void disable()
          Enabled: To avoid confusion, one should always disable an Ejector in a finally block on the way out of its catching context.
 boolean isEnabled()
          Enabled:
 boolean isMine(Throwable t)
          Enabled: Broken out into a separate public test so Ejection catchers can easily test against several Ejectors.
 Object result(Throwable t)
          Enabled: Having caught a possible Ejection, the catcher asks an Ejector for the result corresponding to that Ejection.
 void run()
          Enabled: Non-local exit returning null.
 Object run(Object result)
          Enabled: Non-local exit returning 'result'.
 String toString()
          Suppressed:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myName

private final String myName

myIsEnabled

private boolean myIsEnabled

myResult

private Object myResult

myEjection

private Ejection myEjection
Constructor Detail

Ejector

public Ejector(String optName)
Enabled:

Parameters:
optName -
Method Detail

isEnabled

public boolean isEnabled()
Enabled:

Returns:

disable

public void disable()
Enabled: To avoid confusion, one should always disable an Ejector in a finally block on the way out of its catching context.


isMine

public boolean isMine(Throwable t)
Enabled: Broken out into a separate public test so Ejection catchers can easily test against several Ejectors.


result

public Object result(Throwable t)
Enabled: Having caught a possible Ejection, the catcher asks an Ejector for the result corresponding to that Ejection. If this Ejection was indeed thrown by this Ejector, the corresponding result returned. Otherwise, the Ejection is rethrown.


run

public void run()
Enabled: Non-local exit returning null.

Equivalent to 'run(null)'.

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

run

public Object run(Object result)
Enabled: Non-local exit returning 'result'.

Would normally return void, but to minimize on Deflectors, and since we're not returning anything anyway, we implement OneArgFunc, and so must return Object.

Specified by:
run in interface OneArgFunc

toString

public String toString()
Suppressed:

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


comments?