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:
@@ -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<ChatMessage> getChatHistory (Name username)
|
||||
{
|
||||
ArrayList history = getHistoryList(username);
|
||||
ArrayList<ChatMessage> 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<ChatMessage> 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<ChatMessage> getHistoryList (Name username)
|
||||
{
|
||||
ArrayList history = (ArrayList)_histories.get(username);
|
||||
ArrayList<ChatMessage> history = _histories.get(username);
|
||||
if (history == null) {
|
||||
_histories.put(username, history = new ArrayList());
|
||||
_histories.put(username, history = new ArrayList<ChatMessage>());
|
||||
}
|
||||
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<ChatMessage> 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<MessageObserver>
|
||||
{
|
||||
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<Name,ArrayList<ChatMessage>> _histories =
|
||||
new HashMap<Name,ArrayList<ChatMessage>>();
|
||||
|
||||
/** 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<MessageObserver> _messageObs =
|
||||
new ObserverList<MessageObserver>(ObserverList.FAST_UNSAFE_NOTIFY);
|
||||
|
||||
/** Used to notify our {@link MessageObserver}s. */
|
||||
protected static MessageObserverOp _messageOp = new MessageObserverOp();
|
||||
|
||||
@@ -649,7 +649,7 @@ public class Client
|
||||
* Used to notify client observers of events.
|
||||
*/
|
||||
protected class Notifier
|
||||
implements ObserverList.ObserverOp
|
||||
implements ObserverList.ObserverOp<SessionObserver>
|
||||
{
|
||||
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<SessionObserver> _observers =
|
||||
new ObserverList<SessionObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY);
|
||||
|
||||
/** The entity that manages our network communications. */
|
||||
protected Communicator _comm;
|
||||
|
||||
@@ -29,7 +29,7 @@ package com.threerings.presents.dobj;
|
||||
*
|
||||
* @see DObject#addListener
|
||||
*/
|
||||
public interface ProxySubscriber extends Subscriber
|
||||
public interface ProxySubscriber extends Subscriber<DObject>
|
||||
{
|
||||
/**
|
||||
* Called when any event has been dispatched on an object.
|
||||
|
||||
@@ -40,7 +40,7 @@ import com.threerings.presents.dobj.Subscriber;
|
||||
* appropriately.
|
||||
*/
|
||||
public class ClientResolver extends Invoker.Unit
|
||||
implements Subscriber
|
||||
implements Subscriber<ClientObject>
|
||||
{
|
||||
/**
|
||||
* 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<ClientResolutionListener> _listeners =
|
||||
new ArrayList<ClientResolutionListener>();
|
||||
|
||||
/** The resolving client object. */
|
||||
protected ClientObject _clobj;
|
||||
|
||||
@@ -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<DObject> _subscrips = new HashIntMap<DObject>();
|
||||
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<Class<?>,MessageDispatcher> _disps =
|
||||
new HashMap<Class<?>,MessageDispatcher>();
|
||||
|
||||
/** The amount of time after disconnection a user is allowed before
|
||||
* their session is forcibly ended. */
|
||||
|
||||
@@ -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<Connection,byte[]> tup =
|
||||
(Tuple<Connection,byte[]>)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<Connection,byte[]>(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<byte[]>
|
||||
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++;
|
||||
|
||||
Reference in New Issue
Block a user