Restructured things to work with the new mechanism for creating distributed

objects.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@53 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2006-08-23 23:48:07 +00:00
parent a993e2ec46
commit eed4d67b9e
9 changed files with 88 additions and 139 deletions
@@ -30,6 +30,8 @@ import com.threerings.presents.server.InvocationManager;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.crowd.server.PlaceManager;
import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.whirled.Log;
import com.threerings.whirled.data.Scene;
@@ -142,17 +144,16 @@ public class SceneRegistry
}
/**
* Requests that the specified scene be resolved, which means loaded
* into the server and initialized if the scene is not currently
* active. The supplied callback instance will be notified, on the
* dobjmgr thread, when the scene has been resolved. If the scene is
* already active, it will be notified immediately (before the call to
* {@link #resolveScene} returns).
* Requests that the specified scene be resolved, which means loaded into
* the server and initialized if the scene is not currently active. The
* supplied callback instance will be notified, on the dobjmgr thread, when
* the scene has been resolved. If the scene is already active, it will be
* notified immediately (before the call to {@link #resolveScene} returns).
*
* @param sceneId the id of the scene to resolve.
* @param target a reference to a callback instance that will be
* notified when the scene has been resolved (which may be immediately
* if the scene is already active).
* @param target a reference to a callback instance that will be notified
* when the scene has been resolved (which may be immediately if the scene
* is already active).
*/
public void resolveScene (int sceneId, ResolutionListener target)
{
@@ -239,7 +240,7 @@ public class SceneRegistry
* Called when the scene resolution has completed successfully.
*/
protected void processSuccessfulResolution (
SceneModel model, UpdateList updates)
SceneModel model, final UpdateList updates)
{
// now that the scene is loaded, we can create a scene manager for
// it. that will be initialized by the place registry and when
@@ -248,17 +249,21 @@ public class SceneRegistry
try {
// first create our scene instance
Scene scene = _scfact.createScene(
final Scene scene = _scfact.createScene(
model, _confact.createPlaceConfig(model));
// now create our scene manager
SceneManager scmgr = (SceneManager)
CrowdServer.plreg.createPlace(scene.getPlaceConfig(), null);
scmgr.setSceneData(scene, updates, this);
CrowdServer.plreg.createPlace(scene.getPlaceConfig(),
new PlaceRegistry.PreStartupHook() {
public void invoke (PlaceManager pmgr) {
((SceneManager)pmgr).setSceneData(
scene, updates, SceneRegistry.this);
}
});
// when the scene manager completes its startup procedings, it
// will call back to the scene registry and let us know that
// we can turn the penders loose
// when the scene manager completes its startup procedings, it will
// call back to the scene registry and let us know that we can turn
// the penders loose
} catch (Exception e) {
// so close, but no cigar
@@ -462,11 +462,29 @@ public class SpotSceneManager extends SceneManager
* one another.
*/
protected class ClusterRecord extends HashIntMap
implements Subscriber
{
public ClusterRecord ()
{
CrowdServer.omgr.createObject(ClusterObject.class, this);
_clobj = CrowdServer.omgr.registerObject(new ClusterObject());
_clusters.put(_clobj.getOid(), this);
// let any mapped users know about our cluster
Iterator iter = values().iterator();
while (iter.hasNext()) {
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
body.setClusterOid(_clobj.getOid());
_clobj.addToOccupants(((BodyObject)body).getOid());
}
// configure our cluster record and publish it
_cluster.clusterOid = _clobj.getOid();
_ssobj.addToClusters(_cluster);
// if we didn't manage to add our creating user when we first
// started up, there's no point in our sticking around
if (size() == 0) {
destroy(true);
}
}
public boolean addBody (BodyObject body)
@@ -565,44 +583,6 @@ public class SpotSceneManager extends SceneManager
return _cluster;
}
public void objectAvailable (DObject object)
{
// keep this feller around
_clobj = (ClusterObject)object;
_clusters.put(_clobj.getOid(), this);
// let any mapped users know about our cluster
Iterator iter = values().iterator();
while (iter.hasNext()) {
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
body.setClusterOid(_clobj.getOid());
_clobj.addToOccupants(((BodyObject)body).getOid());
}
// configure our cluster record and publish it
_cluster.clusterOid = _clobj.getOid();
_ssobj.addToClusters(_cluster);
// if we didn't manage to add our creating user when we first
// started up, there's no point in our sticking around
if (size() == 0) {
destroy(true);
}
}
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Aiya! Failed to create cluster object " +
"[cause=" + cause + ", penders=" + size() + "].");
// let any mapped users know that we're hosed
Iterator iter = values().iterator();
while (iter.hasNext()) {
ClusteredBodyObject body = (ClusteredBodyObject)iter.next();
body.setClusterOid(-1);
}
}
public String toString ()
{
return "[cluster=" + _cluster + ", size=" + size() + "]";