org.erights.e.elib.ref
Class ProxyResolver

java.lang.Object
  |
  +--org.erights.e.elib.ref.ProxyResolver
All Implemented Interfaces:
Resolver

public class ProxyResolver
extends Object
implements Resolver

Untamed: A maker on demand of a Proxy as well as the resolver of this Proxy.

I use a WeakPtr to point at my Ref so it may be GCed. Note that ProxyResolver exposes its ProxyHandler. If this isn't suitable for you, wrap it.

Author:
Mark S. Miller

Field Summary
private  ProxyHandler myOptHandler
          While my Ref is handled, it delegates many of my decisions to this handler.
private  Object myOptIdentity
          The basis for the settled identity of the FarRef I make, or null if I make a RemotePromise.
private  WeakPtr myOptRefPtr
          Once it's done, it stops holding the weak ptr.
 
Constructor Summary
ProxyResolver(ProxyHandler handler)
          Enabled: optIdentity defaults to null.
ProxyResolver(ProxyHandler handler, Object optIdentity)
          Enabled: @param handler Delegates delegatable eventual-ref behavior to the handler.
 
Method Summary
 void __printOn(TextWriter out)
          Enabled:
 Object getOptIdentity()
          Enabled:
static ProxyHandler getOptProxyHandler(Unsealer unsealer, Object ref)
          Enabled: If 'ref' is a remote reference over some comm system and 'unsealer' is the magic unsealer for that comm system, then return ref's ProxyHandler.
private  Ref getOptRef()
          Gets the Ref if it's still there.
 Ref getProxy()
          Enabled: Gets my Ref, or quietly remakes it if the old one is gone.
 boolean isDone()
          Enabled:
 ProxyHandler optHandler()
          Enabled:
 void reactToGC()
          Enabled: Automatically eventually invoked when one of my Refs have gone away.
 void resolve(Object target)
          Enabled:
 boolean resolveRace(Object target)
          Enabled: Resolves the proxy to become the target.
 boolean smash(Throwable problem)
          Enabled:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myOptHandler

private ProxyHandler myOptHandler
While my Ref is handled, it delegates many of my decisions to this handler.

When I'm done, I set my handler to null.


myOptIdentity

private Object myOptIdentity
The basis for the settled identity of the FarRef I make, or null if I make a RemotePromise.


myOptRefPtr

private WeakPtr myOptRefPtr
Once it's done, it stops holding the weak ptr.

Constructor Detail

ProxyResolver

public ProxyResolver(ProxyHandler handler)
Enabled: optIdentity defaults to null.


ProxyResolver

public ProxyResolver(ProxyHandler handler,
                     Object optIdentity)
Enabled: @param handler Delegates delegatable eventual-ref behavior to the handler.

Parameters:
optIdentity - If null, the handled reference will be unresolved (a RemotePromise). If non-null, the optIdentity must be an honorary Selfless object. This includes java.math.BigInteger and net.captp.jcomm.ObjectID. The identity object serves as the basis for the sameness identity of the resulting handled resolved reference (FarRef).
Method Detail

isDone

public boolean isDone()
Enabled:

Specified by:
isDone in interface Resolver

getOptIdentity

public Object getOptIdentity()
Enabled:


getOptRef

private Ref getOptRef()
Gets the Ref if it's still there. Otherwise return null.


getProxy

public Ref getProxy()
Enabled: Gets my Ref, or quietly remakes it if the old one is gone. This enables imports to be quietly revived when DGC-ships cross in the night.


optHandler

public ProxyHandler optHandler()
Enabled:


reactToGC

public void reactToGC()
Enabled: Automatically eventually invoked when one of my Refs have gone away.

Normally just forwards the reactToGC() to myOptHandler. But, in order to avoid a race condition, it only does so if there's no current Ref. There might be a current Ref if getProxy() was called after the old Ref was GCed, but before I was notified. Note that multiple Refs might be created and GCed before I get notified, in which case I might notify myOptHandler multiple times.


resolveRace

public boolean resolveRace(Object target)
Enabled: Resolves the proxy to become the target.

In CapTP, there are two reasons this might normally happen:

  1. Communications failure making us BROKEN, or
  2. the target of a Proxy responded to a __whenMoreResolved/1, of which this ProxyResolver is the argument. XXX

Specified by:
resolveRace in interface Resolver
Parameters:
target -
Returns:
Whether this resolveRace(..) caused this Resolver to become done.

resolve

public void resolve(Object target)
Enabled:

Specified by:
resolve in interface Resolver
Parameters:
target -

smash

public boolean smash(Throwable problem)
Enabled:

Specified by:
smash in interface Resolver
Parameters:
problem -
Returns:
See Also:
Resolver.resolveRace(java.lang.Object)

__printOn

public void __printOn(TextWriter out)
               throws IOException
Enabled:

IOException

getOptProxyHandler

public static ProxyHandler getOptProxyHandler(Unsealer unsealer,
                                              Object ref)
Enabled: If 'ref' is a remote reference over some comm system and 'unsealer' is the magic unsealer for that comm system, then return ref's ProxyHandler.



comments?