PSpace Async Bind Methods

These are the methods on a PSpace which allow for asynchronously binding to the IPersistable object with a given OID.


$adt+ PSpace
{
    ...
    MAsyncBind AsyncBind2(OID oid);
    ptr<IPersistable> AsyncBind(OID oid);
    ptr<IAsyncBindRequestHandler> GetAsyncBindRequestHandler() const;
    void SetAsyncBindRequestHandler(ptr<IAsyncBindRequestHandler> h);
    void DeclareObjectDoesNotExist(OID oid);
};

Application developers don't usually call these methods, instead they call AsyncGet() on a pref or cref variable within the calculation function of a $dep node or $cache function. AsyncGet() on a pref calls the following function:


$function+ ptr<IPersistable> AsyncBindObjectInMemoryGivenOid(OID oid)
{
    return GetThreadPtr<PSpace>()->AsyncBind(oid);
}

MAsyncBind AsyncBind2(OID oid)

This function doesn't block on I/O.

Must be called with a lock on the associated CSpace.

This can cause an asynchronous task to be posted to find the object in the LSS. While looking for the object in the LSS this function returns MAsyncBind(EAsyncBindResult::Pending, null). See MAsyncBind.

If the object is not found in the LSS and there is no IAsyncBindRequestHandler then this function returns MAsyncBind(EAsyncBindResult::DoesNotExist, null).

If the object is not found in the LSS and there is a IAsyncBindRequestHandler then this function returns a result according to what is returned by the call to BeginAsyncBindRequest.

Takes part in the DGS as follows:

If this function is called by a thread which is calculating an active agent, then this function causes an active DGS node to be created and recorded in a map keyed by OID (if not found already). Activity of the created DGS node causes the object to be loaded from disk asynchronously. Downstream DGS nodes in the client are invalidated once the object has been loaded.


ptr<IPersistable> AsyncBind(OID oid)

Equivalent to AsyncBind2(oid).po


ptr<IAsyncBindRequestHandler> GetAsyncBindRequestHandler() const
void SetAsyncBindRequestHandler(ptr<IAsyncBindRequestHandler> h)

A PSpace records a single ptr<IAsyncBindRequestHandler> which provides a "hook" for notification when an attempt to load an object with a given OID fails because it doesn't exist in the LSS, in order to take on responsibility for binding to the object in some other way - perhaps using object replication from another process.

When a PSpace is first created no hook is defined and a call to GetAsyncBindRequestHandler() returns null.

Both these get/set functions must be called with an exclusive lock on the associated CSpace.

Implementators of IAsyncBindRequestHandler can choose to daisy chain the handlers - i.e. save the existing hook if any, and make the new hook forward on the call to BeginAsyncBindRequest() to the previous hook depending on the OID.


void DeclareObjectDoesNotExist(OID oid)

Typically an implementor of IAsyncBindRequestHandler will record a set of oids which are pending an async bind. BeginAsyncBindRequest() can be used to insert an oid into the set, and EndAsyncBindRequest() can be used to remove it again.

For the oids that are pending, an implementor of IAsyncBindRequestHandler can resolve a given oid in one of two ways:

Calling either of these functions causes EndAsyncBindRequest() to be called.