Fixed up cluster object handling; wasn't doing the right thing on

reconnect and needs to know the name of the field to listen for to avoid
issuing rapid-fire subscription requests.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2546 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-05-06 00:21:59 +00:00
parent b9fdc60650
commit 061e27d54c
2 changed files with 45 additions and 33 deletions
@@ -1,5 +1,5 @@
// //
// $Id: SpotSceneDirector.java,v 1.28 2003/04/07 21:50:04 mdb Exp $ // $Id: SpotSceneDirector.java,v 1.29 2003/05/06 00:21:59 mdb Exp $
package com.threerings.whirled.spot.client; package com.threerings.whirled.spot.client;
@@ -271,22 +271,17 @@ public class SpotSceneDirector extends BasicDirector
return true; return true;
} }
// documentation inherited // documentation inherited from interface
public void objectAvailable (DObject object) public void objectAvailable (DObject object)
{ {
// we've got our cluster chat object, configure the chat director clearCluster();
// with it and keep a reference ourselves _clobj = object;
if (_chatdir != null) { if (_chatdir != null) {
// unwire and clear out our cluster chat object if we've got one
clearCluster();
// set up the new cluster object
_chatdir.addAuxiliarySource(object, CLUSTER_CHAT_TYPE); _chatdir.addAuxiliarySource(object, CLUSTER_CHAT_TYPE);
_clobj = object;
} }
} }
// documentation inherited // documentation inherited from interface
public void requestFailed (int oid, ObjectAccessException cause) public void requestFailed (int oid, ObjectAccessException cause)
{ {
Log.warning("Unable to subscribe to cluster chat object " + Log.warning("Unable to subscribe to cluster chat object " +
@@ -296,25 +291,13 @@ public class SpotSceneDirector extends BasicDirector
// documentation inherited from interface // documentation inherited from interface
public void attributeChanged (AttributeChangedEvent event) public void attributeChanged (AttributeChangedEvent event)
{ {
int cloid = _self.getClusterOid(); if (event.getName().equals(_self.getClusterField()) &&
if ((_clobj == null && cloid <= 0) || !event.getValue().equals(event.getOldValue())) {
(_clobj != null && cloid == _clobj.getOid())) { maybeUpdateCluster();
// our cluster didn't change, we can stop now
return;
}
// clear out any old cluster object
clearCluster();
// if there's a new cluster object, subscribe to it
if (_chatdir != null && cloid > 0) {
DObjectManager omgr = _ctx.getDObjectManager();
// we'll wire up to the chat director when this completes
omgr.subscribeToObject(cloid, this);
} }
} }
// documentation inherited from interface // documentation inherited
public void clientDidLogon (Client client) public void clientDidLogon (Client client)
{ {
super.clientDidLogon(client); super.clientDidLogon(client);
@@ -322,9 +305,12 @@ public class SpotSceneDirector extends BasicDirector
// listen to the client object // listen to the client object
client.getClientObject().addListener(this); client.getClientObject().addListener(this);
_self = (ClusteredBodyObject)client.getClientObject(); _self = (ClusteredBodyObject)client.getClientObject();
// we may need to subscribe to a cluster due to session resumption
maybeUpdateCluster();
} }
// documentation inherited from interface // documentation inherited
public void clientObjectDidChange (Client client) public void clientObjectDidChange (Client client)
{ {
super.clientObjectDidChange(client); super.clientObjectDidChange(client);
@@ -363,9 +349,30 @@ public class SpotSceneDirector extends BasicDirector
{ {
// clear out our last known location id // clear out our last known location id
_location = null; _location = null;
}
// unwire and clear out our cluster chat object if we've got one /**
* Checks to see if our cluster has changed and does the necessary
* subscription machinations if necessary.
*/
protected void maybeUpdateCluster ()
{
int cloid = _self.getClusterOid();
if ((_clobj == null && cloid <= 0) ||
(_clobj != null && cloid == _clobj.getOid())) {
// our cluster didn't change, we can stop now
return;
}
// clear out any old cluster object
clearCluster(); clearCluster();
// if there's a new cluster object, subscribe to it
if (_chatdir != null && cloid > 0) {
DObjectManager omgr = _ctx.getDObjectManager();
// we'll wire up to the chat director when this completes
omgr.subscribeToObject(cloid, this);
}
} }
/** /**
@@ -374,10 +381,10 @@ public class SpotSceneDirector extends BasicDirector
*/ */
protected void clearCluster () protected void clearCluster ()
{ {
if (_chatdir != null && _clobj != null) { if (_clobj != null) {
// unwire the auxiliary chat object if (_chatdir != null) {
_chatdir.removeAuxiliarySource(_clobj); _chatdir.removeAuxiliarySource(_clobj);
// unsubscribe as well }
DObjectManager omgr = _ctx.getDObjectManager(); DObjectManager omgr = _ctx.getDObjectManager();
omgr.unsubscribeFromObject(_clobj.getOid(), this); omgr.unsubscribeFromObject(_clobj.getOid(), this);
_clobj = null; _clobj = null;
@@ -1,5 +1,5 @@
// //
// $Id: ClusteredBodyObject.java,v 1.1 2003/02/12 07:23:31 mdb Exp $ // $Id: ClusteredBodyObject.java,v 1.2 2003/05/06 00:21:59 mdb Exp $
package com.threerings.whirled.spot.data; package com.threerings.whirled.spot.data;
@@ -12,6 +12,11 @@ import com.threerings.whirled.data.ScenedBodyObject;
*/ */
public interface ClusteredBodyObject extends ScenedBodyObject public interface ClusteredBodyObject extends ScenedBodyObject
{ {
/**
* Returns the field name of the cluster oid distributed object field.
*/
public String getClusterField ();
/** /**
* Returns the oid of the cluster to which this user currently * Returns the oid of the cluster to which this user currently
* belongs. * belongs.