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
+1 -1
View File
@@ -108,7 +108,7 @@
debug="on" optimize="{$build.optimize}" deprecation="on" debug="on" optimize="{$build.optimize}" deprecation="on"
source="1.5" target="1.5"> source="1.5" target="1.5">
<classpath refid="classpath"/> <classpath refid="classpath"/>
<!--<compilerarg value="-Xlint:unchecked"/>--> <compilerarg value="-Xlint:unchecked"/>
</javac> </javac>
</target> </target>
@@ -504,7 +504,7 @@ public class ChatDirector extends BasicDirector
* of success or failure. * of success or failure.
*/ */
public void requestTell (final Name target, String msg, public void requestTell (final Name target, String msg,
final ResultListener rl) final ResultListener<Name> rl)
{ {
// make sure they can say what they want to say // make sure they can say what they want to say
final String message = filter(msg, target, true); final String message = filter(msg, target, true);
@@ -1263,13 +1263,14 @@ public class ChatDirector extends BasicDirector
history[0] = histEntry; history[0] = histEntry;
// request to send this text as a tell message // request to send this text as a tell message
requestTell(target, escapeMessage(message), new ResultListener() { requestTell(target, escapeMessage(message),
public void requestCompleted (Object result) { new ResultListener<Name>() {
public void requestCompleted (Name target) {
// replace the full one in the history with just: // replace the full one in the history with just:
// /tell "<handle>" // /tell "<handle>"
String newEntry = "/" + command + " " + String newEntry = "/" + command + " " +
(useQuotes ? ("\"" + result + "\"") (useQuotes ? ("\"" + target + "\"")
: String.valueOf(result)) + " "; : String.valueOf(target)) + " ";
_history.remove(newEntry); _history.remove(newEntry);
int dex = _history.lastIndexOf("/" + histEntry); int dex = _history.lastIndexOf("/" + histEntry);
if (dex >= 0) { if (dex >= 0) {
@@ -150,7 +150,7 @@ public class MuteDirector extends BasicDirector
*/ */
public Name[] getMuted () public Name[] getMuted ()
{ {
return (Name[]) _mutelist.toArray(new Name[_mutelist.size()]); return _mutelist.toArray(new Name[_mutelist.size()]);
} }
// documentation inherited from interface ChatFilter // documentation inherited from interface ChatFilter
@@ -175,9 +175,9 @@ public class MuteDirector extends BasicDirector
*/ */
protected void notifyObservers (final Name username, final boolean muted) protected void notifyObservers (final Name username, final boolean muted)
{ {
_observers.apply(new ObserverList.ObserverOp() { _observers.apply(new ObserverList.ObserverOp<MuteObserver>() {
public boolean apply (Object observer) { public boolean apply (MuteObserver observer) {
((MuteObserver)observer).muteChanged(username, muted); observer.muteChanged(username, muted);
return true; return true;
} }
}); });
@@ -187,9 +187,9 @@ public class MuteDirector extends BasicDirector
protected ChatDirector _chatdir; protected ChatDirector _chatdir;
/** The mutelist. */ /** The mutelist. */
protected HashSet _mutelist = new HashSet(); protected HashSet<Name> _mutelist = new HashSet<Name>();
/** List of mutelist observers. */ /** List of mutelist observers. */
protected ObserverList _observers = protected ObserverList<MuteObserver> _observers =
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); new ObserverList<MuteObserver>(ObserverList.FAST_UNSAFE_NOTIFY);
} }
@@ -47,7 +47,7 @@ import com.threerings.crowd.util.CrowdContext;
* before actually issuing the request. * before actually issuing the request.
*/ */
public class LocationDirector extends BasicDirector public class LocationDirector extends BasicDirector
implements LocationCodes, Subscriber, LocationReceiver, implements LocationCodes, Subscriber<PlaceObject>, LocationReceiver,
LocationService.MoveListener LocationService.MoveListener
{ {
/** /**
@@ -217,13 +217,12 @@ public class LocationDirector extends BasicDirector
* @return true if everyone is happy with the move, false if it was * @return true if everyone is happy with the move, false if it was
* vetoed by one of the location observers. * vetoed by one of the location observers.
*/ */
public boolean mayMoveTo (final int placeId, ResultListener rl) public boolean mayMoveTo (final int placeId, ResultListener<Object> rl)
{ {
final boolean[] vetoed = new boolean[1]; final boolean[] vetoed = new boolean[1];
_observers.apply(new ObserverOp() { _observers.apply(new ObserverOp<LocationObserver>() {
public boolean apply (Object obs) { public boolean apply (LocationObserver obs) {
LocationObserver lobs = (LocationObserver)obs; vetoed[0] = (vetoed[0] || !obs.locationMayChange(placeId));
vetoed[0] = (vetoed[0] || !lobs.locationMayChange(placeId));
return true; return true;
} }
}); });
@@ -380,10 +379,10 @@ public class LocationDirector extends BasicDirector
super.clientDidLogon(client); super.clientDidLogon(client);
// subscribe to our body object // subscribe to our body object
Subscriber sub = new Subscriber() { Subscriber<BodyObject> sub = new Subscriber<BodyObject>() {
public void objectAvailable (DObject object) public void objectAvailable (BodyObject object)
{ {
gotBodyObject((BodyObject)object); gotBodyObject(object);
} }
public void requestFailed (int oid, ObjectAccessException cause) public void requestFailed (int oid, ObjectAccessException cause)
@@ -474,10 +473,10 @@ public class LocationDirector extends BasicDirector
* Called when we receive the place object to which we subscribed * Called when we receive the place object to which we subscribed
* after a successful moveTo request. * after a successful moveTo request.
*/ */
public void objectAvailable (DObject object) public void objectAvailable (PlaceObject object)
{ {
// yay, we have our new place object // yay, we have our new place object
_plobj = (PlaceObject)object; _plobj = object;
// let the place controller know that we're ready to roll // let the place controller know that we're ready to roll
if (_controller != null) { if (_controller != null) {
@@ -559,9 +558,9 @@ public class LocationDirector extends BasicDirector
protected void notifyFailure (final int placeId, final String reason) protected void notifyFailure (final int placeId, final String reason)
{ {
_observers.apply(new ObserverOp() { _observers.apply(new ObserverOp<LocationObserver>() {
public boolean apply (Object obs) { public boolean apply (LocationObserver obs) {
((LocationObserver)obs).locationChangeFailed(placeId, reason); obs.locationChangeFailed(placeId, reason);
return true; return true;
} }
}); });
@@ -585,8 +584,8 @@ public class LocationDirector extends BasicDirector
protected LocationService _lservice; protected LocationService _lservice;
/** Our location observer list. */ /** Our location observer list. */
protected ObserverList _observers = protected ObserverList<LocationObserver> _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); new ObserverList<LocationObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The oid of the place we currently occupy. */ /** The oid of the place we currently occupy. */
protected int _placeId = -1; protected int _placeId = -1;
@@ -615,12 +614,13 @@ public class LocationDirector extends BasicDirector
/** A listener that wants to know if we succeeded or /** A listener that wants to know if we succeeded or
* how we failed to move. */ * how we failed to move. */
protected ResultListener _moveListener; protected ResultListener<Object> _moveListener;
/** The operation used to inform observers that the location changed. */ /** The operation used to inform observers that the location changed. */
protected ObserverOp _didChangeOp = new ObserverOp() { protected ObserverOp<LocationObserver> _didChangeOp =
public boolean apply (Object obs) { new ObserverOp<LocationObserver>() {
((LocationObserver)obs).locationDidChange(_plobj); public boolean apply (LocationObserver obs) {
obs.locationDidChange(_plobj);
return true; return true;
} }
}; };
@@ -161,9 +161,9 @@ public class OccupantDirector extends BasicDirector
// now let the occupant observers know what's up // now let the occupant observers know what's up
final OccupantInfo info = (OccupantInfo)event.getEntry(); final OccupantInfo info = (OccupantInfo)event.getEntry();
_observers.apply(new ObserverList.ObserverOp() { _observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (Object observer) { public boolean apply (OccupantObserver observer) {
((OccupantObserver)observer).occupantEntered(info); observer.occupantEntered(info);
return true; return true;
} }
}); });
@@ -182,9 +182,9 @@ public class OccupantDirector extends BasicDirector
// now let the occupant observers know what's up // now let the occupant observers know what's up
final OccupantInfo info = (OccupantInfo) event.getEntry(); final OccupantInfo info = (OccupantInfo) event.getEntry();
final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry(); final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry();
_observers.apply(new ObserverList.ObserverOp() { _observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (Object observer) { public boolean apply (OccupantObserver observer) {
((OccupantObserver)observer).occupantUpdated(oinfo, info); observer.occupantUpdated(oinfo, info);
return true; return true;
} }
}); });
@@ -202,17 +202,17 @@ public class OccupantDirector extends BasicDirector
// let the occupant observers know what's up // let the occupant observers know what's up
final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry(); final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry();
_observers.apply(new ObserverList.ObserverOp() { _observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (Object observer) { public boolean apply (OccupantObserver observer) {
((OccupantObserver)observer).occupantLeft(oinfo); observer.occupantLeft(oinfo);
return true; return true;
} }
}); });
} }
/** The occupant observers to keep abreast of occupant antics. */ /** The occupant observers to keep abreast of occupant antics. */
protected ObserverList _observers = protected ObserverList<OccupantObserver> _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); new ObserverList<OccupantObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The user's current location. */ /** The user's current location. */
protected PlaceObject _place; protected PlaceObject _place;
@@ -222,7 +222,7 @@ public abstract class PlaceController extends Controller
protected void addDelegate (PlaceControllerDelegate delegate) protected void addDelegate (PlaceControllerDelegate delegate)
{ {
if (_delegates == null) { if (_delegates == null) {
_delegates = new ArrayList(); _delegates = new ArrayList<PlaceControllerDelegate>();
} }
_delegates.add(delegate); _delegates.add(delegate);
} }
@@ -243,7 +243,7 @@ public abstract class PlaceController extends Controller
if (_delegates != null) { if (_delegates != null) {
int dcount = _delegates.size(); int dcount = _delegates.size();
for (int i = 0; i < dcount; i++) { for (int i = 0; i < dcount; i++) {
op.apply((PlaceControllerDelegate)_delegates.get(i)); op.apply(_delegates.get(i));
} }
} }
} }
@@ -252,13 +252,12 @@ public abstract class PlaceController extends Controller
* Applies the supplied operation to the registered delegates that * Applies the supplied operation to the registered delegates that
* derive from the specified class. * derive from the specified class.
*/ */
protected void applyToDelegates (Class dclass, DelegateOp op) protected void applyToDelegates (Class<?> dclass, DelegateOp op)
{ {
if (_delegates != null) { if (_delegates != null) {
int dcount = _delegates.size(); int dcount = _delegates.size();
for (int i = 0; i < dcount; i++) { for (int i = 0; i < dcount; i++) {
PlaceControllerDelegate delegate = PlaceControllerDelegate delegate = _delegates.get(i);
(PlaceControllerDelegate)_delegates.get(i);
if (dclass.isAssignableFrom(delegate.getClass())) { if (dclass.isAssignableFrom(delegate.getClass())) {
op.apply(delegate); op.apply(delegate);
} }
@@ -280,5 +279,5 @@ public abstract class PlaceController extends Controller
protected PlaceView _view; protected PlaceView _view;
/** A list of the delegates in use by this controller. */ /** A list of the delegates in use by this controller. */
protected ArrayList _delegates; protected ArrayList<PlaceControllerDelegate> _delegates;
} }
@@ -141,7 +141,7 @@ public class PlaceObject extends DObject
* <code>occupantInfo</code> set. The set will not change until the event is * <code>occupantInfo</code> set. The set will not change until the event is
* actually propagated through the system. * actually propagated through the system.
*/ */
public void addToOccupantInfo (DSet.Entry elem) public void addToOccupantInfo (OccupantInfo elem)
{ {
requestEntryAdd(OCCUPANT_INFO, occupantInfo, elem); requestEntryAdd(OCCUPANT_INFO, occupantInfo, elem);
} }
@@ -161,7 +161,7 @@ public class PlaceObject extends DObject
* <code>occupantInfo</code> set. The set will not change until the event is * <code>occupantInfo</code> set. The set will not change until the event is
* actually propagated through the system. * actually propagated through the system.
*/ */
public void updateOccupantInfo (DSet.Entry elem) public void updateOccupantInfo (OccupantInfo elem)
{ {
requestEntryUpdate(OCCUPANT_INFO, occupantInfo, elem); requestEntryUpdate(OCCUPANT_INFO, occupantInfo, elem);
} }
@@ -32,7 +32,7 @@ import com.threerings.crowd.data.BodyObject;
public class CrowdClientResolver extends ClientResolver public class CrowdClientResolver extends ClientResolver
{ {
// documentation inherited // documentation inherited
public Class getClientObjectClass () public Class<? extends ClientObject> getClientObjectClass ()
{ {
return BodyObject.class; return BodyObject.class;
} }
@@ -121,7 +121,7 @@ public class PlaceManager
*/ */
public OccupantInfo getOccupantInfo (int bodyOid) public OccupantInfo getOccupantInfo (int bodyOid)
{ {
return (OccupantInfo)_occInfo.get(bodyOid); return _occInfo.get(bodyOid);
} }
/** /**
@@ -173,7 +173,7 @@ public class PlaceManager
* *
* @see PlaceRegistry#createPlace * @see PlaceRegistry#createPlace
*/ */
protected Class getPlaceObjectClass () protected Class<? extends PlaceObject> getPlaceObjectClass ()
{ {
return PlaceObject.class; return PlaceObject.class;
} }
@@ -217,7 +217,7 @@ public class PlaceManager
public void addDelegate (PlaceManagerDelegate delegate) public void addDelegate (PlaceManagerDelegate delegate)
{ {
if (_delegates == null) { if (_delegates == null) {
_delegates = new ArrayList(); _delegates = new ArrayList<PlaceManagerDelegate>();
} }
_delegates.add(delegate); _delegates.add(delegate);
} }
@@ -551,7 +551,7 @@ public class PlaceManager
{ {
// create our handler map if necessary // create our handler map if necessary
if (_msghandlers == null) { if (_msghandlers == null) {
_msghandlers = new HashMap(); _msghandlers = new HashMap<String,MessageHandler>();
} }
_msghandlers.put(name, handler); _msghandlers.put(name, handler);
} }
@@ -565,7 +565,7 @@ public class PlaceManager
{ {
MessageHandler handler = null; MessageHandler handler = null;
if (_msghandlers != null) { if (_msghandlers != null) {
handler = (MessageHandler)_msghandlers.get(event.getName()); handler = _msghandlers.get(event.getName());
} }
if (handler != null) { if (handler != null) {
handler.handleEvent(event, this); handler.handleEvent(event, this);
@@ -682,7 +682,7 @@ public class PlaceManager
if (_delegates != null) { if (_delegates != null) {
int dcount = _delegates.size(); int dcount = _delegates.size();
for (int i = 0; i < dcount; i++) { 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; protected PlaceConfig _config;
/** Message handlers are used to process message events. */ /** 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. */ /** 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. */ /** 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 /** The interval currently registered to shut this place
* down after a certain period of idility, or null if no * down after a certain period of idility, or null if no
@@ -45,7 +45,7 @@ import com.threerings.crowd.data.PlaceObject;
* places. * places.
*/ */
public class PlaceRegistry public class PlaceRegistry
implements Subscriber implements Subscriber<PlaceObject>
{ {
/** /**
* Used to receive a callback when the place object associated with a * 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 // stick the manager on the creation queue because we know
// we'll get our calls to objectAvailable()/requestFailed() in // we'll get our calls to objectAvailable()/requestFailed() in
// the order that we call createObject() // 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 // 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; return pmgr;
} }
@@ -170,7 +173,7 @@ public class PlaceRegistry
*/ */
public PlaceManager getPlaceManager (int placeOid) 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 * should only be accessed on the dobjmgr thread and shouldn't be kept
* around across event dispatches. * around across event dispatches.
*/ */
public Iterator enumeratePlaces () public Iterator<PlaceObject> enumeratePlaces ()
{ {
final Iterator itr = _pmgrs.elements(); final Iterator<PlaceManager> itr = _pmgrs.values().iterator();
return new Iterator() { return new Iterator<PlaceObject>() {
public boolean hasNext () public boolean hasNext ()
{ {
return itr.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(); 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 * This should only be accessed on the dobjmgr thread and shouldn't be
* kept around across event dispatches. * kept around across event dispatches.
*/ */
public Iterator enumeratePlaceManagers () public Iterator<PlaceManager> enumeratePlaceManagers ()
{ {
return _pmgrs.elements(); return _pmgrs.values().iterator();
} }
// documentation inherited // 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 // pop the next place manager off of the queue and let it know
// that everything went swimmingly // that everything went swimmingly
Tuple tuple = (Tuple)_createq.getNonBlocking(); Tuple<PlaceManager,CreationObserver> tuple = _createq.getNonBlocking();
if (tuple == null) { if (tuple == null) {
Log.warning("Place created but no manager queued up to hear " + Log.warning("Place created but no manager queued up to hear " +
"about it!? [pobj=" + object + "]."); "about it!? [pobj=" + plobj + "].");
return; return;
} }
// make sure it's the right kind of object PlaceManager pmgr = tuple.left;
if (!(object instanceof PlaceObject)) { CreationObserver observer = tuple.right;
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;
// stick the manager into our table // stick the manager into our table
_pmgrs.put(plobj.getOid(), pmgr); _pmgrs.put(plobj.getOid(), pmgr);
@@ -240,7 +235,7 @@ public class PlaceRegistry
try { try {
pmgr.startup(plobj); pmgr.startup(plobj);
} catch (Exception e) { } catch (Exception e) {
Log.warning("Error starting place manager [obj=" + object + Log.warning("Error starting place manager [obj=" + plobj +
", pmgr=" + pmgr + "]."); ", pmgr=" + pmgr + "].");
Log.logStackTrace(e); Log.logStackTrace(e);
} }
@@ -252,8 +247,8 @@ public class PlaceRegistry
observer.placeCreated(plobj, pmgr); observer.placeCreated(plobj, pmgr);
} catch (Exception e) { } catch (Exception e) {
Log.warning("Error informing CreationObserver of place " + Log.warning("Error informing CreationObserver of place " +
"[obj=" + object + ", pmgr=" + pmgr + ", obs=" + observer + "[obj=" + plobj + ", pmgr=" + pmgr +
"]."); ", obs=" + observer + "].");
Log.logStackTrace(e); Log.logStackTrace(e);
} }
} }
@@ -264,14 +259,14 @@ public class PlaceRegistry
{ {
// pop a place manager off the queue since it is queued up to // pop a place manager off the queue since it is queued up to
// manage the failed place object // manage the failed place object
PlaceManager pmgr = (PlaceManager)_createq.getNonBlocking(); Tuple<PlaceManager,CreationObserver> tuple = _createq.getNonBlocking();
if (pmgr == null) { if (tuple == null) {
Log.warning("Place creation failed but no manager queued " + Log.warning("Place creation failed but no manager queued " +
"up to hear about it!? [cause=" + cause + "]."); "up to hear about it!? [cause=" + cause + "].");
return; return;
} }
Log.warning("Failed to create place object [mgr=" + pmgr + Log.warning("Failed to create place object [mgr=" + tuple.left +
", cause=" + cause + "]."); ", cause=" + cause + "].");
} }
@@ -300,8 +295,9 @@ public class PlaceRegistry
protected RootDObjectManager _omgr; protected RootDObjectManager _omgr;
/** A queue of place managers waiting for their place objects. */ /** 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. */ /** A mapping from place object id to place manager. */
protected HashIntMap _pmgrs = new HashIntMap(); protected HashIntMap<PlaceManager> _pmgrs = new HashIntMap<PlaceManager>();
} }