ZOMG, Narya now perfectly passes our coding standards as enforced by

CheckStyle. The checks are slightly looser than I'd like but way better than
nothing and we get a bunch of other useful warnings like shadowed names and
other handy bits.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5253 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-07-22 14:36:54 +00:00
parent 5c4ab96880
commit 0a893e1de1
33 changed files with 159 additions and 124 deletions
@@ -193,6 +193,7 @@ public class ClientResolver extends Invoker.Unit
/** A place to keep an exception around for a moment. */
protected Exception _failure;
@Inject @MainInvoker Invoker _invoker;
@Inject RootDObjectManager _omgr;
// dependencies
protected @Inject @MainInvoker Invoker _invoker;
protected @Inject RootDObjectManager _omgr;
}
@@ -21,8 +21,10 @@
package com.threerings.presents.server;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -33,7 +35,6 @@ import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil;
import com.threerings.io.Streamable;
import com.threerings.util.StreamableArrayList;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller.ListenerMarshaller;
@@ -100,7 +101,8 @@ public class InvocationManager
*
* @param dispatcher the dispatcher to be registered.
*/
public <T extends InvocationMarshaller> T registerDispatcher (InvocationDispatcher<T> dispatcher)
public <T extends InvocationMarshaller> T registerDispatcher (
InvocationDispatcher<T> dispatcher)
{
return registerDispatcher(dispatcher, null);
}
@@ -139,9 +141,9 @@ public class InvocationManager
// if it's a bootstrap service, slap it in the list
if (group != null) {
StreamableArrayList<InvocationMarshaller> list = _bootlists.get(group);
List<InvocationMarshaller> list = _bootlists.get(group);
if (list == null) {
_bootlists.put(group, list = new StreamableArrayList<InvocationMarshaller>());
_bootlists.put(group, list = Lists.newArrayList());
}
list.add(marsh);
}
@@ -175,12 +177,11 @@ public class InvocationManager
/**
* Constructs a list of all bootstrap services registered in any of the supplied groups.
*/
public StreamableArrayList<InvocationMarshaller> getBootstrapServices (String[] bootGroups)
public List<InvocationMarshaller> getBootstrapServices (String[] bootGroups)
{
StreamableArrayList<InvocationMarshaller> services =
new StreamableArrayList<InvocationMarshaller>();
List<InvocationMarshaller> services = Lists.newArrayList();
for (String group : bootGroups) {
StreamableArrayList<InvocationMarshaller> list = _bootlists.get(group);
List<InvocationMarshaller> list = _bootlists.get(group);
if (list != null) {
services.addAll(list);
}
@@ -319,10 +320,11 @@ public class InvocationManager
protected IntMap<InvocationDispatcher> _dispatchers = IntMaps.newHashIntMap();
/** Maps bootstrap group to lists of services to be provided to clients at boot time. */
protected Map<String,StreamableArrayList<InvocationMarshaller>> _bootlists = Maps.newHashMap();
protected Map<String, List<InvocationMarshaller>> _bootlists = Maps.newHashMap();
// debugging action...
protected final Map<Integer,String> _recentRegServices = new LRUHashMap<Integer,String>(10000);
protected final Map<Integer, String> _recentRegServices =
new LRUHashMap<Integer, String>(10000);
/** The text appended to the procedure name when generating a failure response. */
protected static final String FAILED_SUFFIX = "Failed";
@@ -538,7 +538,7 @@ public class PresentsClient
*/
protected void handleThrottleExceeded ()
{
log.warning("Client sent more than 100 messages in 10 seconds, disconnecting " + this + ".");
log.warning("Client sent more than 100 msgs in 10 seconds, disconnecting " + this + ".");
safeEndSession();
_throttle = null;
}
@@ -676,11 +676,11 @@ public class PresentsClient
data.clientOid = _clobj.getOid();
// fill in the list of bootstrap services
data.services = new StreamableArrayList<InvocationMarshaller>();
if (_areq.getBootGroups() == null) {
log.warning("Client provided no invocation service boot groups? " + this);
data.services = new StreamableArrayList<InvocationMarshaller>();
} else {
data.services = _invmgr.getBootstrapServices(_areq.getBootGroups());
data.services.addAll(_invmgr.getBootstrapServices(_areq.getBootGroups()));
}
}
@@ -847,20 +847,20 @@ public class PresentsClient
}
// from interface ProxySubscriber
public void objectAvailable (DObject object)
public void objectAvailable (DObject dobj)
{
if (postMessage(new ObjectResponse<DObject>(object))) {
if (postMessage(new ObjectResponse<DObject>(dobj))) {
_firstEventId = _omgr.getNextEventId(false);
this.object = object;
object = dobj;
synchronized (_subscrips) {
// make a note of this new subscription
_subscrips.put(object.getOid(), this);
_subscrips.put(dobj.getOid(), this);
}
subscribedToObject(object);
subscribedToObject(dobj);
} else {
// if we failed to send the object response, unsubscribe
object.removeSubscriber(this);
dobj.removeSubscriber(this);
}
}
@@ -903,7 +903,7 @@ public class PresentsClient
/**
* Dispatch the supplied message for the specified client.
*/
public void dispatch (PresentsClient client, UpstreamMessage mge);
void dispatch (PresentsClient client, UpstreamMessage mge);
}
/**
@@ -1025,7 +1025,7 @@ public class PresentsClient
protected int _messagesDropped;
/** A mapping of message dispatchers. */
protected static Map<Class<?>,MessageDispatcher> _disps = Maps.newHashMap();
protected static Map<Class<?>, MessageDispatcher> _disps = Maps.newHashMap();
/** The amount of time after disconnection a user is allowed before their session is forcibly
* ended. */
@@ -21,7 +21,9 @@
package com.threerings.presents.server;
import java.lang.reflect.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
@@ -39,7 +41,20 @@ import com.samskivert.util.RunQueue;
import com.samskivert.util.StringUtil;
import com.samskivert.util.Throttle;
import com.threerings.presents.dobj.*;
import com.threerings.presents.dobj.AccessController;
import com.threerings.presents.dobj.CompoundEvent;
import com.threerings.presents.dobj.DEvent;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.dobj.InvocationRequestEvent;
import com.threerings.presents.dobj.NoSuchObjectException;
import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.ObjectAddedEvent;
import com.threerings.presents.dobj.ObjectDestroyedEvent;
import com.threerings.presents.dobj.ObjectRemovedEvent;
import com.threerings.presents.dobj.OidList;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.dobj.Subscriber;
import static com.threerings.presents.Log.log;
@@ -338,7 +353,7 @@ public class PresentsDObjectMgr
*/
public void dumpUnitProfiles ()
{
for (Map.Entry<String,UnitProfile> entry : _profiles.entrySet()) {
for (Map.Entry<String, UnitProfile> entry : _profiles.entrySet()) {
log.info("P: " + entry.getKey() + " => " + entry.getValue());
}
}
@@ -534,7 +549,7 @@ public class PresentsDObjectMgr
if (UNIT_PROF_ENABLED) {
report.append("- Unit profiles: ").append(_profiles.size()).append("\n");
for (Map.Entry<String,UnitProfile> entry : _profiles.entrySet()) {
for (Map.Entry<String, UnitProfile> entry : _profiles.entrySet()) {
report.append(" ").append(entry.getKey());
report.append(" ").append(entry.getValue()).append("\n");
}
@@ -910,15 +925,13 @@ public class PresentsDObjectMgr
public String field;
public int reffedOid;
public Reference (int reffingOid, String field, int reffedOid)
{
public Reference (int reffingOid, String field, int reffedOid) {
this.reffingOid = reffingOid;
this.field = field;
this.reffedOid = reffedOid;
}
public boolean equals (Reference other)
{
public boolean equals (Reference other) {
if (other == null) {
return false;
} else {
@@ -926,14 +939,15 @@ public class PresentsDObjectMgr
}
}
public boolean equals (int reffingOid, String field)
{
return (this.reffingOid == reffingOid && this.field.equals(field));
public boolean equals (int oReffingOid, String oField) {
return (reffingOid == oReffingOid && field.equals(oField));
}
@Override
public String toString ()
{
@Override public int hashCode () {
return reffingOid ^ field.hashCode();
}
@Override public String toString () {
return "[reffingOid=" + reffingOid + ", field=" + field +
", reffedOid=" + reffedOid + "]";
}
@@ -1010,13 +1024,13 @@ public class PresentsDObjectMgr
protected long _nextEventId = 1;
/** Used to profile our events and runnable units. */
protected Map<String,UnitProfile> _profiles = Maps.newHashMap();
protected Map<String, UnitProfile> _profiles = Maps.newHashMap();
/** Used to track runtime statistics. */
protected Stats _recent = new Stats(), _current = _recent;
/** Maps event classes to helpers that perform additional processing for particular events. */
protected Map<Class,Method> _helpers = Maps.newHashMap();
protected Map<Class, Method> _helpers = Maps.newHashMap();
/** Used to resolve unit names when profiling. Injected by the invmgr when it's created. */
protected InvocationManager _invmgr;
@@ -48,6 +48,7 @@ public class ShutdownManager
void shutdown ();
}
/** Constraints for use with {@link #addConstraint}. */
public static enum Constraint { RUNS_BEFORE, RUNS_AFTER };
@Inject ShutdownManager (@EventQueue RunQueue dobjq)
@@ -75,7 +76,6 @@ public class ShutdownManager
* Adds a constraint that a certain shutdowner must be run before another.
*/
public void addConstraint (Shutdowner lhs, Constraint constraint, Shutdowner rhs)
throws IllegalArgumentException
{
if (lhs == null || rhs == null) {
throw new IllegalArgumentException("Cannot add constraint about null shutdowner.");
@@ -283,7 +283,7 @@ public class ConnectionManager extends LoopingThread
protected void willStart ()
{
int successes = 0;
IOException _failure = null;
IOException failure = null;
for (int ii = 0; ii < _ports.length; ii++) {
try {
// create a listening socket and add it to the select set
@@ -299,7 +299,7 @@ public class ConnectionManager extends LoopingThread
} catch (IOException ioe) {
log.warning("Failure listening to socket on port '" +
_ports[ii] + "'.", ioe);
_failure = ioe;
failure = ioe;
}
}
@@ -332,7 +332,7 @@ public class ConnectionManager extends LoopingThread
// if we failed to listen on at least one port, give up the ghost
if (successes == 0) {
if (_startlist != null) {
_startlist.requestFailed(_failure);
_startlist.requestFailed(failure);
}
return;
}
@@ -581,7 +581,7 @@ public class ConnectionManager extends LoopingThread
}
// then send any new messages
Tuple<Connection,byte[]> tup;
Tuple<Connection, byte[]> tup;
while ((tup = _outq.getNonBlocking()) != null) {
Connection conn = tup.left;
@@ -882,7 +882,7 @@ public class ConnectionManager extends LoopingThread
// log.info("Flattened " + msg + " into " + data.length + " bytes.");
// and slap both on the queue
_outq.append(new Tuple<Connection,byte[]>(conn, data));
_outq.append(new Tuple<Connection, byte[]>(conn, data));
} catch (Exception e) {
log.warning("Failure flattening message [conn=" + conn +
@@ -1017,7 +1017,7 @@ public class ConnectionManager extends LoopingThread
}
// documentation inherited
public void handlePartialWrite (Connection conn, ByteBuffer buffer)
public void handlePartialWrite (Connection wconn, ByteBuffer buffer)
{
// set up our _partial buffer
_partial = ByteBuffer.allocateDirect(buffer.remaining());
@@ -1062,7 +1062,7 @@ public class ConnectionManager extends LoopingThread
protected int _runtimeExceptionCount;
/** Maps selection keys to network event handlers. */
protected Map<SelectionKey,NetEventHandler> _handlers = Maps.newHashMap();
protected Map<SelectionKey, NetEventHandler> _handlers = Maps.newHashMap();
/** Connections mapped by identifier. */
protected IntMap<Connection> _connections = IntMaps.newHashIntMap();
@@ -1070,14 +1070,14 @@ public class ConnectionManager extends LoopingThread
protected Queue<Connection> _deathq = new Queue<Connection>();
protected Queue<AuthingConnection> _authq = new Queue<AuthingConnection>();
protected Queue<Tuple<Connection,byte[]>> _outq = new Queue<Tuple<Connection,byte[]>>();
protected Queue<Tuple<Connection,byte[]>> _dataq = new Queue<Tuple<Connection,byte[]>>();
protected Queue<Tuple<Connection, byte[]>> _outq = new Queue<Tuple<Connection, byte[]>>();
protected Queue<Tuple<Connection, byte[]>> _dataq = new Queue<Tuple<Connection, byte[]>>();
protected FramingOutputStream _framer;
protected ByteArrayOutputStream _flattener;
protected ByteBuffer _outbuf = ByteBuffer.allocateDirect(64 * 1024);
protected ByteBuffer _databuf = ByteBuffer.allocateDirect(Client.MAX_DATAGRAM_SIZE);
protected Map<Connection,OverflowQueue> _oflowqs = Maps.newHashMap();
protected Map<Connection, OverflowQueue> _oflowqs = Maps.newHashMap();
protected List<ConnectionObserver> _observers = Lists.newArrayList();