RatingManagerDelegate -> RatingDelegate (we're not a delegate of a
RatingManager, we're a GameManagerDelegate that handles ratings); inject our dependencies. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@672 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
+12
-25
@@ -26,7 +26,9 @@ import static com.threerings.parlor.Log.log;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import com.samskivert.jdbc.RepositoryUnit;
|
import com.samskivert.jdbc.RepositoryUnit;
|
||||||
|
|
||||||
@@ -38,6 +40,8 @@ import com.samskivert.util.StringUtil;
|
|||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
import com.threerings.media.util.MathUtil;
|
import com.threerings.media.util.MathUtil;
|
||||||
|
|
||||||
|
import com.threerings.presents.annotation.MainInvoker;
|
||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
import com.threerings.crowd.data.PlaceConfig;
|
import com.threerings.crowd.data.PlaceConfig;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
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.
|
* Rates players after each game and handles persisting the results.
|
||||||
*/
|
*/
|
||||||
public abstract class RatingManagerDelegate extends GameManagerDelegate
|
public abstract class RatingDelegate extends GameManagerDelegate
|
||||||
implements RatingCodes
|
implements RatingCodes
|
||||||
{
|
{
|
||||||
public RatingManagerDelegate (Invoker invoker)
|
|
||||||
{
|
|
||||||
_invoker = invoker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void didInit (PlaceConfig config)
|
public void didInit (PlaceConfig config)
|
||||||
{
|
{
|
||||||
super.didInit(config);
|
super.didInit(config);
|
||||||
_gmgr = (GameManager)_plmgr;
|
_gmgr = (GameManager)_plmgr;
|
||||||
_repo = getRatingRepository();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -219,8 +217,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
|
|
||||||
final int gameId = getGameId();
|
final int gameId = getGameId();
|
||||||
_invoker.postUnit(new RepositoryUnit("loadRatings(" + gameId + ")") {
|
_invoker.postUnit(new RepositoryUnit("loadRatings(" + gameId + ")") {
|
||||||
@Override
|
@Override public void invokePersist () throws Exception {
|
||||||
public void invokePersist () throws Exception {
|
|
||||||
// map the records by player id so that we can correlate with the db results
|
// map the records by player id so that we can correlate with the db results
|
||||||
IntMap<Rating> map = IntMaps.newHashIntMap();
|
IntMap<Rating> map = IntMaps.newHashIntMap();
|
||||||
for (Rating rating : ratings) {
|
for (Rating rating : ratings) {
|
||||||
@@ -238,8 +235,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void handleSuccess () {
|
||||||
public void handleSuccess () {
|
|
||||||
// stuff our populated records into the _ratings mapping
|
// stuff our populated records into the _ratings mapping
|
||||||
for (Rating rating : ratings) {
|
for (Rating rating : ratings) {
|
||||||
_ratings.put(rating.playerId, rating);
|
_ratings.put(rating.playerId, rating);
|
||||||
@@ -256,15 +252,13 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
|
|
||||||
final int gameId = getGameId();
|
final int gameId = getGameId();
|
||||||
_invoker.postUnit(new RepositoryUnit("saveRatings(" + gameId + ")") {
|
_invoker.postUnit(new RepositoryUnit("saveRatings(" + gameId + ")") {
|
||||||
@Override
|
@Override public void invokePersist () throws Exception {
|
||||||
public void invokePersist () throws Exception {
|
|
||||||
for (Rating rating : ratings) {
|
for (Rating rating : ratings) {
|
||||||
_repo.setRating(gameId, rating.playerId, rating.rating, rating.experience);
|
_repo.setRating(gameId, rating.playerId, rating.rating, rating.experience);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void handleSuccess () {
|
||||||
public void handleSuccess () {
|
|
||||||
// let subclasses publish the new ratings if they so desire
|
// let subclasses publish the new ratings if they so desire
|
||||||
for (Rating rating : ratings) {
|
for (Rating rating : ratings) {
|
||||||
updateRatingInMemory(gameId, rating);
|
updateRatingInMemory(gameId, rating);
|
||||||
@@ -397,11 +391,6 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
|
|||||||
*/
|
*/
|
||||||
protected abstract int minimumRatedDuration ();
|
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.
|
* 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. */
|
/** An appropriately casted reference to our GameObject. */
|
||||||
protected GameObject _gobj;
|
protected GameObject _gobj;
|
||||||
|
|
||||||
/** The RatingRepository that holds our data. */
|
|
||||||
protected RatingRepository _repo;
|
|
||||||
|
|
||||||
/** Contains the persistent id of the players in this game. */
|
/** Contains the persistent id of the players in this game. */
|
||||||
protected int[] _playerIds;
|
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. */
|
/** A timestamp set at the beginning of the game, used to calculate its duration. */
|
||||||
protected int _startStamp;
|
protected int _startStamp;
|
||||||
|
|
||||||
/** The invoker on which we'll perform our database activity. */
|
// our dependencies
|
||||||
protected Invoker _invoker;
|
@Inject protected RatingRepository _repo;
|
||||||
|
@Inject protected @MainInvoker Invoker _invoker;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user