diff --git a/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java b/src/java/com/threerings/parlor/rating/server/RatingDelegate.java similarity index 94% rename from src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java rename to src/java/com/threerings/parlor/rating/server/RatingDelegate.java index 5d1ccfb2..b1062bae 100644 --- a/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java +++ b/src/java/com/threerings/parlor/rating/server/RatingDelegate.java @@ -26,7 +26,9 @@ import static com.threerings.parlor.Log.log; import java.util.Collection; import java.util.Collections; import java.util.List; + import com.google.common.collect.Lists; +import com.google.inject.Inject; import com.samskivert.jdbc.RepositoryUnit; @@ -38,6 +40,8 @@ import com.samskivert.util.StringUtil; import com.threerings.util.Name; import com.threerings.media.util.MathUtil; +import com.threerings.presents.annotation.MainInvoker; + import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceObject; @@ -54,20 +58,14 @@ import com.threerings.parlor.rating.server.persist.RatingRepository; /** * Rates players after each game and handles persisting the results. */ -public abstract class RatingManagerDelegate extends GameManagerDelegate +public abstract class RatingDelegate extends GameManagerDelegate implements RatingCodes { - public RatingManagerDelegate (Invoker invoker) - { - _invoker = invoker; - } - @Override public void didInit (PlaceConfig config) { super.didInit(config); _gmgr = (GameManager)_plmgr; - _repo = getRatingRepository(); } @Override @@ -117,7 +115,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate } // note the time at which we started - _startStamp = (int) (System.currentTimeMillis() / 1000); + _startStamp = (int)(System.currentTimeMillis() / 1000); // this contains the persistent player id for each position in a seated table game _playerIds = new int[_gmgr.getPlayerSlots()]; @@ -219,8 +217,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate final int gameId = getGameId(); _invoker.postUnit(new RepositoryUnit("loadRatings(" + gameId + ")") { - @Override - public void invokePersist () throws Exception { + @Override public void invokePersist () throws Exception { // map the records by player id so that we can correlate with the db results IntMap map = IntMaps.newHashIntMap(); for (Rating rating : ratings) { @@ -238,8 +235,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate } } - @Override - public void handleSuccess () { + @Override public void handleSuccess () { // stuff our populated records into the _ratings mapping for (Rating rating : ratings) { _ratings.put(rating.playerId, rating); @@ -256,15 +252,13 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate final int gameId = getGameId(); _invoker.postUnit(new RepositoryUnit("saveRatings(" + gameId + ")") { - @Override - public void invokePersist () throws Exception { + @Override public void invokePersist () throws Exception { for (Rating rating : ratings) { _repo.setRating(gameId, rating.playerId, rating.rating, rating.experience); } } - @Override - public void handleSuccess () { + @Override public void handleSuccess () { // let subclasses publish the new ratings if they so desire for (Rating rating : ratings) { updateRatingInMemory(gameId, rating); @@ -397,11 +391,6 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate */ protected abstract int minimumRatedDuration (); - /** - * Return a reference to the {@link RatingRepository} instance we should use to persist. - */ - protected abstract RatingRepository getRatingRepository (); - /** * Optionally store update ratings in memory e.g. in the user object. * @@ -472,9 +461,6 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate /** An appropriately casted reference to our GameObject. */ protected GameObject _gobj; - /** The RatingRepository that holds our data. */ - protected RatingRepository _repo; - /** Contains the persistent id of the players in this game. */ protected int[] _playerIds; @@ -484,6 +470,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate /** A timestamp set at the beginning of the game, used to calculate its duration. */ protected int _startStamp; - /** The invoker on which we'll perform our database activity. */ - protected Invoker _invoker; + // our dependencies + @Inject protected RatingRepository _repo; + @Inject protected @MainInvoker Invoker _invoker; }