org.erights.e.elib.ref
Class WhenResolvedReactor

java.lang.Object
  |
  +--org.erights.e.elib.ref.WhenResolvedReactor
All Implemented Interfaces:
DeadManSwitch, Marker, OneArgFunc, PassByProxy

class WhenResolvedReactor
extends Object
implements DeadManSwitch, OneArgFunc, PassByProxy

Used to implement Ref.whenResolved(Object, OneArgFunc), which is used to implement the when-catch construct.

Wraps a 'done' function (the second argument of whenResolved, which is the right side of the "->" of a when-catch construct), so that the done function will eventually be invoked with the original reference exactly once under the following conditions:

This object is woken up by __reactToLostClient and the response to __whenMoreResolved, but in both cases it ignores the argument and treats the message just as a wakeup call.

Author:
Mark S. Miller, Terry Stanley
See Also:
WhenBrokenReactor

Field Summary
private  Resolver myOptResolver
           
private  OneArgFunc myOptWrapped
           
private  Object myRef
           
 
Fields inherited from interface org.erights.e.elib.serial.PassByProxy
HONORARY, HONORED_NAMES
 
Constructor Summary
(package private) WhenResolvedReactor(OneArgFunc wrapped, Object ref, Resolver optResolver)
          When ref is resolved, invoke wrapped, and resolve optResolver (if non-null) to its outcome.
 
Method Summary
 void __reactToLostClient(Throwable ignored)
          Just like run/1, this is treated merely as a wakeup call to check myRef.
 Object run(Object ignored)
          Causes us to wakeup and check if myRef is resolved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myOptWrapped

private OneArgFunc myOptWrapped

myRef

private Object myRef

myOptResolver

private Resolver myOptResolver
Constructor Detail

WhenResolvedReactor

WhenResolvedReactor(OneArgFunc wrapped,
                    Object ref,
                    Resolver optResolver)
When ref is resolved, invoke wrapped, and resolve optResolver (if non-null) to its outcome.

Assumes a first __whenMoreResolved will be sent with this WhenResolvedReactor as argument.

Method Detail

run

public Object run(Object ignored)
Causes us to wakeup and check if myRef is resolved.

If myRef is resolved, then invoke myOptWrapped once (resolving myOptResolver to the outcome), and remember not to invoke it again (by forgetting it). Also forget myRef and myOptResolver, since we won't need them again. Further invocations silently return null rather than complaining.

If myRef is not resolved, then send a new


     myRef <- __whenMoreResolved(this)
 
message whose response should wake me up again.

Specified by:
run in interface OneArgFunc
Returns:
Always returns null, irrespective of what myOptWrapped.run(...) returns.

__reactToLostClient

public void __reactToLostClient(Throwable ignored)
Just like run/1, this is treated merely as a wakeup call to check myRef.

Specified by:
__reactToLostClient in interface DeadManSwitch
See Also:
org.erights.e.elib.prim.MirandaMethods#__reactToLostClient


comments?