Files
narya/src/java/com/threerings/crowd/data/PlaceObject.dobj
T
Michael Bayne e85e6ad617 Catch our funny choking getOccupantInfo and log the failure prior to
allowing things to get out of hand. Since getOccupantInfo may normally
return null, doing so in our strange failure case will not cause further
freakout.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2697 542714f4-19e9-0310-aa3c-eee0fc999fb1
2003-07-11 00:47:33 +00:00

87 lines
2.7 KiB
Plaintext

//
// $Id: PlaceObject.dobj,v 1.16 2003/07/11 00:47:33 mdb Exp $
package com.threerings.crowd.data;
import java.util.Iterator;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DSet;
import com.threerings.presents.dobj.OidList;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.data.SpeakMarshaller;
import com.threerings.crowd.chat.data.SpeakObject;
/**
* A distributed object that contains information on a place that is
* occupied by bodies. This place might be a chat room, a game room, an
* island in a massively multiplayer piratical universe, anything that has
* occupants that might want to chat with one another.
*/
public class PlaceObject extends DObject
implements SpeakObject
{
/**
* Tracks the oid of the body objects of all of the occupants of this
* place.
*/
public OidList occupants = new OidList();
/**
* Contains an info record (of type {@link OccupantInfo}) for each
* occupant that contains information about that occupant that needs
* to be known by everyone in the place. <em>Note:</em> Don't obtain
* occupant info records directly from this set when on the server,
* use <code>PlaceManager.getOccupantInfo()</code> instead (along with
* <code>PlaceManager.updateOccupantInfo()</code>) because it does
* some special processing to ensure that readers and updaters don't
* step on one another even if they make rapid fire changes to a
* user's occupant info.
*/
public DSet occupantInfo = new DSet();
/** Used to generate speak requests on this place object. */
public SpeakMarshaller speakService;
/**
* Used to indicate whether broadcast chat messages should be dispatched
* on this place object.
*/
public boolean shouldBroadcast ()
{
return true;
}
/**
* Looks up a user's occupant info by name.
*
* @return the occupant info record for the named user or null if no
* user in the room has that username.
*/
public OccupantInfo getOccupantInfo (String username)
{
try {
Iterator iter = occupantInfo.entries();
while (iter.hasNext()) {
OccupantInfo info = (OccupantInfo)iter.next();
if (info.username.equals(username)) {
return info;
}
}
} catch (Throwable t) {
Log.warning("PlaceObject.getOccupantInfo choked.");
Log.logStackTrace(t);
}
return null;
}
// documentation inherited
public void applyToListeners (ListenerOp op)
{
for (int ii = 0, ll = occupants.size(); ii < ll; ii++) {
op.apply(occupants.get(ii));
}
}
}