Chipping away at proper type safety for all of the Narya code.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4232 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-06-27 17:46:36 +00:00
parent 54db9d7d4e
commit 0a5953bf17
6 changed files with 46 additions and 46 deletions
@@ -295,9 +295,9 @@ public class SpeakProvider
* Returns a list of {@link ChatMessage} objects to which this user * Returns a list of {@link ChatMessage} objects to which this user
* has been privy in the recent past. * has been privy in the recent past.
*/ */
public static ArrayList getChatHistory (Name username) public static ArrayList<ChatMessage> getChatHistory (Name username)
{ {
ArrayList history = getHistoryList(username); ArrayList<ChatMessage> history = getHistoryList(username);
pruneHistory(System.currentTimeMillis(), history); pruneHistory(System.currentTimeMillis(), history);
return history; return history;
} }
@@ -323,7 +323,7 @@ public class SpeakProvider
} }
// add the message to this user's chat history // add the message to this user's chat history
ArrayList history = getHistoryList(username); ArrayList<ChatMessage> history = getHistoryList(username);
history.add(msg); history.add(msg);
// if the history is big enough, potentially prune it (we always // if the history is big enough, potentially prune it (we always
@@ -342,11 +342,11 @@ public class SpeakProvider
/** /**
* Returns this user's chat history, creating one if necessary. * Returns this user's chat history, creating one if necessary.
*/ */
protected static ArrayList getHistoryList (Name username) protected static ArrayList<ChatMessage> getHistoryList (Name username)
{ {
ArrayList history = (ArrayList)_histories.get(username); ArrayList<ChatMessage> history = _histories.get(username);
if (history == null) { if (history == null) {
_histories.put(username, history = new ArrayList()); _histories.put(username, history = new ArrayList<ChatMessage>());
} }
return history; return history;
} }
@@ -354,11 +354,12 @@ public class SpeakProvider
/** /**
* Prunes all messages from this history which are expired. * Prunes all messages from this history which are expired.
*/ */
protected static void pruneHistory (long now, ArrayList history) protected static void pruneHistory (
long now, ArrayList<ChatMessage> history)
{ {
int prunepos = 0; int prunepos = 0;
for (int ll = history.size(); prunepos < ll; prunepos++) { for (int ll = history.size(); prunepos < ll; prunepos++) {
ChatMessage msg = (ChatMessage)history.get(prunepos); ChatMessage msg = history.get(prunepos);
if (now - msg.timestamp < HISTORY_EXPIRATION) { if (now - msg.timestamp < HISTORY_EXPIRATION) {
break; // stop when we get to the first valid message break; // stop when we get to the first valid message
} }
@@ -384,15 +385,16 @@ public class SpeakProvider
} }
/** Used to notify our {@link MessageObserver}s. */ /** Used to notify our {@link MessageObserver}s. */
protected static class MessageObserverOp implements ObserverList.ObserverOp protected static class MessageObserverOp
implements ObserverList.ObserverOp<MessageObserver>
{ {
public void init (Name hearer, UserMessage message) { public void init (Name hearer, UserMessage message) {
_hearer = hearer; _hearer = hearer;
_message = message; _message = message;
} }
public boolean apply (Object observer) { public boolean apply (MessageObserver observer) {
((MessageObserver)observer).messageDelivered(_hearer, _message); observer.messageDelivered(_hearer, _message);
return true; return true;
} }
@@ -407,14 +409,15 @@ public class SpeakProvider
protected SpeakerValidator _validator; protected SpeakerValidator _validator;
/** Recent chat history for the server. */ /** Recent chat history for the server. */
protected static HashMap _histories = new HashMap(); protected static HashMap<Name,ArrayList<ChatMessage>> _histories =
new HashMap<Name,ArrayList<ChatMessage>>();
/** Used to note the recipients of a chat message. */ /** Used to note the recipients of a chat message. */
protected static MessageMapper _messageMapper = new MessageMapper(); protected static MessageMapper _messageMapper = new MessageMapper();
/** A list of {@link MessageObserver}s. */ /** A list of {@link MessageObserver}s. */
protected static ObserverList _messageObs = new ObserverList( protected static ObserverList<MessageObserver> _messageObs =
ObserverList.FAST_UNSAFE_NOTIFY); new ObserverList<MessageObserver>(ObserverList.FAST_UNSAFE_NOTIFY);
/** Used to notify our {@link MessageObserver}s. */ /** Used to notify our {@link MessageObserver}s. */
protected static MessageObserverOp _messageOp = new MessageObserverOp(); protected static MessageObserverOp _messageOp = new MessageObserverOp();
@@ -649,7 +649,7 @@ public class Client
* Used to notify client observers of events. * Used to notify client observers of events.
*/ */
protected class Notifier protected class Notifier
implements ObserverList.ObserverOp implements ObserverList.ObserverOp<SessionObserver>
{ {
public Notifier (int code, Exception cause) public Notifier (int code, Exception cause)
{ {
@@ -663,9 +663,8 @@ public class Client
return _rejected; return _rejected;
} }
public boolean apply (Object observer) public boolean apply (SessionObserver obs)
{ {
SessionObserver obs = (SessionObserver)observer;
switch (_code) { switch (_code) {
case CLIENT_DID_LOGON: case CLIENT_DID_LOGON:
obs.clientDidLogon(Client.this); obs.clientDidLogon(Client.this);
@@ -748,8 +747,8 @@ public class Client
protected int[] _ports; protected int[] _ports;
/** Our list of client observers. */ /** Our list of client observers. */
protected ObserverList _observers = protected ObserverList<SessionObserver> _observers =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); new ObserverList<SessionObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The entity that manages our network communications. */ /** The entity that manages our network communications. */
protected Communicator _comm; protected Communicator _comm;
@@ -29,7 +29,7 @@ package com.threerings.presents.dobj;
* *
* @see DObject#addListener * @see DObject#addListener
*/ */
public interface ProxySubscriber extends Subscriber public interface ProxySubscriber extends Subscriber<DObject>
{ {
/** /**
* Called when any event has been dispatched on an object. * Called when any event has been dispatched on an object.
@@ -40,7 +40,7 @@ import com.threerings.presents.dobj.Subscriber;
* appropriately. * appropriately.
*/ */
public class ClientResolver extends Invoker.Unit public class ClientResolver extends Invoker.Unit
implements Subscriber implements Subscriber<ClientObject>
{ {
/** /**
* Initiailizes this instance. * Initiailizes this instance.
@@ -70,11 +70,11 @@ public class ClientResolver extends Invoker.Unit
} }
// documentation inherited // documentation inherited
public void objectAvailable (DObject object) public void objectAvailable (ClientObject object)
{ {
// we've got our object, so shunt ourselves over to the invoker // we've got our object, so shunt ourselves over to the invoker
// thread to perform database loading // thread to perform database loading
_clobj = (ClientObject)object; _clobj = object;
PresentsServer.invoker.postUnit(this); PresentsServer.invoker.postUnit(this);
// we no longer need to be a subscriber of the object now that it // we no longer need to be a subscriber of the object now that it
@@ -121,10 +121,8 @@ public class ClientResolver extends Invoker.Unit
PresentsServer.clmgr.mapClientObject(_username, _clobj); PresentsServer.clmgr.mapClientObject(_username, _clobj);
// and let the listeners in on the secret as well // and let the listeners in on the secret as well
int lcount = _listeners.size(); for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) {
for (int i = 0; i < lcount; i++) { ClientResolutionListener crl = _listeners.get(ii);
ClientResolutionListener crl = (ClientResolutionListener)
_listeners.get(i);
try { try {
// add a reference for each listener // add a reference for each listener
_clobj.reference(); _clobj.reference();
@@ -173,10 +171,8 @@ public class ClientResolver extends Invoker.Unit
*/ */
protected void reportFailure (Exception cause) protected void reportFailure (Exception cause)
{ {
int lcount = _listeners.size(); for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) {
for (int i = 0; i < lcount; i++) { ClientResolutionListener crl = _listeners.get(ii);
ClientResolutionListener crl = (ClientResolutionListener)
_listeners.get(i);
try { try {
crl.resolutionFailed(_username, cause); crl.resolutionFailed(_username, cause);
} catch (Exception e) { } catch (Exception e) {
@@ -193,7 +189,8 @@ public class ClientResolver extends Invoker.Unit
protected Name _username; protected Name _username;
/** The entities to notify of success or failure. */ /** The entities to notify of success or failure. */
protected ArrayList _listeners = new ArrayList(); protected ArrayList<ClientResolutionListener> _listeners =
new ArrayList<ClientResolutionListener>();
/** The resolving client object. */ /** The resolving client object. */
protected ClientObject _clobj; protected ClientObject _clobj;
@@ -512,7 +512,7 @@ public class PresentsClient
*/ */
public synchronized void unmapSubscrip (int oid) public synchronized void unmapSubscrip (int oid)
{ {
DObject object = (DObject)_subscrips.remove(oid); DObject object = _subscrips.remove(oid);
if (object != null) { if (object != null) {
object.removeSubscriber(this); object.removeSubscriber(this);
} else { } else {
@@ -527,8 +527,7 @@ public class PresentsClient
*/ */
protected void clearSubscrips (boolean verbose) protected void clearSubscrips (boolean verbose)
{ {
for (Iterator itr = _subscrips.elements(); itr.hasNext(); ) { for (DObject object : _subscrips.values()) {
DObject object = (DObject)itr.next();
if (verbose) { if (verbose) {
Log.info("Clearing subscription [client=" + this + Log.info("Clearing subscription [client=" + this +
", obj=" + object.getOid() + "]."); ", obj=" + object.getOid() + "].");
@@ -751,8 +750,7 @@ public class PresentsClient
// we dispatch to a message dispatcher that is specialized for the // we dispatch to a message dispatcher that is specialized for the
// particular class of message that we received // particular class of message that we received
MessageDispatcher disp = (MessageDispatcher) MessageDispatcher disp = _disps.get(message.getClass());
_disps.get(message.getClass());
if (disp == null) { if (disp == null) {
Log.warning("No dispatcher for message [msg=" + message + "]."); Log.warning("No dispatcher for message [msg=" + message + "].");
return; return;
@@ -957,7 +955,7 @@ public class PresentsClient
protected Name _username; protected Name _username;
protected Connection _conn; protected Connection _conn;
protected ClientObject _clobj; protected ClientObject _clobj;
protected HashIntMap _subscrips = new HashIntMap(); protected HashIntMap<DObject> _subscrips = new HashIntMap<DObject>();
protected ClassLoader _loader; protected ClassLoader _loader;
/** The time at which this client started their session. */ /** The time at which this client started their session. */
@@ -981,7 +979,8 @@ public class PresentsClient
protected int _messagesDropped; protected int _messagesDropped;
/** A mapping of message dispatchers. */ /** A mapping of message dispatchers. */
protected static HashMap _disps = new HashMap(); protected static HashMap<Class<?>,MessageDispatcher> _disps =
new HashMap<Class<?>,MessageDispatcher>();
/** The amount of time after disconnection a user is allowed before /** The amount of time after disconnection a user is allowed before
* their session is forcibly ended. */ * their session is forcibly ended. */
@@ -396,9 +396,11 @@ public class ConnectionManager extends LoopingThread
} }
// send any messages that are waiting on the outgoing queue // send any messages that are waiting on the outgoing queue
Tuple tup; Object obj;
while ((tup = (Tuple)_outq.getNonBlocking()) != null) { while ((obj = _outq.getNonBlocking()) != null) {
Connection conn = (Connection)tup.left; @SuppressWarnings("unchecked") Tuple<Connection,byte[]> tup =
(Tuple<Connection,byte[]>)obj;
Connection conn = tup.left;
// if an overflow queue exists for this client, go ahead and // if an overflow queue exists for this client, go ahead and
// slap the message on there because we can't send it until // slap the message on there because we can't send it until
@@ -416,7 +418,7 @@ public class ConnectionManager extends LoopingThread
} }
// otherwise write the message out to the client directly // otherwise write the message out to the client directly
writeMessage(conn, (byte[])tup.right, _oflowHandler); writeMessage(conn, tup.right, _oflowHandler);
} }
// check for connections that have completed authentication // check for connections that have completed authentication
@@ -735,7 +737,7 @@ public class ConnectionManager extends LoopingThread
// data.length + " bytes."); // data.length + " bytes.");
// and slap both on the queue // and slap both on the queue
_outq.append(new Tuple(conn, data)); _outq.append(new Tuple<Connection,byte[]>(conn, data));
} catch (Exception e) { } catch (Exception e) {
Log.warning("Failure flattening message [conn=" + conn + Log.warning("Failure flattening message [conn=" + conn +
@@ -791,7 +793,7 @@ public class ConnectionManager extends LoopingThread
* higher levels so that further messages are not queued up for the * higher levels so that further messages are not queued up for the
* unresponsive client. * unresponsive client.
*/ */
protected class OverflowQueue extends ArrayList protected class OverflowQueue extends ArrayList<byte[]>
implements PartialWriteHandler implements PartialWriteHandler
{ {
/** The connection for which we're managing overflow. */ /** The connection for which we're managing overflow. */
@@ -841,7 +843,7 @@ public class ConnectionManager extends LoopingThread
} }
while (size() > 0) { while (size() > 0) {
byte[] data = (byte[])remove(0); byte[] data = remove(0);
// if any of these messages are partially written, we have // if any of these messages are partially written, we have
// to stop and wait for the next tick // to stop and wait for the next tick
_msgs++; _msgs++;