org.erights.e.elib.ref
Class SwitchableRef

java.lang.Object
  |
  +--org.erights.e.elib.ref.Ref
        |
        +--org.erights.e.elib.ref.SwitchableRef
All Implemented Interfaces:
Amplifiable, Callable

class SwitchableRef
extends Ref

All message asyncronously delivered to a SwitchableRef will be forwarded its current target. A SwitchableRef starts out switchable, in which case it stays EVENTUAL and does not reveal its current target. While it is switchable, its Resolver can change its target, and can make it unswitchable. Once it's unswitchable, its Resolver can do neither, and the SwitchableRef becomes equivalent to its target -- ie, it can shorten.

Author:
Mark S. Miller

Field Summary
private  boolean myIsSwitchable
          Can myTarget (and myIsSwitchable) be changed?
private  Ref myTarget
          The current destination for all messages.
 
Fields inherited from class org.erights.e.elib.ref.Ref
BROKEN, EVENTUAL, NEAR, TheViciousRef
 
Constructor Summary
(package private) SwitchableRef(Ref target)
           
 
Method Summary
 Object callAll(String verb, Object[] args)
          Suppressed: Use E.callAll(obj, verb, args) rather than obj.callAll(verb, args).
(package private)  void commit()
          Used by a resolvers to turn off switchability, and thereby make this Ref equivalent to its current target.
 boolean isResolved()
          Suppressed:
 Throwable optProblem()
          As long as I'm switchable, I'm EVENTUAL so my optProblem must be null, even if my target is BROKEN.
(package private)  Ref resolutionRef()
          If this has been shortened (target set and committed), then return that target; else return this.
 Ref sendAll(String verb, Object[] args)
          Suppressed: Use E.sendAll(obj, verb, args) rather than obj.sendAll(verb, args).
 Throwable sendAllOnly(String verb, Object[] args)
          Suppressed: Use E.sendAllOnly(obj, verb, args) rather than obj.sendAllOnly(verb, args).
 void sendMsg(Message msg)
          Override to pass the Message through to the resolved target.
(package private)  void setTarget(Ref newTarget)
          Used by a resolvers to change the target.
 String state()
          If shortened (targetted and committed), returns the target's state(); else returns EVENTUAL.
 
Methods inherited from class org.erights.e.elib.ref.Ref
broken, disconnected, getAllegedType, getOptProxyHandler, GetRefMaker, ignore, isBroken, isDeepFrozen, isDeepPassByCopy, isEventual, isFar, isNear, isPassByProxy, isPBC, isPersistent, isResolved, isSameEver, isSelfish, isSelfless, isSettled, makeBufferingPromise, makeSwitchablePromise, optBroken, optProblem, optSealedDispatch, optSealedDispatch, optShorten, promise, resolution, resolution, respondsTo, state, toCallable, toRef, toString, whenBroken, whenBrokenOnly, whenResolved, whenResolvedOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myTarget

private Ref myTarget
The current destination for all messages.


myIsSwitchable

private boolean myIsSwitchable
Can myTarget (and myIsSwitchable) be changed?

Constructor Detail

SwitchableRef

SwitchableRef(Ref target)
Method Detail

optProblem

public Throwable optProblem()
As long as I'm switchable, I'm EVENTUAL so my optProblem must be null, even if my target is BROKEN.

All implementations of optProblem/0 must be thread safe, in order for Ref.state/0 to be thread safe.

Specified by:
optProblem in class Ref
See Also:
Ref.optProblem(Object)

resolutionRef

Ref resolutionRef()
If this has been shortened (target set and committed), then return that target; else return this.

All implementations of resolutionRef/0 must be thread safe, in order for Ref.resolution/0 to be thread safe: If resolutionRef/0 is called from another thread while this ref is in the middle of being shortened, then resolutionRef/0 must return either this or what this ref is being shortened to.

XXX Although the implementation doesn't synchronize, it is inductively thread safe given a simple memory model. Is it safe in Java's complex memory model? Do we care -- are any Java implementations not faithful to the simple memory model?

Specified by:
resolutionRef in class Ref

state

public String state()
If shortened (targetted and committed), returns the target's state(); else returns EVENTUAL.

All implementations of state/0 must be thread safe, in order for Ref.isNear/1 to be thread safe.

Overrides:
state in class Ref
See Also:
Ref.state(Object)

callAll

public Object callAll(String verb,
                      Object[] args)
Description copied from class: Ref
Suppressed: Use E.callAll(obj, verb, args) rather than obj.callAll(verb, args).

Specified by:
callAll in interface Callable
Specified by:
callAll in class Ref

sendMsg

public void sendMsg(Message msg)
Override to pass the Message through to the resolved target.

Overrides:
sendMsg in class Ref

sendAll

public Ref sendAll(String verb,
                   Object[] args)
Description copied from class: Ref
Suppressed: Use E.sendAll(obj, verb, args) rather than obj.sendAll(verb, args).

Specified by:
sendAll in class Ref

sendAllOnly

public Throwable sendAllOnly(String verb,
                             Object[] args)
Description copied from class: Ref
Suppressed: Use E.sendAllOnly(obj, verb, args) rather than obj.sendAllOnly(verb, args).

Specified by:
sendAllOnly in class Ref
Returns:
Why wasn't this event queued? It isn't queued if this vat or comm connection is shut down, in which case the returned problem explains why. If null is returned, then the event was queued, though it may still not arrive.

isResolved

public boolean isResolved()
Description copied from class: Ref
Suppressed:

Specified by:
isResolved in class Ref

setTarget

void setTarget(Ref newTarget)
Description copied from class: Ref
Used by a resolvers to change the target. If newTarget is equivalent to this Ref, then this Ref becomes broken by a ViciousCycleException.

Specified by:
setTarget in class Ref

commit

void commit()
Description copied from class: Ref
Used by a resolvers to turn off switchability, and thereby make this Ref equivalent to its current target.

If the current target is already equivalent to this Ref, then this Ref becomes broken by a ViciousCycleException.

Specified by:
commit in class Ref


comments?