diff --git a/src/java/com/threerings/whirled/server/AbstractSceneMoveHandler.java b/src/java/com/threerings/whirled/server/AbstractSceneMoveHandler.java index 137df85e..51841023 100644 --- a/src/java/com/threerings/whirled/server/AbstractSceneMoveHandler.java +++ b/src/java/com/threerings/whirled/server/AbstractSceneMoveHandler.java @@ -26,6 +26,7 @@ import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.server.InvocationException; import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.server.LocationManager; import com.threerings.whirled.client.SceneService; import com.threerings.whirled.data.SceneCodes; @@ -40,8 +41,10 @@ import static com.threerings.whirled.Log.log; public abstract class AbstractSceneMoveHandler implements SceneRegistry.ResolutionListener { - public AbstractSceneMoveHandler (BodyObject body, InvocationService.InvocationListener listener) + public AbstractSceneMoveHandler (LocationManager locman, BodyObject body, + InvocationService.InvocationListener listener) { + _locman = locman; _body = body; _listener = listener; } @@ -80,6 +83,7 @@ public abstract class AbstractSceneMoveHandler protected abstract void effectSceneMove (SceneManager scmgr) throws InvocationException; + protected LocationManager _locman; protected BodyObject _body; protected InvocationService.InvocationListener _listener; } diff --git a/src/java/com/threerings/whirled/server/SceneManager.java b/src/java/com/threerings/whirled/server/SceneManager.java index 1789704e..f60ee3cc 100644 --- a/src/java/com/threerings/whirled/server/SceneManager.java +++ b/src/java/com/threerings/whirled/server/SceneManager.java @@ -21,11 +21,14 @@ package com.threerings.whirled.server; +import com.google.inject.Inject; + import com.samskivert.jdbc.WriteOnlyUnit; import com.samskivert.util.Invoker; +import com.threerings.presents.annotation.MainInvoker; + import com.threerings.crowd.data.Place; -import com.threerings.crowd.server.CrowdServer; import com.threerings.crowd.server.PlaceManager; import com.threerings.whirled.data.Scene; @@ -118,7 +121,7 @@ public class SceneManager extends PlaceManager // Wait until us and all of our subclasses have completely finished running didStartup // prior to registering the scene as being ready. - CrowdServer.omgr.postRunnable(new Runnable() { + _omgr.postRunnable(new Runnable() { public void run () { _screg.sceneManagerDidStart(SceneManager.this); } @@ -157,7 +160,7 @@ public class SceneManager extends PlaceManager // and apply and store it in the repository if (isPersistent()) { - WhirledServer.invoker.postUnit(new WriteOnlyUnit("recordUpdate(" + update + ")") { + _invoker.postUnit(new WriteOnlyUnit("recordUpdate(" + update + ")") { public void invokePersist () throws Exception { _screg.getSceneRepository().applyAndRecordUpdate(_scene.getSceneModel(), update); } @@ -193,4 +196,7 @@ public class SceneManager extends PlaceManager /** A reference to the scene registry so that we can call back to it when we're fully * initialized. */ protected SceneRegistry _screg; + + /** The invoker on which we'll do our database operations. */ + @Inject protected @MainInvoker Invoker _invoker; } diff --git a/src/java/com/threerings/whirled/server/SceneMoveHandler.java b/src/java/com/threerings/whirled/server/SceneMoveHandler.java index 07902be2..2fc34f15 100644 --- a/src/java/com/threerings/whirled/server/SceneMoveHandler.java +++ b/src/java/com/threerings/whirled/server/SceneMoveHandler.java @@ -26,7 +26,7 @@ import com.threerings.presents.server.InvocationException; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceConfig; -import com.threerings.crowd.server.CrowdServer; +import com.threerings.crowd.server.LocationManager; import com.threerings.whirled.client.SceneService; import com.threerings.whirled.data.SceneCodes; @@ -38,9 +38,10 @@ import com.threerings.whirled.data.SceneUpdate; */ public class SceneMoveHandler extends AbstractSceneMoveHandler { - public SceneMoveHandler (BodyObject body, int sceneVer, SceneService.SceneMoveListener listener) + public SceneMoveHandler (LocationManager locman, BodyObject body, int sceneVer, + SceneService.SceneMoveListener listener) { - super(body, listener); + super(locman, body, listener); _version = sceneVer; } @@ -50,7 +51,7 @@ public class SceneMoveHandler extends AbstractSceneMoveHandler { // move to location associated with this scene int ploid = scmgr.getPlaceObject().getOid(); - PlaceConfig config = CrowdServer.locman.moveTo(_body, ploid); + PlaceConfig config = _locman.moveTo(_body, ploid); // check to see if they need a newer version of the scene data SceneService.SceneMoveListener listener = (SceneService.SceneMoveListener)_listener; diff --git a/src/java/com/threerings/whirled/server/SceneRegistry.java b/src/java/com/threerings/whirled/server/SceneRegistry.java index 85755c9b..99341451 100644 --- a/src/java/com/threerings/whirled/server/SceneRegistry.java +++ b/src/java/com/threerings/whirled/server/SceneRegistry.java @@ -21,11 +21,18 @@ package com.threerings.whirled.server; -import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.Lists; +import com.google.inject.Inject; +import com.google.inject.Singleton; import com.samskivert.jdbc.RepositoryUnit; -import com.samskivert.util.HashIntMap; +import com.samskivert.util.IntMaps; +import com.samskivert.util.IntMap; +import com.samskivert.util.Invoker; +import com.threerings.presents.annotation.MainInvoker; import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.server.InvocationException; @@ -33,7 +40,7 @@ import com.threerings.presents.server.InvocationManager; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceConfig; -import com.threerings.crowd.server.CrowdServer; +import com.threerings.crowd.server.LocationManager; import com.threerings.crowd.server.PlaceManager; import com.threerings.crowd.server.PlaceRegistry; @@ -61,6 +68,7 @@ import static com.threerings.whirled.Log.log; * *
Note: All access to the scene registry should take place from the dobjmgr thread.
*/
+@Singleton
public class SceneRegistry
implements SceneCodes, SceneProvider
{
@@ -97,16 +105,10 @@ public class SceneRegistry
}
/**
- * Constructs a scene registry, instructing it to load and store scenes using the supplied
- * scene repository.
+ * Constructs a scene registry.
*/
- public SceneRegistry (InvocationManager invmgr, SceneRepository screp,
- SceneFactory scfact, ConfigFactory confact)
+ @Inject public SceneRegistry (InvocationManager invmgr)
{
- _screp = screp;
- _scfact = scfact;
- _confact = confact;
-
// register our scene service
invmgr.registerDispatcher(new SceneDispatcher(this), SceneCodes.WHIRLED_GROUP);
}
@@ -166,7 +168,7 @@ public class SceneRegistry
// otherwise we have to load the scene from the repository
final int fsceneId = sceneId;
- WhirledServer.invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") {
+ _invoker.postUnit(new RepositoryUnit("resolveScene(" + sceneId + ")") {
public void invokePersist () throws Exception {
_model = _screp.loadSceneModel(fsceneId);
_updates = _screp.loadUpdates(fsceneId);
@@ -187,7 +189,7 @@ public class SceneRegistry
SceneService.SceneMoveListener listener)
{
BodyObject body = (BodyObject)caller;
- resolveScene(sceneId, new SceneMoveHandler(body, sceneVer, listener));
+ resolveScene(sceneId, new SceneMoveHandler(_locman, body, sceneVer, listener));
}
/**
@@ -197,7 +199,7 @@ public class SceneRegistry
public void moveBody (BodyObject source, int sceneId)
{
// first remove them from their old place
- CrowdServer.locman.leaveOccupiedPlace(source);
+ _locman.leaveOccupiedPlace(source);
// then send a forced move notification
SceneSender.forcedMove(source, sceneId);
@@ -210,7 +212,7 @@ public class SceneRegistry
public void leaveOccupiedScene (BodyObject source)
{
// remove them from their occupied place (clears out scene info as well)
- CrowdServer.locman.leaveOccupiedPlace(source);
+ _locman.leaveOccupiedPlace(source);
}
/**
@@ -220,11 +222,11 @@ public class SceneRegistry
*/
protected boolean addResolutionListener (int sceneId, ResolutionListener rl)
{
- ArrayList> _penders = IntMaps.newHashIntMap();
}
diff --git a/src/java/com/threerings/whirled/server/WhirledServer.java b/src/java/com/threerings/whirled/server/WhirledServer.java
index 89ea184f..6001d302 100644
--- a/src/java/com/threerings/whirled/server/WhirledServer.java
+++ b/src/java/com/threerings/whirled/server/WhirledServer.java
@@ -21,6 +21,7 @@
package com.threerings.whirled.server;
+import com.google.inject.Inject;
import com.google.inject.Injector;
import com.threerings.util.Name;
@@ -52,9 +53,6 @@ public abstract class WhirledServer extends CrowdServer
}
}
- /** The scene registry. */
- public static SceneRegistry screg;
-
@Override // from CrowdServer
public void init (Injector injector)
throws Exception
@@ -62,7 +60,7 @@ public abstract class WhirledServer extends CrowdServer
super.init(injector);
// configure the client to use our whirled client
- clmgr.setClientFactory(new ClientFactory() {
+ _clmgr.setClientFactory(new ClientFactory() {
public Class extends PresentsClient> getClientClass (AuthRequest areq) {
return WhirledClient.class;
}
@@ -70,14 +68,5 @@ public abstract class WhirledServer extends CrowdServer
return ClientResolver.class;
}
});
-
- // create our scene registry
- screg = createSceneRegistry();
}
-
- /**
- * Creates the scene registry to be used on this server.
- */
- protected abstract SceneRegistry createSceneRegistry ()
- throws Exception;
}