Add support for loading extra data (in addition to the scene model and its

updates) during the scene resolution process which is then passed to the
manager during initialization. This is useful for information that lives in the
scene distributed object and needs to be put there before anyone arrives in the
scene.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@783 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2008-12-04 18:08:16 +00:00
parent 2c8c193705
commit 47f24a152f
6 changed files with 48 additions and 37 deletions
@@ -205,9 +205,9 @@ public class StageSceneManager extends SpotSceneManager
} }
@Override // documentation inherited @Override // documentation inherited
protected void gotSceneData () protected void gotSceneData (Object extras)
{ {
super.gotSceneData(); super.gotSceneData(extras);
// cast some scene related bits // cast some scene related bits
_sscene = (StageScene)_scene; _sscene = (StageScene)_scene;
@@ -83,7 +83,7 @@ public class SceneManager extends PlaceManager
* Called by the scene registry once the scene manager has been created (and initialized), but * Called by the scene registry once the scene manager has been created (and initialized), but
* before it is started up. * before it is started up.
*/ */
protected void setSceneData (Scene scene, UpdateList updates, SceneRegistry screg) protected void setSceneData (Scene scene, UpdateList updates, Object extras, SceneRegistry screg)
{ {
_scene = scene; _scene = scene;
_screg = screg; _screg = screg;
@@ -99,15 +99,18 @@ public class SceneManager extends PlaceManager
} }
// let derived classes react to the receipt of scene data // let derived classes react to the receipt of scene data
gotSceneData(); gotSceneData(extras);
} }
/** /**
* A method that can be overridden by derived classes to perform initialization processing * A method that can be overridden by derived classes to perform initialization processing
* after we receive our scene information but before we're started up (and hence registered as * after we receive our scene information but before we're started up (and hence registered as
* an active place). * an active place).
*
* @param extras optional additional information supplied by the repository when the scene was
* loaded, or null if the repository provided no extras.
*/ */
protected void gotSceneData () protected void gotSceneData (Object extras)
{ {
} }
@@ -168,21 +168,20 @@ public class SceneRegistry
// otherwise we have to load the scene from the repository // otherwise we have to load the scene from the repository
final int fsceneId = sceneId; final int fsceneId = sceneId;
_invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") { _invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") {
@Override @Override public void invokePersist () throws Exception {
public void invokePersist () throws Exception {
_model = _screp.loadSceneModel(fsceneId); _model = _screp.loadSceneModel(fsceneId);
_updates = _screp.loadUpdates(fsceneId); _updates = _screp.loadUpdates(fsceneId);
_extras = _screp.loadExtras(fsceneId);
} }
@Override @Override public void handleSuccess () {
public void handleSuccess () { processSuccessfulResolution(_model, _updates, _extras);
processSuccessfulResolution(_model, _updates);
} }
@Override @Override public void handleFailure (Exception error) {
public void handleFailure (Exception error) {
processFailedResolution(fsceneId, error); processFailedResolution(fsceneId, error);
} }
protected SceneModel _model; protected SceneModel _model;
protected UpdateList _updates; protected UpdateList _updates;
protected Object _extras;
}); });
} }
@@ -240,7 +239,8 @@ public class SceneRegistry
/** /**
* Called when the scene resolution has completed successfully. * Called when the scene resolution has completed successfully.
*/ */
protected void processSuccessfulResolution (SceneModel model, final UpdateList updates) protected void processSuccessfulResolution (
SceneModel model, final UpdateList updates, final Object extras)
{ {
// now that the scene is loaded, we can create a scene manager for it. that will be // now that the scene is loaded, we can create a scene manager for it. that will be
// initialized by the place registry and when that is finally complete, then we can let our // initialized by the place registry and when that is finally complete, then we can let our
@@ -253,7 +253,7 @@ public class SceneRegistry
// now create our scene manager // now create our scene manager
_plreg.createPlace(scene.getPlaceConfig(), new PlaceRegistry.PreStartupHook() { _plreg.createPlace(scene.getPlaceConfig(), new PlaceRegistry.PreStartupHook() {
public void invoke (PlaceManager pmgr) { public void invoke (PlaceManager pmgr) {
((SceneManager)pmgr).setSceneData(scene, updates, SceneRegistry.this); ((SceneManager)pmgr).setSceneData(scene, updates, extras, SceneRegistry.this);
} }
}); });
@@ -47,11 +47,18 @@ public class DummySceneRepository implements SceneRepository
// documentation inherited from interface // documentation inherited from interface
public UpdateList loadUpdates (int sceneId) public UpdateList loadUpdates (int sceneId)
throws PersistenceException, NoSuchSceneException throws PersistenceException
{ {
return new UpdateList(); return new UpdateList();
} }
// documentation inherited from interface
public Object loadExtras (int sceneId)
throws PersistenceException
{
return null;
}
// documentation inherited from interface // documentation inherited from interface
public void applyAndRecordUpdate (SceneModel model, SceneUpdate update) public void applyAndRecordUpdate (SceneModel model, SceneUpdate update)
throws PersistenceException throws PersistenceException
@@ -29,21 +29,18 @@ import com.threerings.whirled.util.NoSuchSceneException;
import com.threerings.whirled.util.UpdateList; import com.threerings.whirled.util.UpdateList;
/** /**
* The scene repository provides the basic interface for loading and * The scene repository provides the basic interface for loading and updating scene data. It is
* updating scene data. It is used by the scene registry and though more * used by the scene registry and though more scene related persistence services may be needed in a
* scene related persistence services may be needed in a full-fledged * full-fledged application, the scene repository only encapsulates those needed by the scene
* application, the scene repository only encapsulates those needed by the * registry and other services provided by the Whirled framework.
* scene registry and other services provided by the Whirled framework.
*/ */
public interface SceneRepository public interface SceneRepository
{ {
/** /**
* Fetches the model for the scene with the specified scene id. * Fetches the model for the scene with the specified scene id.
* *
* @exception PersistenceException thrown if an error occurs * @exception PersistenceException thrown if an error occurs attempting to load the scene data.
* attempting to load the scene data. * @exception NoSuchSceneException thrown if no scene exists with the specified scene id.
* @exception NoSuchSceneException thrown if no scene exists with the
* specified scene id.
*/ */
public SceneModel loadSceneModel (int sceneId) public SceneModel loadSceneModel (int sceneId)
throws PersistenceException, NoSuchSceneException; throws PersistenceException, NoSuchSceneException;
@@ -51,22 +48,26 @@ public interface SceneRepository
/** /**
* Fetches the set of updates associated with the specified scene. * Fetches the set of updates associated with the specified scene.
* *
* @exception PersistenceException thrown if an error occurs * @exception PersistenceException thrown if an error occurs attempting to load the scene
* attempting to load the scene updates. * updates.
* @exception NoSuchSceneException thrown if no scene exists with the
* specified scene id.
*/ */
public UpdateList loadUpdates (int sceneId) public UpdateList loadUpdates (int sceneId)
throws PersistenceException, NoSuchSceneException; throws PersistenceException;
/** /**
* Applise the supplied scene update to persistent representation of * Loads optional additional scene data. This data is loaded during the scene resolution
* its associated scene, then stores the update persistently for * process and made available to the scene manager via {@link SceneManager#gotSceneData}.
* future invocations of the server to load. <em>Note:</em> the scene */
* update will have already been applied to the supplied scene model. public Object loadExtras (int sceneId)
throws PersistenceException;
/**
* Applise the supplied scene update to persistent representation of its associated scene, then
* stores the update persistently for future invocations of the server to load. <em>Note:</em>
* the scene update will have already been applied to the supplied scene model.
* *
* @exception PersistenceException thrown if an error occurs * @exception PersistenceException thrown if an error occurs attempting to apply the scene
* attempting to apply the scene update. * update.
*/ */
public void applyAndRecordUpdate (SceneModel model, SceneUpdate update) public void applyAndRecordUpdate (SceneModel model, SceneUpdate update)
throws PersistenceException; throws PersistenceException;
@@ -123,9 +123,9 @@ public class SpotSceneManager extends SceneManager
} }
@Override @Override
protected void gotSceneData () protected void gotSceneData (Object extras)
{ {
super.gotSceneData(); super.gotSceneData(extras);
// keep a casted reference around to our scene // keep a casted reference around to our scene
_sscene = (SpotScene)_scene; _sscene = (SpotScene)_scene;