From 0a5953bf17fdd93336572c7e6708a171e47d636f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 27 Jun 2006 17:46:36 +0000 Subject: [PATCH] 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 --- .../crowd/chat/server/SpeakProvider.java | 31 ++++++++++--------- .../threerings/presents/client/Client.java | 9 +++--- .../presents/dobj/ProxySubscriber.java | 2 +- .../presents/server/ClientResolver.java | 21 ++++++------- .../presents/server/PresentsClient.java | 13 ++++---- .../server/net/ConnectionManager.java | 16 +++++----- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/server/SpeakProvider.java b/src/java/com/threerings/crowd/chat/server/SpeakProvider.java index 011927741..11b68944b 100644 --- a/src/java/com/threerings/crowd/chat/server/SpeakProvider.java +++ b/src/java/com/threerings/crowd/chat/server/SpeakProvider.java @@ -295,9 +295,9 @@ public class SpeakProvider * Returns a list of {@link ChatMessage} objects to which this user * has been privy in the recent past. */ - public static ArrayList getChatHistory (Name username) + public static ArrayList getChatHistory (Name username) { - ArrayList history = getHistoryList(username); + ArrayList history = getHistoryList(username); pruneHistory(System.currentTimeMillis(), history); return history; } @@ -323,7 +323,7 @@ public class SpeakProvider } // add the message to this user's chat history - ArrayList history = getHistoryList(username); + ArrayList history = getHistoryList(username); history.add(msg); // 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. */ - protected static ArrayList getHistoryList (Name username) + protected static ArrayList getHistoryList (Name username) { - ArrayList history = (ArrayList)_histories.get(username); + ArrayList history = _histories.get(username); if (history == null) { - _histories.put(username, history = new ArrayList()); + _histories.put(username, history = new ArrayList()); } return history; } @@ -354,11 +354,12 @@ public class SpeakProvider /** * Prunes all messages from this history which are expired. */ - protected static void pruneHistory (long now, ArrayList history) + protected static void pruneHistory ( + long now, ArrayList history) { int prunepos = 0; 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) { break; // stop when we get to the first valid message } @@ -384,15 +385,16 @@ public class SpeakProvider } /** Used to notify our {@link MessageObserver}s. */ - protected static class MessageObserverOp implements ObserverList.ObserverOp + protected static class MessageObserverOp + implements ObserverList.ObserverOp { public void init (Name hearer, UserMessage message) { _hearer = hearer; _message = message; } - public boolean apply (Object observer) { - ((MessageObserver)observer).messageDelivered(_hearer, _message); + public boolean apply (MessageObserver observer) { + observer.messageDelivered(_hearer, _message); return true; } @@ -407,14 +409,15 @@ public class SpeakProvider protected SpeakerValidator _validator; /** Recent chat history for the server. */ - protected static HashMap _histories = new HashMap(); + protected static HashMap> _histories = + new HashMap>(); /** Used to note the recipients of a chat message. */ protected static MessageMapper _messageMapper = new MessageMapper(); /** A list of {@link MessageObserver}s. */ - protected static ObserverList _messageObs = new ObserverList( - ObserverList.FAST_UNSAFE_NOTIFY); + protected static ObserverList _messageObs = + new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); /** Used to notify our {@link MessageObserver}s. */ protected static MessageObserverOp _messageOp = new MessageObserverOp(); diff --git a/src/java/com/threerings/presents/client/Client.java b/src/java/com/threerings/presents/client/Client.java index 4990298e4..e28bbd1be 100644 --- a/src/java/com/threerings/presents/client/Client.java +++ b/src/java/com/threerings/presents/client/Client.java @@ -649,7 +649,7 @@ public class Client * Used to notify client observers of events. */ protected class Notifier - implements ObserverList.ObserverOp + implements ObserverList.ObserverOp { public Notifier (int code, Exception cause) { @@ -663,9 +663,8 @@ public class Client return _rejected; } - public boolean apply (Object observer) + public boolean apply (SessionObserver obs) { - SessionObserver obs = (SessionObserver)observer; switch (_code) { case CLIENT_DID_LOGON: obs.clientDidLogon(Client.this); @@ -748,8 +747,8 @@ public class Client protected int[] _ports; /** Our list of client observers. */ - protected ObserverList _observers = - new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); + protected ObserverList _observers = + new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); /** The entity that manages our network communications. */ protected Communicator _comm; diff --git a/src/java/com/threerings/presents/dobj/ProxySubscriber.java b/src/java/com/threerings/presents/dobj/ProxySubscriber.java index e3ea97b56..b0490d43a 100644 --- a/src/java/com/threerings/presents/dobj/ProxySubscriber.java +++ b/src/java/com/threerings/presents/dobj/ProxySubscriber.java @@ -29,7 +29,7 @@ package com.threerings.presents.dobj; * * @see DObject#addListener */ -public interface ProxySubscriber extends Subscriber +public interface ProxySubscriber extends Subscriber { /** * Called when any event has been dispatched on an object. diff --git a/src/java/com/threerings/presents/server/ClientResolver.java b/src/java/com/threerings/presents/server/ClientResolver.java index 3b0c52bfd..5b5ad9bdb 100644 --- a/src/java/com/threerings/presents/server/ClientResolver.java +++ b/src/java/com/threerings/presents/server/ClientResolver.java @@ -40,7 +40,7 @@ import com.threerings.presents.dobj.Subscriber; * appropriately. */ public class ClientResolver extends Invoker.Unit - implements Subscriber + implements Subscriber { /** * Initiailizes this instance. @@ -70,11 +70,11 @@ public class ClientResolver extends Invoker.Unit } // documentation inherited - public void objectAvailable (DObject object) + public void objectAvailable (ClientObject object) { // we've got our object, so shunt ourselves over to the invoker // thread to perform database loading - _clobj = (ClientObject)object; + _clobj = object; PresentsServer.invoker.postUnit(this); // 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); // and let the listeners in on the secret as well - int lcount = _listeners.size(); - for (int i = 0; i < lcount; i++) { - ClientResolutionListener crl = (ClientResolutionListener) - _listeners.get(i); + for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) { + ClientResolutionListener crl = _listeners.get(ii); try { // add a reference for each listener _clobj.reference(); @@ -173,10 +171,8 @@ public class ClientResolver extends Invoker.Unit */ protected void reportFailure (Exception cause) { - int lcount = _listeners.size(); - for (int i = 0; i < lcount; i++) { - ClientResolutionListener crl = (ClientResolutionListener) - _listeners.get(i); + for (int ii = 0, ll = _listeners.size(); ii < ll; ii++) { + ClientResolutionListener crl = _listeners.get(ii); try { crl.resolutionFailed(_username, cause); } catch (Exception e) { @@ -193,7 +189,8 @@ public class ClientResolver extends Invoker.Unit protected Name _username; /** The entities to notify of success or failure. */ - protected ArrayList _listeners = new ArrayList(); + protected ArrayList _listeners = + new ArrayList(); /** The resolving client object. */ protected ClientObject _clobj; diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index 664386292..f41a6f3df 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -512,7 +512,7 @@ public class PresentsClient */ public synchronized void unmapSubscrip (int oid) { - DObject object = (DObject)_subscrips.remove(oid); + DObject object = _subscrips.remove(oid); if (object != null) { object.removeSubscriber(this); } else { @@ -527,8 +527,7 @@ public class PresentsClient */ protected void clearSubscrips (boolean verbose) { - for (Iterator itr = _subscrips.elements(); itr.hasNext(); ) { - DObject object = (DObject)itr.next(); + for (DObject object : _subscrips.values()) { if (verbose) { Log.info("Clearing subscription [client=" + this + ", obj=" + object.getOid() + "]."); @@ -751,8 +750,7 @@ public class PresentsClient // we dispatch to a message dispatcher that is specialized for the // particular class of message that we received - MessageDispatcher disp = (MessageDispatcher) - _disps.get(message.getClass()); + MessageDispatcher disp = _disps.get(message.getClass()); if (disp == null) { Log.warning("No dispatcher for message [msg=" + message + "]."); return; @@ -957,7 +955,7 @@ public class PresentsClient protected Name _username; protected Connection _conn; protected ClientObject _clobj; - protected HashIntMap _subscrips = new HashIntMap(); + protected HashIntMap _subscrips = new HashIntMap(); protected ClassLoader _loader; /** The time at which this client started their session. */ @@ -981,7 +979,8 @@ public class PresentsClient protected int _messagesDropped; /** A mapping of message dispatchers. */ - protected static HashMap _disps = new HashMap(); + protected static HashMap,MessageDispatcher> _disps = + new HashMap,MessageDispatcher>(); /** The amount of time after disconnection a user is allowed before * their session is forcibly ended. */ diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index 3d1f35824..678b9d160 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -396,9 +396,11 @@ public class ConnectionManager extends LoopingThread } // send any messages that are waiting on the outgoing queue - Tuple tup; - while ((tup = (Tuple)_outq.getNonBlocking()) != null) { - Connection conn = (Connection)tup.left; + Object obj; + while ((obj = _outq.getNonBlocking()) != null) { + @SuppressWarnings("unchecked") Tuple tup = + (Tuple)obj; + Connection conn = tup.left; // if an overflow queue exists for this client, go ahead and // 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 - writeMessage(conn, (byte[])tup.right, _oflowHandler); + writeMessage(conn, tup.right, _oflowHandler); } // check for connections that have completed authentication @@ -735,7 +737,7 @@ public class ConnectionManager extends LoopingThread // data.length + " bytes."); // and slap both on the queue - _outq.append(new Tuple(conn, data)); + _outq.append(new Tuple(conn, data)); } catch (Exception e) { 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 * unresponsive client. */ - protected class OverflowQueue extends ArrayList + protected class OverflowQueue extends ArrayList implements PartialWriteHandler { /** The connection for which we're managing overflow. */ @@ -841,7 +843,7 @@ public class ConnectionManager extends LoopingThread } while (size() > 0) { - byte[] data = (byte[])remove(0); + byte[] data = remove(0); // if any of these messages are partially written, we have // to stop and wait for the next tick _msgs++;