Use new LifecycleManager, remove need for manual initialization.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@842 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2009-05-27 18:36:27 +00:00
parent 48f501a2ba
commit 1c1d621051
@@ -36,37 +36,39 @@ import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.RootDObjectManager; import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.ShutdownManager; import com.threerings.presents.server.LifecycleManager;
import com.threerings.parlor.tourney.data.TourneyConfig; import com.threerings.parlor.tourney.data.TourneyConfig;
import com.threerings.parlor.tourney.server.persist.TourneyRepository; import com.threerings.parlor.tourney.server.persist.TourneyRepository;
import static com.threerings.parlor.Log.log;
/** /**
* An extensible tournament manager. * An extensible tournament manager.
*/ */
@Singleton @Singleton
public abstract class TourniesManager public abstract class TourniesManager
implements TourniesProvider, ShutdownManager.Shutdowner implements TourniesProvider, LifecycleManager.Component
{ {
/** @Inject public TourniesManager (LifecycleManager lifemgr)
* Initializes the tournies manager and starts its periodic update task. {
*/ lifemgr.addComponent(this);
public void init (Injector injector) }
throws PersistenceException
// from interface LifecycleManager.Component
public void init ()
{ {
loadTourneyConfigs(); loadTourneyConfigs();
_injector = injector;
_interval = new Interval(_omgr) { _interval = new Interval(_omgr) {
@Override @Override public void expired () {
public void expired () {
updateTournies(); updateTournies();
} }
}; };
_interval.schedule(getIntervalDelay(), true); _interval.schedule(getIntervalDelay(), true);
} }
// from interface ShutdownManager.Shutdowner // from interface LifecycleManager.Component
public void shutdown () public void shutdown ()
{ {
_interval.cancel(); _interval.cancel();
@@ -80,11 +82,6 @@ public abstract class TourniesManager
makeTourney(config, listener); makeTourney(config, listener);
} }
protected TourniesManager (ShutdownManager shutmgr)
{
shutmgr.registerShutdowner(this);
}
/** /**
* Called to actually create a tourney once it has been validated and the prize has been * Called to actually create a tourney once it has been validated and the prize has been
* reserved. * reserved.
@@ -113,11 +110,14 @@ public abstract class TourniesManager
* Load all the tournament configuration information stored in the repository. * Load all the tournament configuration information stored in the repository.
*/ */
protected void loadTourneyConfigs () protected void loadTourneyConfigs ()
throws PersistenceException
{ {
ArrayList<TourneyConfig> tournies = _tournrep.loadTournies(); try {
for (TourneyConfig config : tournies) { ArrayList<TourneyConfig> tournies = _tournrep.loadTournies();
makeTourney(config, null); for (TourneyConfig config : tournies) {
makeTourney(config, null);
}
} catch (PersistenceException pe) {
log.warning("Failed to load tourney configurations.", pe);
} }
} }
@@ -139,9 +139,6 @@ public abstract class TourniesManager
*/ */
protected abstract long getIntervalDelay (); protected abstract long getIntervalDelay ();
/** Used to resolve dependencies in the {@link TourneyManager}s that we create. */
protected Injector _injector;
/** The interval which updates loaded tournies. */ /** The interval which updates loaded tournies. */
protected Interval _interval; protected Interval _interval;
@@ -152,6 +149,7 @@ public abstract class TourniesManager
protected Map<Comparable<?>, TourneyManager> _tourneys = Maps.newHashMap(); protected Map<Comparable<?>, TourneyManager> _tourneys = Maps.newHashMap();
// our dependencies // our dependencies
@Inject protected Injector _injector;
@Inject protected RootDObjectManager _omgr; @Inject protected RootDObjectManager _omgr;
@Inject protected TourneyRepository _tournrep; @Inject protected TourneyRepository _tournrep;
} }