org.erights.e.elib.ref
Class WhenBrokenReactor

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

class WhenBrokenReactor
extends Object
implements DeadManSwitch, OneArgFunc, PassByProxy

Used to implement Ref.whenBroken(Object, OneArgFunc).

Wraps a 'done' function (the second argument of whenBroken), 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 __whenBroken, 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:
WhenResolvedReactor

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
WhenBrokenReactor(OneArgFunc wrapped, Object ref, Resolver optResolver)
          Should ref become broken, invoke wrapped, and resolve optResolver (if not null) to its outcome.
 
Method Summary
 void __reactToLostClient(Throwable problem)
          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 broken.
 
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

WhenBrokenReactor

public WhenBrokenReactor(OneArgFunc wrapped,
                         Object ref,
                         Resolver optResolver)
Should ref become broken, invoke wrapped, and resolve optResolver (if not null) to its outcome.

Assumes a first __whenBroken will be sent with this WhenBrokenReactor as argument.

Method Detail

run

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

If myRef is broken, 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. If myRef is resolved but not broken, then be clever.

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

__reactToLostClient

public void __reactToLostClient(Throwable problem)
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?