Behold, TAPOAFTSM! The Awesome Power Of A Fully Type-Safe Mothership.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4246 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-07-05 00:56:16 +00:00
parent 8afd0316ec
commit bdadd2377e
10 changed files with 91 additions and 94 deletions
@@ -32,7 +32,7 @@ import com.threerings.crowd.data.BodyObject;
public class CrowdClientResolver extends ClientResolver
{
// documentation inherited
public Class getClientObjectClass ()
public Class<? extends ClientObject> getClientObjectClass ()
{
return BodyObject.class;
}
@@ -121,7 +121,7 @@ public class PlaceManager
*/
public OccupantInfo getOccupantInfo (int bodyOid)
{
return (OccupantInfo)_occInfo.get(bodyOid);
return _occInfo.get(bodyOid);
}
/**
@@ -173,7 +173,7 @@ public class PlaceManager
*
* @see PlaceRegistry#createPlace
*/
protected Class getPlaceObjectClass ()
protected Class<? extends PlaceObject> getPlaceObjectClass ()
{
return PlaceObject.class;
}
@@ -217,7 +217,7 @@ public class PlaceManager
public void addDelegate (PlaceManagerDelegate delegate)
{
if (_delegates == null) {
_delegates = new ArrayList();
_delegates = new ArrayList<PlaceManagerDelegate>();
}
_delegates.add(delegate);
}
@@ -551,7 +551,7 @@ public class PlaceManager
{
// create our handler map if necessary
if (_msghandlers == null) {
_msghandlers = new HashMap();
_msghandlers = new HashMap<String,MessageHandler>();
}
_msghandlers.put(name, handler);
}
@@ -565,7 +565,7 @@ public class PlaceManager
{
MessageHandler handler = null;
if (_msghandlers != null) {
handler = (MessageHandler)_msghandlers.get(event.getName());
handler = _msghandlers.get(event.getName());
}
if (handler != null) {
handler.handleEvent(event, this);
@@ -682,7 +682,7 @@ public class PlaceManager
if (_delegates != null) {
int dcount = _delegates.size();
for (int i = 0; i < dcount; i++) {
op.apply((PlaceManagerDelegate)_delegates.get(i));
op.apply(_delegates.get(i));
}
}
}
@@ -704,13 +704,14 @@ public class PlaceManager
protected PlaceConfig _config;
/** Message handlers are used to process message events. */
protected HashMap _msghandlers;
protected HashMap<String,MessageHandler> _msghandlers;
/** A list of the delegates in use by this manager. */
protected ArrayList _delegates;
protected ArrayList<PlaceManagerDelegate> _delegates;
/** Used to keep a canonical copy of the occupant info records. */
protected HashIntMap _occInfo = new HashIntMap();
protected HashIntMap<OccupantInfo> _occInfo =
new HashIntMap<OccupantInfo>();
/** The interval currently registered to shut this place
* down after a certain period of idility, or null if no
@@ -45,7 +45,7 @@ import com.threerings.crowd.data.PlaceObject;
* places.
*/
public class PlaceRegistry
implements Subscriber
implements Subscriber<PlaceObject>
{
/**
* Used to receive a callback when the place object associated with a
@@ -156,10 +156,13 @@ public class PlaceRegistry
// stick the manager on the creation queue because we know
// we'll get our calls to objectAvailable()/requestFailed() in
// the order that we call createObject()
_createq.append(new Tuple(pmgr, observer));
_createq.append(
new Tuple<PlaceManager,CreationObserver>(pmgr, observer));
// and request to create the place object
_omgr.createObject(pmgr.getPlaceObjectClass(), this);
@SuppressWarnings("unchecked") Class<PlaceObject> pclass =
(Class<PlaceObject>)pmgr.getPlaceObjectClass();
_omgr.createObject(pclass, this);
return pmgr;
}
@@ -170,7 +173,7 @@ public class PlaceRegistry
*/
public PlaceManager getPlaceManager (int placeOid)
{
return (PlaceManager)_pmgrs.get(placeOid);
return _pmgrs.get(placeOid);
}
/**
@@ -178,18 +181,18 @@ public class PlaceRegistry
* should only be accessed on the dobjmgr thread and shouldn't be kept
* around across event dispatches.
*/
public Iterator enumeratePlaces ()
public Iterator<PlaceObject> enumeratePlaces ()
{
final Iterator itr = _pmgrs.elements();
return new Iterator() {
final Iterator<PlaceManager> itr = _pmgrs.values().iterator();
return new Iterator<PlaceObject>() {
public boolean hasNext ()
{
return itr.hasNext();
}
public Object next ()
public PlaceObject next ()
{
PlaceManager plmgr = (PlaceManager)itr.next();
PlaceManager plmgr = itr.next();
return (plmgr == null) ? null : plmgr.getPlaceObject();
}
@@ -205,33 +208,25 @@ public class PlaceRegistry
* This should only be accessed on the dobjmgr thread and shouldn't be
* kept around across event dispatches.
*/
public Iterator enumeratePlaceManagers ()
public Iterator<PlaceManager> enumeratePlaceManagers ()
{
return _pmgrs.elements();
return _pmgrs.values().iterator();
}
// documentation inherited
public void objectAvailable (DObject object)
public void objectAvailable (PlaceObject plobj)
{
// pop the next place manager off of the queue and let it know
// that everything went swimmingly
Tuple tuple = (Tuple)_createq.getNonBlocking();
Tuple<PlaceManager,CreationObserver> tuple = _createq.getNonBlocking();
if (tuple == null) {
Log.warning("Place created but no manager queued up to hear " +
"about it!? [pobj=" + object + "].");
"about it!? [pobj=" + plobj + "].");
return;
}
// make sure it's the right kind of object
if (!(object instanceof PlaceObject)) {
Log.warning("Place registry notified of the creation of " +
"non-place object!? [obj=" + object + "].");
return;
}
PlaceManager pmgr = (PlaceManager)tuple.left;
CreationObserver observer = (CreationObserver)tuple.right;
PlaceObject plobj = (PlaceObject)object;
PlaceManager pmgr = tuple.left;
CreationObserver observer = tuple.right;
// stick the manager into our table
_pmgrs.put(plobj.getOid(), pmgr);
@@ -240,7 +235,7 @@ public class PlaceRegistry
try {
pmgr.startup(plobj);
} catch (Exception e) {
Log.warning("Error starting place manager [obj=" + object +
Log.warning("Error starting place manager [obj=" + plobj +
", pmgr=" + pmgr + "].");
Log.logStackTrace(e);
}
@@ -252,8 +247,8 @@ public class PlaceRegistry
observer.placeCreated(plobj, pmgr);
} catch (Exception e) {
Log.warning("Error informing CreationObserver of place " +
"[obj=" + object + ", pmgr=" + pmgr + ", obs=" + observer +
"].");
"[obj=" + plobj + ", pmgr=" + pmgr +
", obs=" + observer + "].");
Log.logStackTrace(e);
}
}
@@ -264,14 +259,14 @@ public class PlaceRegistry
{
// pop a place manager off the queue since it is queued up to
// manage the failed place object
PlaceManager pmgr = (PlaceManager)_createq.getNonBlocking();
if (pmgr == null) {
Tuple<PlaceManager,CreationObserver> tuple = _createq.getNonBlocking();
if (tuple == null) {
Log.warning("Place creation failed but no manager queued " +
"up to hear about it!? [cause=" + cause + "].");
return;
}
Log.warning("Failed to create place object [mgr=" + pmgr +
Log.warning("Failed to create place object [mgr=" + tuple.left +
", cause=" + cause + "].");
}
@@ -300,8 +295,9 @@ public class PlaceRegistry
protected RootDObjectManager _omgr;
/** A queue of place managers waiting for their place objects. */
protected Queue _createq = new Queue();
protected Queue<Tuple<PlaceManager,CreationObserver>> _createq =
new Queue<Tuple<PlaceManager,CreationObserver>>();
/** A mapping from place object id to place manager. */
protected HashIntMap _pmgrs = new HashIntMap();
protected HashIntMap<PlaceManager> _pmgrs = new HashIntMap<PlaceManager>();
}