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
protected void gotSceneData ()
protected void gotSceneData (Object extras)
{
super.gotSceneData();
super.gotSceneData(extras);
// cast some scene related bits
_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
* 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;
_screg = screg;
@@ -99,15 +99,18 @@ public class SceneManager extends PlaceManager
}
// 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
* after we receive our scene information but before we're started up (and hence registered as
* 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
final int fsceneId = sceneId;
_invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") {
@Override
public void invokePersist () throws Exception {
@Override public void invokePersist () throws Exception {
_model = _screp.loadSceneModel(fsceneId);
_updates = _screp.loadUpdates(fsceneId);
_extras = _screp.loadExtras(fsceneId);
}
@Override
public void handleSuccess () {
processSuccessfulResolution(_model, _updates);
@Override public void handleSuccess () {
processSuccessfulResolution(_model, _updates, _extras);
}
@Override
public void handleFailure (Exception error) {
@Override public void handleFailure (Exception error) {
processFailedResolution(fsceneId, error);
}
protected SceneModel _model;
protected UpdateList _updates;
protected Object _extras;
});
}
@@ -240,7 +239,8 @@ public class SceneRegistry
/**
* 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
// 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
_plreg.createPlace(scene.getPlaceConfig(), new PlaceRegistry.PreStartupHook() {
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
public UpdateList loadUpdates (int sceneId)
throws PersistenceException, NoSuchSceneException
throws PersistenceException
{
return new UpdateList();
}
// documentation inherited from interface
public Object loadExtras (int sceneId)
throws PersistenceException
{
return null;
}
// documentation inherited from interface
public void applyAndRecordUpdate (SceneModel model, SceneUpdate update)
throws PersistenceException
@@ -29,21 +29,18 @@ import com.threerings.whirled.util.NoSuchSceneException;
import com.threerings.whirled.util.UpdateList;
/**
* The scene repository provides the basic interface for loading and
* updating scene data. It is used by the scene registry and though more
* scene related persistence services may be needed in a full-fledged
* application, the scene repository only encapsulates those needed by the
* scene registry and other services provided by the Whirled framework.
* The scene repository provides the basic interface for loading and updating scene data. It is
* used by the scene registry and though more scene related persistence services may be needed in a
* full-fledged application, the scene repository only encapsulates those needed by the scene
* registry and other services provided by the Whirled framework.
*/
public interface SceneRepository
{
/**
* Fetches the model for the scene with the specified scene id.
*
* @exception PersistenceException thrown if an error occurs
* attempting to load the scene data.
* @exception NoSuchSceneException thrown if no scene exists with the
* specified scene id.
* @exception PersistenceException thrown if an error occurs attempting to load the scene data.
* @exception NoSuchSceneException thrown if no scene exists with the specified scene id.
*/
public SceneModel loadSceneModel (int sceneId)
throws PersistenceException, NoSuchSceneException;
@@ -51,22 +48,26 @@ public interface SceneRepository
/**
* Fetches the set of updates associated with the specified scene.
*
* @exception PersistenceException thrown if an error occurs
* attempting to load the scene updates.
* @exception NoSuchSceneException thrown if no scene exists with the
* specified scene id.
* @exception PersistenceException thrown if an error occurs attempting to load the scene
* updates.
*/
public UpdateList loadUpdates (int sceneId)
throws PersistenceException, NoSuchSceneException;
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.
* Loads optional additional scene data. This data is loaded during the scene resolution
* process and made available to the scene manager via {@link SceneManager#gotSceneData}.
*/
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
* attempting to apply the scene update.
* @exception PersistenceException thrown if an error occurs attempting to apply the scene
* update.
*/
public void applyAndRecordUpdate (SceneModel model, SceneUpdate update)
throws PersistenceException;
@@ -123,9 +123,9 @@ public class SpotSceneManager extends SceneManager
}
@Override
protected void gotSceneData ()
protected void gotSceneData (Object extras)
{
super.gotSceneData();
super.gotSceneData(extras);
// keep a casted reference around to our scene
_sscene = (SpotScene)_scene;