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"
source="1.5" target="1.5">
<classpath refid="classpath"/>
<!--<compilerarg value="-Xlint:unchecked"/>-->
<compilerarg value="-Xlint:unchecked"/>
</javac>
</target>
@@ -504,7 +504,7 @@ public class ChatDirector extends BasicDirector
* of success or failure.
*/
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
final String message = filter(msg, target, true);
@@ -1263,13 +1263,14 @@ public class ChatDirector extends BasicDirector
history[0] = histEntry;
// request to send this text as a tell message
requestTell(target, escapeMessage(message), new ResultListener() {
public void requestCompleted (Object result) {
requestTell(target, escapeMessage(message),
new ResultListener<Name>() {
public void requestCompleted (Name target) {
// replace the full one in the history with just:
// /tell "<handle>"
String newEntry = "/" + command + " " +
(useQuotes ? ("\"" + result + "\"")
: String.valueOf(result)) + " ";
(useQuotes ? ("\"" + target + "\"")
: String.valueOf(target)) + " ";
_history.remove(newEntry);
int dex = _history.lastIndexOf("/" + histEntry);
if (dex >= 0) {
@@ -150,7 +150,7 @@ public class MuteDirector extends BasicDirector
*/
public Name[] getMuted ()
{
return (Name[]) _mutelist.toArray(new Name[_mutelist.size()]);
return _mutelist.toArray(new Name[_mutelist.size()]);
}
// documentation inherited from interface ChatFilter
@@ -175,9 +175,9 @@ public class MuteDirector extends BasicDirector
*/
protected void notifyObservers (final Name username, final boolean muted)
{
_observers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
((MuteObserver)observer).muteChanged(username, muted);
_observers.apply(new ObserverList.ObserverOp<MuteObserver>() {
public boolean apply (MuteObserver observer) {
observer.muteChanged(username, muted);
return true;
}
});
@@ -187,9 +187,9 @@ public class MuteDirector extends BasicDirector
protected ChatDirector _chatdir;
/** The mutelist. */
protected HashSet _mutelist = new HashSet();
protected HashSet<Name> _mutelist = new HashSet<Name>();
/** List of mutelist observers. */
protected ObserverList _observers =
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
protected ObserverList<MuteObserver> _observers =
new ObserverList<MuteObserver>(ObserverList.FAST_UNSAFE_NOTIFY);
}
@@ -47,7 +47,7 @@ import com.threerings.crowd.util.CrowdContext;
* before actually issuing the request.
*/
public class LocationDirector extends BasicDirector
implements LocationCodes, Subscriber, LocationReceiver,
implements LocationCodes, Subscriber<PlaceObject>, LocationReceiver,
LocationService.MoveListener
{
/**
@@ -217,13 +217,12 @@ public class LocationDirector extends BasicDirector
* @return true if everyone is happy with the move, false if it was
* 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];
_observers.apply(new ObserverOp() {
public boolean apply (Object obs) {
LocationObserver lobs = (LocationObserver)obs;
vetoed[0] = (vetoed[0] || !lobs.locationMayChange(placeId));
_observers.apply(new ObserverOp<LocationObserver>() {
public boolean apply (LocationObserver obs) {
vetoed[0] = (vetoed[0] || !obs.locationMayChange(placeId));
return true;
}
});
@@ -380,10 +379,10 @@ public class LocationDirector extends BasicDirector
super.clientDidLogon(client);
// subscribe to our body object
Subscriber sub = new Subscriber() {
public void objectAvailable (DObject object)
Subscriber<BodyObject> sub = new Subscriber<BodyObject>() {
public void objectAvailable (BodyObject object)
{
gotBodyObject((BodyObject)object);
gotBodyObject(object);
}
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
* after a successful moveTo request.
*/
public void objectAvailable (DObject object)
public void objectAvailable (PlaceObject object)
{
// yay, we have our new place object
_plobj = (PlaceObject)object;
_plobj = object;
// let the place controller know that we're ready to roll
if (_controller != null) {
@@ -559,9 +558,9 @@ public class LocationDirector extends BasicDirector
protected void notifyFailure (final int placeId, final String reason)
{
_observers.apply(new ObserverOp() {
public boolean apply (Object obs) {
((LocationObserver)obs).locationChangeFailed(placeId, reason);
_observers.apply(new ObserverOp<LocationObserver>() {
public boolean apply (LocationObserver obs) {
obs.locationChangeFailed(placeId, reason);
return true;
}
});
@@ -585,8 +584,8 @@ public class LocationDirector extends BasicDirector
protected LocationService _lservice;
/** Our location observer list. */
protected ObserverList _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
protected ObserverList<LocationObserver> _observers =
new ObserverList<LocationObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The oid of the place we currently occupy. */
protected int _placeId = -1;
@@ -615,12 +614,13 @@ public class LocationDirector extends BasicDirector
/** A listener that wants to know if we succeeded or
* how we failed to move. */
protected ResultListener _moveListener;
protected ResultListener<Object> _moveListener;
/** The operation used to inform observers that the location changed. */
protected ObserverOp _didChangeOp = new ObserverOp() {
public boolean apply (Object obs) {
((LocationObserver)obs).locationDidChange(_plobj);
protected ObserverOp<LocationObserver> _didChangeOp =
new ObserverOp<LocationObserver>() {
public boolean apply (LocationObserver obs) {
obs.locationDidChange(_plobj);
return true;
}
};
@@ -161,9 +161,9 @@ public class OccupantDirector extends BasicDirector
// now let the occupant observers know what's up
final OccupantInfo info = (OccupantInfo)event.getEntry();
_observers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
((OccupantObserver)observer).occupantEntered(info);
_observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (OccupantObserver observer) {
observer.occupantEntered(info);
return true;
}
});
@@ -182,9 +182,9 @@ public class OccupantDirector extends BasicDirector
// now let the occupant observers know what's up
final OccupantInfo info = (OccupantInfo) event.getEntry();
final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry();
_observers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
((OccupantObserver)observer).occupantUpdated(oinfo, info);
_observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (OccupantObserver observer) {
observer.occupantUpdated(oinfo, info);
return true;
}
});
@@ -202,17 +202,17 @@ public class OccupantDirector extends BasicDirector
// let the occupant observers know what's up
final OccupantInfo oinfo = (OccupantInfo) event.getOldEntry();
_observers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
((OccupantObserver)observer).occupantLeft(oinfo);
_observers.apply(new ObserverList.ObserverOp<OccupantObserver>() {
public boolean apply (OccupantObserver observer) {
observer.occupantLeft(oinfo);
return true;
}
});
}
/** The occupant observers to keep abreast of occupant antics. */
protected ObserverList _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
protected ObserverList<OccupantObserver> _observers =
new ObserverList<OccupantObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The user's current location. */
protected PlaceObject _place;
@@ -222,7 +222,7 @@ public abstract class PlaceController extends Controller
protected void addDelegate (PlaceControllerDelegate delegate)
{
if (_delegates == null) {
_delegates = new ArrayList();
_delegates = new ArrayList<PlaceControllerDelegate>();
}
_delegates.add(delegate);
}
@@ -243,7 +243,7 @@ public abstract class PlaceController extends Controller
if (_delegates != null) {
int dcount = _delegates.size();
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
* derive from the specified class.
*/
protected void applyToDelegates (Class dclass, DelegateOp op)
protected void applyToDelegates (Class<?> dclass, DelegateOp op)
{
if (_delegates != null) {
int dcount = _delegates.size();
for (int i = 0; i < dcount; i++) {
PlaceControllerDelegate delegate =
(PlaceControllerDelegate)_delegates.get(i);
PlaceControllerDelegate delegate = _delegates.get(i);
if (dclass.isAssignableFrom(delegate.getClass())) {
op.apply(delegate);
}
@@ -280,5 +279,5 @@ public abstract class PlaceController extends Controller
protected PlaceView _view;
/** 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
* actually propagated through the system.
*/
public void addToOccupantInfo (DSet.Entry elem)
public void addToOccupantInfo (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
* actually propagated through the system.
*/
public void updateOccupantInfo (DSet.Entry elem)
public void updateOccupantInfo (OccupantInfo elem)
{
requestEntryUpdate(OCCUPANT_INFO, occupantInfo, elem);
}
@@ -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>();
}