More unit convenience.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@599 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2008-05-18 11:29:31 +00:00
parent eb6ad10295
commit 7890e26b43
2 changed files with 24 additions and 61 deletions
@@ -21,7 +21,7 @@
package com.threerings.whirled.server; package com.threerings.whirled.server;
import com.samskivert.io.PersistenceException; import com.samskivert.jdbc.WriteOnlyUnit;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import com.threerings.crowd.data.Place; import com.threerings.crowd.data.Place;
@@ -156,16 +156,9 @@ public class SceneManager extends PlaceManager
// and apply and store it in the repository // and apply and store it in the repository
if (isPersistent()) { if (isPersistent()) {
WhirledServer.invoker.postUnit(new Invoker.Unit() { WhirledServer.invoker.postUnit(new WriteOnlyUnit("recordUpdate(" + update + ")") {
public boolean invoke () { public void invokePersist () throws Exception {
try { _screg.getSceneRepository().applyAndRecordUpdate(_scene.getSceneModel(), update);
_screg.getSceneRepository().applyAndRecordUpdate(_scene.getSceneModel(),
update);
} catch (PersistenceException pe) {
Log.warning("Failed to apply scene update " + update + ".");
Log.logStackTrace(pe);
}
return false;
} }
}); });
} }
@@ -23,8 +23,8 @@ package com.threerings.whirled.server;
import java.util.ArrayList; import java.util.ArrayList;
import com.samskivert.jdbc.RepositoryUnit;
import com.samskivert.util.HashIntMap; import com.samskivert.util.HashIntMap;
import com.samskivert.util.Invoker;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.data.InvocationMarshaller;
@@ -153,62 +153,32 @@ public class SceneRegistry
{ {
SceneManager mgr = _scenemgrs.get(sceneId); SceneManager mgr = _scenemgrs.get(sceneId);
if (mgr != null) { if (mgr != null) {
// if the scene is already resolved, we're ready to roll // the scene is already resolved, we're ready to roll
target.sceneWasResolved(mgr); target.sceneWasResolved(mgr);
return; return;
} }
if (Log.debug()) { // if the scene is already being resolved, we need do no more
Log.debug("Resolving scene [id=" + sceneId + "]."); if (!addResolutionListener(sceneId, target)) {
return;
} }
// otherwise we've got to resolve the scene and call them back later; we can manipulate the // otherwise we have to load the scene from the repository
// penders table with impunity here because we only do so on the dobjmgr thread final int fsceneId = sceneId;
WhirledServer.invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") {
// Add this guy to be notified, and if nobody has yet, start resolving the scene public void invokePersist () throws Exception {
if (addResolutionListener(sceneId, target)) { _model = _screp.loadSceneModel(fsceneId);
// i don't like cluttering up method declarations with final keywords... _updates = _screp.loadUpdates(fsceneId);
final int fsceneId = sceneId;
if (Log.debug()) {
Log.debug("Invoking scene lookup [id=" + sceneId + "].");
} }
public void handleSuccess () {
// then we queue up an execution unit that'll load the scene and initialize it etc. processSuccessfulResolution(_model, _updates);
WhirledServer.invoker.postUnit(new Invoker.Unit() { }
// this is run on the invoker thread public void handleFailure (Exception error) {
public boolean invoke () { processFailedResolution(fsceneId, error);
try { }
_model = _screp.loadSceneModel(fsceneId); protected SceneModel _model;
_updates = _screp.loadUpdates(fsceneId); protected UpdateList _updates;
} catch (Exception e) { });
_cause = e;
}
return true;
}
// this is run on the dobjmgr thread
public void handleResult () {
if (_cause != null) {
processFailedResolution(fsceneId, _cause);
} else if (_model != null) {
processSuccessfulResolution(_model, _updates);
} else {
Log.warning("Scene loading unit finished with neither a scene nor a " +
"reason for failure!?");
}
}
public String toString () {
return "SceneRegistry.SceneLoader " + (_model == null ? "" : _model.name) +
"(" + fsceneId + ")";
}
protected SceneModel _model;
protected UpdateList _updates;
protected Exception _cause;
});
}
} }
// from interface SceneService // from interface SceneService