Implemented the mechanism for initiating and clearing out a remote object

proxy. Untested, but hey, it probably works. :)


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4543 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-02-08 19:43:55 +00:00
parent 9a39128322
commit a1be45996b
2 changed files with 128 additions and 42 deletions
@@ -43,8 +43,9 @@ import com.threerings.util.Name;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
import com.threerings.presents.client.ClientObserver; import com.threerings.presents.client.ClientObserver;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.AttributeChangeListener; import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.EntryAddedEvent; import com.threerings.presents.dobj.EntryAddedEvent;
import com.threerings.presents.dobj.EntryRemovedEvent; import com.threerings.presents.dobj.EntryRemovedEvent;
import com.threerings.presents.dobj.EntryUpdatedEvent; import com.threerings.presents.dobj.EntryUpdatedEvent;
@@ -206,6 +207,74 @@ public class PeerManager
creds.getPassword()); creds.getPassword());
} }
/**
* Initiates a proxy on an object that is managed by the specified peer. The object will be
* proxied into this server's distributed object space and its local oid reported back to the
* supplied result listener.
*
* <p> Note that proxy requests <em>do not</em> stack like subscription requests. Only one
* entity must issue a request to proxy an object and that entity must be responsible for
* releasing the proxy when it knows that there are no longer any local subscribers to the
* object.
*/
public <T extends DObject> void proxyRemoteObject (
String nodeName, int remoteOid, final ResultListener<Integer> listener)
{
final Client peer = getPeerClient(nodeName);
if (peer == null) {
String errmsg = "Have no connection to peer [node=" + nodeName + "].";
listener.requestFailed(new ObjectAccessException(errmsg));
return;
}
final Tuple<String,Integer> key = new Tuple<String,Integer>(nodeName, remoteOid);
if (_proxies.containsKey(key)) {
String errmsg = "Cannot proxy already proxied object [key=" + key + "].";
listener.requestFailed(new ObjectAccessException(errmsg));
return;
}
// issue a request to subscribe to the remote object
peer.getDObjectManager().subscribeToObject(remoteOid, new Subscriber<T>() {
public void objectAvailable (T object) {
// make a note of this proxy mapping
_proxies.put(key, new Tuple<Subscriber<?>,DObject>(this, object));
// map the object into our local oid space
PresentsServer.omgr.registerProxyObject(object, peer.getDObjectManager());
// then tell the caller about the (now remapped) oid
listener.requestCompleted(object.getOid());
}
public void requestFailed (int oid, ObjectAccessException cause) {
listener.requestFailed(cause);
}
});
}
/**
* Unsubscribes from and clears a proxied object. The caller must be sure that there are no
* remaining subscribers to the object on this local server.
*/
public void unproxyRemoteObject (String nodeName, int remoteOid)
{
Tuple<String,Integer> key = new Tuple<String,Integer>(nodeName, remoteOid);
Tuple<Subscriber<?>,DObject> bits = _proxies.remove(key);
if (bits == null) {
log.warning("Requested to clear unknown proxy [key=" + key + "].");
return;
}
// clear out the local object manager's proxy mapping
PresentsServer.omgr.clearProxyObject(remoteOid, bits.right);
// now unsubscribe from the object on our peer
final Client peer = getPeerClient(nodeName);
if (peer == null) {
log.warning("Unable to unsubscribe from proxy, missing peer [key=" + key + "].");
return;
}
peer.getDObjectManager().unsubscribeFromObject(remoteOid, bits.left);
}
/** /**
* Returns the client object representing the connection to the named peer, or * Returns the client object representing the connection to the named peer, or
* <code>null</code> if we are not currently connected to it. * <code>null</code> if we are not currently connected to it.
@@ -850,6 +919,10 @@ public class PeerManager
protected NodeObject _nodeobj; protected NodeObject _nodeobj;
protected HashMap<String,PeerNode> _peers = new HashMap<String,PeerNode>(); protected HashMap<String,PeerNode> _peers = new HashMap<String,PeerNode>();
/** Contains a mapping of proxied objects to subscriber instances. */
protected HashMap<Tuple<String,Integer>,Tuple<Subscriber<?>,DObject>> _proxies =
new HashMap<Tuple<String,Integer>,Tuple<Subscriber<?>,DObject>>();
/** Our stale cache observers. */ /** Our stale cache observers. */
protected HashMap<String, ObserverList<StaleCacheObserver>> _cacheobs = protected HashMap<String, ObserverList<StaleCacheObserver>> _cacheobs =
new HashMap<String, ObserverList<StaleCacheObserver>>(); new HashMap<String, ObserverList<StaleCacheObserver>>();
@@ -120,6 +120,19 @@ public class PresentsDObjectMgr
_proxies.put(origObjectId, new ProxyReference(object.getOid(), omgr)); _proxies.put(origObjectId, new ProxyReference(object.getOid(), omgr));
} }
/**
* Clears a proxy object reference from our local distributed object space. This merely removes
* it from our internal tables, the caller is responsible for coordinating the deregistration
* of the object with the proxying client.
*/
public void clearProxyObject (int origObjectId, DObject object)
{
if (_proxies.remove(origObjectId) == null) {
log.warning("Missing proxy mapping for cleared proxy [ooid=" + origObjectId + "].");
}
_objects.remove(object.getOid());
}
// from interface DObjectManager // from interface DObjectManager
public boolean isManager (DObject object) public boolean isManager (DObject object)
{ {