Styley stylopolis.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5252 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-07-22 14:01:51 +00:00
parent 706b85a0e4
commit 5c4ab96880
26 changed files with 139 additions and 77 deletions
@@ -35,8 +35,25 @@ import com.samskivert.util.StringUtil;
import com.samskivert.util.IntMap;
import com.samskivert.util.Interval;
import com.threerings.presents.dobj.*;
import com.threerings.presents.net.*;
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.ObjectAccessException;
import com.threerings.presents.dobj.ObjectDestroyedEvent;
import com.threerings.presents.dobj.Subscriber;
import com.threerings.presents.net.BootstrapData;
import com.threerings.presents.net.BootstrapNotification;
import com.threerings.presents.net.DownstreamMessage;
import com.threerings.presents.net.EventNotification;
import com.threerings.presents.net.FailureResponse;
import com.threerings.presents.net.ForwardEventRequest;
import com.threerings.presents.net.ObjectResponse;
import com.threerings.presents.net.PongResponse;
import com.threerings.presents.net.SubscribeRequest;
import com.threerings.presents.net.UnsubscribeRequest;
import com.threerings.presents.net.UnsubscribeResponse;
import static com.threerings.presents.Log.log;
@@ -913,7 +913,7 @@ public class DObject
protected transient boolean _deathWish = false;
/** Maintains a mapping of sorted field arrays for each distributed object class. */
protected static HashMap<Class,Field[]> _ftable = new HashMap<Class,Field[]>();
protected static HashMap<Class, Field[]> _ftable = new HashMap<Class, Field[]>();
/** Used to sort and search {@link #_fields}. */
protected static final Comparator<Field> FIELD_COMP = new Comparator<Field>() {
@@ -28,7 +28,6 @@ import java.util.ConcurrentModificationException;
import java.util.Iterator;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.StringUtil;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
@@ -49,6 +48,8 @@ import static com.threerings.presents.Log.log;
* case of entry removal, only the key for the entry to be removed will be transmitted with the
* removal event to save network bandwidth. Lastly, the object returned by {@link Entry#getKey}
* must be a {@link Streamable} type.
*
* @param <E> the type of entry stored in this set.
*/
public class DSet<E extends DSet.Entry>
implements Iterable<E>, Streamable, Cloneable
@@ -197,10 +198,8 @@ public class DSet<E extends DSet.Entry>
public Iterator<E> iterator ()
{
// the crazy sanity checks
if (_size < 0 ||_size > _entries.length ||
(_size > 0 && _entries[_size-1] == null)) {
log.warning("DSet in a bad way [size=" + _size +
", entries=" + StringUtil.toString(_entries) + "].");
if (_size < 0 || _size > _entries.length || (_size > 0 && _entries[_size-1] == null)) {
log.warning("DSet in a bad way", "size", _size, "entries", _entries);
Thread.dumpStack();
}
@@ -221,9 +220,8 @@ public class DSet<E extends DSet.Entry>
throw new ConcurrentModificationException();
}
if (_ssize != _size) {
log.warning("Size changed during iteration [ssize=" + _ssize +
", nsize=" + _size +
", entsries=" + StringUtil.toString(_entries) + "].");
log.warning("Size changed during iteration", "ssize", _ssize, "nsize", _size,
"entries", _entries);
Thread.dumpStack();
}
}
@@ -460,6 +458,7 @@ public class DSet<E extends DSet.Entry>
}
}
/** Used to search for keys. */
protected static class KeyWrapper implements DSet.Entry
{
public KeyWrapper (Comparable key) {
@@ -44,7 +44,7 @@ public class DynamicListener
{
this(target, new MethodFinder(target.getClass()));
}
/**
* Creates a listener that dynamically dispatches events on the supplied
* target using the methods in finder.
@@ -140,5 +140,5 @@ public class DynamicListener
protected MethodFinder _finder;
/** A cache of already resolved methods. */
protected HashMap<String,Method> _mcache = new HashMap<String,Method>();
protected HashMap<String, Method> _mcache = new HashMap<String, Method>();
}
@@ -29,6 +29,9 @@ import com.samskivert.util.StringUtil;
* posted to the dobjmgr.
*
* @see DObjectManager#postEvent
*
* @param <T> the type of entry being handled by this event. This must match the type on the set
* that generated this event.
*/
public class EntryAddedEvent<T extends DSet.Entry> extends NamedEvent
{
@@ -29,6 +29,9 @@ import static com.threerings.presents.Log.log;
* posted to the dobjmgr.
*
* @see DObjectManager#postEvent
*
* @param <T> the type of entry being handled by this event. This must match the type on the set
* that generated this event.
*/
public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
{
@@ -32,6 +32,9 @@ import static com.threerings.presents.Log.log;
* constructed to request the update of an entry and posted to the dobjmgr.
*
* @see DObjectManager#postEvent
*
* @param <T> the type of entry being handled by this event. This must match the type on the set
* that generated this event.
*/
public class EntryUpdatedEvent<T extends DSet.Entry> extends NamedEvent
{
@@ -24,10 +24,13 @@ package com.threerings.presents.dobj;
/**
* Implements the methods in SetListener so that you don't have to implement the ones you don't
* want to.
*
*
* <p> <b>NOTE:</b> This adapter will receive <em>all</em> Entry events from a DObject it's
* listening to, so it should check that the event's name matches the field it's interested in
* before acting on the event.
*
* @param <T> the type of entry being handled by this listener. This must match the type on the set
* that generates the events.
*/
public class SetAdapter<T extends DSet.Entry> implements SetListener<T>
{
@@ -24,12 +24,15 @@ package com.threerings.presents.dobj;
/**
* Implemented by entities which wish to hear about changes that occur to set attributes of a
* particular distributed object.
*
*
* <p> <b>NOTE:</b> This listener will receive <em>all</em> Entry events from a DObject it's
* listening to, so it should check that the event's name matches the field it's interested in
* before acting on the event.
*
*
* @see DObject#addListener
*
* @param <T> the type of entry being handled by this listener. This must match the type on the set
* that generates the events.
*/
public interface SetListener<T extends DSet.Entry> extends ChangeListener
{
@@ -37,6 +37,8 @@ package com.threerings.presents.dobj;
* @see AttributeChangeListener
* @see SetListener
* @see OidListListener
*
* @param <T> the type object being subscribed to.
*/
public interface Subscriber<T extends DObject>
{
@@ -23,6 +23,9 @@ package com.threerings.presents.net;
import com.threerings.presents.dobj.DEvent;
/**
* Contains an event forwarded from the server.
*/
public class EventNotification extends DownstreamMessage
{
/**
@@ -21,6 +21,9 @@
package com.threerings.presents.net;
/**
* Communicates failure to subscribe to an object.
*/
public class FailureResponse extends DownstreamMessage
{
/**
@@ -23,6 +23,9 @@ package com.threerings.presents.net;
import com.threerings.presents.dobj.DEvent;
/**
* Forwards an event to the server for dispatch.
*/
public class ForwardEventRequest extends UpstreamMessage
{
/**
@@ -21,6 +21,9 @@
package com.threerings.presents.net;
/**
* Requests to end our session with the server.
*/
public class LogoffRequest extends UpstreamMessage
{
/**
@@ -23,6 +23,11 @@ package com.threerings.presents.net;
import com.threerings.presents.dobj.DObject;
/**
* Contains a distributed object to which the client has subscribed.
*
* @param <T> the type of object delivered by the response.
*/
public class ObjectResponse<T extends DObject>
extends DownstreamMessage
{
@@ -26,11 +26,13 @@ import java.io.IOException;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
/**
* Let's the server know we're still alive.
*/
public class PingRequest extends UpstreamMessage
{
/** The number of milliseconds of idle upstream that are allowed to
* elapse before the client sends a ping message to the server to let
* it know that we're still alive. */
/** The number of milliseconds of idle upstream that are allowed to elapse before the client
* sends a ping message to the server to let it know that we're still alive. */
public static final long PING_INTERVAL = 60 * 1000L;
/**
@@ -50,8 +52,8 @@ public class PingRequest extends UpstreamMessage
}
/**
* Returns a timestamp that was obtained when this packet was encoded
* by the low-level networking code.
* Returns a timestamp that was obtained when this packet was encoded by the low-level
* networking code.
*/
public long getPackStamp ()
{
@@ -59,8 +61,8 @@ public class PingRequest extends UpstreamMessage
}
/**
* Returns a timestamp that was obtained when this packet was decoded
* by the low-level networking code.
* Returns a timestamp that was obtained when this packet was decoded by the low-level
* networking code.
*/
public long getUnpackStamp ()
{
@@ -73,8 +75,8 @@ public class PingRequest extends UpstreamMessage
public void writeObject (ObjectOutputStream out)
throws IOException
{
// grab a timestamp noting when we were encoded into a raw buffer
// for delivery over the network
// grab a timestamp noting when we were encoded into a raw buffer for delivery over the
// network
_packStamp = System.currentTimeMillis();
out.defaultWriteObject();
@@ -86,8 +88,8 @@ public class PingRequest extends UpstreamMessage
public void readObject (ObjectInputStream in)
throws IOException, ClassNotFoundException
{
// grab a timestamp noting when we were decoded from a raw buffer
// after being received over the network
// grab a timestamp noting when we were decoded from a raw buffer after being received over
// the network
_unpackStamp = System.currentTimeMillis();
in.defaultReadObject();
@@ -114,9 +116,8 @@ public class PingRequest extends UpstreamMessage
/** A time stamp obtained when we serialize this object. */
protected transient long _packStamp;
/** A time stamp obtained when we unserialize this object (the intent
* is to get a timestamp as close as possible to when the packet was
* received on the network). */
/** A time stamp obtained when we unserialize this object (the intent is to get a timestamp as
* close as possible to when the packet was received on the network). */
protected transient long _unpackStamp;
/** The transport parameters. */
@@ -28,6 +28,10 @@ import com.threerings.io.ObjectOutputStream;
import static com.threerings.presents.Log.log;
/**
* Let's the client know the server heard its ping (and that the server and connection are still
* alive).
*/
public class PongResponse extends DownstreamMessage
{
/**
@@ -39,20 +43,19 @@ public class PongResponse extends DownstreamMessage
}
/**
* Constructs a pong response which will use the supplied ping time to
* establish the end-to-end processing delay introduced by the server.
* Constructs a pong response which will use the supplied ping time to establish the end-to-end
* processing delay introduced by the server.
*/
public PongResponse (long pingStamp, Transport transport)
{
// save this for when we are serialized in preparation for
// delivery over the network
// save this for when we are serialized in preparation for delivery over the network
_pingStamp = pingStamp;
_transport = transport;
}
/**
* Returns the time at which this packet was packed for delivery in
* the time frame of the server that sent the packet.
* Returns the time at which this packet was packed for delivery in the time frame of the
* server that sent the packet.
*/
public long getPackStamp ()
{
@@ -60,9 +63,9 @@ public class PongResponse extends DownstreamMessage
}
/**
* Returns the number of milliseconds that elapsed between the time
* that the ping which instigated this pong was read from the network
* and the time that this pong was written to the network.
* Returns the number of milliseconds that elapsed between the time that the ping which
* instigated this pong was read from the network and the time that this pong was written to
* the network.
*/
public int getProcessDelay ()
{
@@ -70,8 +73,8 @@ public class PongResponse extends DownstreamMessage
}
/**
* Returns a timestamp that was obtained when this packet was decoded
* by the low-level networking code.
* Returns a timestamp that was obtained when this packet was decoded by the low-level
* networking code.
*/
public long getUnpackStamp ()
{
@@ -87,8 +90,7 @@ public class PongResponse extends DownstreamMessage
// make a note of the time at which we were packed
_packStamp = System.currentTimeMillis();
// the time spent between unpacking the ping and packing the pong
// is the processing delay
// the time spent between unpacking the ping and packing the pong is the processing delay
if (_pingStamp == 0L) {
log.warning("Pong response written that was not constructed " +
"with a valid ping stamp [rsp=" + this + "].");
@@ -106,8 +108,8 @@ public class PongResponse extends DownstreamMessage
public void readObject (ObjectInputStream in)
throws IOException, ClassNotFoundException
{
// grab a timestamp noting when we were decoded from a raw buffer
// after being received over the network
// grab a timestamp noting when we were decoded from a raw buffer after being received over
// the network
_unpackStamp = System.currentTimeMillis();
in.defaultReadObject();
@@ -131,23 +133,19 @@ public class PongResponse extends DownstreamMessage
return "[type=PONG, msgid=" + messageId + ", transport=" + _transport + "]";
}
/** The ping unpack stamp provided at construct time to this pong
* response; only valid on the sending process, not the receiving
* process. */
/** The ping unpack stamp provided at construct time to this pong response; only valid on the
* sending process, not the receiving process. */
protected transient long _pingStamp;
/** The timestamp obtained immediately before this packet was sent out
* over the network. */
/** The timestamp obtained immediately before this packet was sent out over the network. */
protected long _packStamp;
/** The delay in milliseconds between the time that the ping request
* was read from the network and the time the pong response was
* written to the network. */
/** The delay in milliseconds between the time that the ping request was read from the network
* and the time the pong response was written to the network. */
protected int _processDelay;
/** A time stamp obtained when we unserialize this object (the intent
* is to get a timestamp as close as possible to when the packet was
* received on the network). */
/** A time stamp obtained when we unserialize this object (the intent is to get a timestamp as
* close as possible to when the packet was received on the network). */
protected transient long _unpackStamp;
/** The transport parameters. */
@@ -21,6 +21,9 @@
package com.threerings.presents.net;
/**
* Requests to subscribe to a particular distributed object.
*/
public class SubscribeRequest extends UpstreamMessage
{
/**
@@ -25,8 +25,8 @@ import com.samskivert.util.HashIntMap;
/**
* Message transport parameters. These include the type of transport and the channel (used to
* define independent streams for ordered transport), and may eventually include message
* priority, etc.
* define independent streams for ordered transport), and may eventually include message priority,
* etc.
*/
public class Transport
{
@@ -109,8 +109,8 @@ public class Transport
}
protected boolean _reliable, _ordered;
}
}
/** The unreliable/unordered mode of transport. */
public static final Transport UNRELIABLE_UNORDERED = getInstance(Type.UNRELIABLE_UNORDERED);
@@ -21,6 +21,9 @@
package com.threerings.presents.net;
/**
* Requests to end a subscription to a particular distributed object.
*/
public class UnsubscribeRequest extends UpstreamMessage
{
/**
@@ -23,6 +23,9 @@ package com.threerings.presents.net;
import com.threerings.util.Name;
/**
* Extends the basic credentials with a password.
*/
public class UsernamePasswordCreds extends Credentials
{
/**
@@ -376,7 +376,7 @@ public abstract class PeerManager
return;
}
final Tuple<String,Integer> key = new Tuple<String,Integer>(nodeName, remoteOid);
final Tuple<String, Integer> key = new Tuple<String, Integer>(nodeName, remoteOid);
if (_proxies.containsKey(key)) {
String errmsg = "Cannot proxy already proxied object [key=" + key + "].";
listener.requestFailed(new ObjectAccessException(errmsg));
@@ -387,7 +387,7 @@ public abstract class PeerManager
peer.getDObjectManager().subscribeToObject(remoteOid, new Subscriber<T>() {
public void objectAvailable (T object) {
// make a note of this proxy mapping
_proxies.put(key, new Tuple<Subscriber<?>,DObject>(this, object));
_proxies.put(key, new Tuple<Subscriber<?>, DObject>(this, object));
// map the object into our local oid space
_omgr.registerProxyObject(object, peer.getDObjectManager());
// then tell the caller about the (now remapped) oid
@@ -405,8 +405,8 @@ public abstract class PeerManager
*/
public void unproxyRemoteObject (String nodeName, int remoteOid)
{
Tuple<String,Integer> key = new Tuple<String,Integer>(nodeName, remoteOid);
Tuple<Subscriber<?>,DObject> bits = _proxies.remove(key);
Tuple<String, Integer> key = new Tuple<String, Integer>(nodeName, remoteOid);
Tuple<Subscriber<?>, DObject> bits = _proxies.remove(key);
if (bits == null) {
log.warning("Requested to clear unknown proxy [key=" + key + "].");
return;
@@ -807,7 +807,7 @@ public abstract class PeerManager
_nodes = _noderepo.loadNodes();
}
@Override
public void handleSuccess() {
public void handleSuccess () {
for (NodeRecord record : _nodes) {
if (record.nodeName.equals(_nodeName)) {
continue;
@@ -1202,7 +1202,7 @@ public abstract class PeerManager
protected String _nodeName, _sharedSecret;
protected NodeRecord _self;
protected NodeObject _nodeobj;
protected Map<String,PeerNode> _peers = Maps.newHashMap();
protected Map<String, PeerNode> _peers = Maps.newHashMap();
/** Used to resolve dependencies in unserialized {@link NodeAction} instances. */
protected Injector _injector;
@@ -1211,7 +1211,8 @@ public abstract class PeerManager
protected ArrayIntSet _suboids = new ArrayIntSet();
/** Contains a mapping of proxied objects to subscriber instances. */
protected Map<Tuple<String,Integer>,Tuple<Subscriber<?>,DObject>> _proxies = Maps.newHashMap();
protected Map<Tuple<String, Integer>, Tuple<Subscriber<?>, DObject>> _proxies =
Maps.newHashMap();
/** Our stale cache observers. */
protected Map<String, ObserverList<StaleCacheObserver>> _cacheobs = Maps.newHashMap();
@@ -77,7 +77,7 @@ public class NodeRecord extends PersistentRecord
/** Increment this value if you modify the definition of this persistent
* object in a way that will result in a change to its SQL counterpart. */
public static final int SCHEMA_VERSION = 1;
/** The unique name assigned to this node. */
@Id
@Column(name="NODE_NAME", length=64)
@@ -55,7 +55,7 @@ public abstract class Authenticator
invoker.postUnit(new Invoker.Unit("authenticateConnection") {
@Override
public boolean invoke() {
public boolean invoke () {
try {
processAuthentication(conn, rsp);
} catch (Exception e) { // Persistence or Runtime
@@ -32,7 +32,7 @@ import com.threerings.presents.net.AuthRequest;
public interface ClientFactory
{
/** The default client factory. */
public static ClientFactory DEFAULT = new ClientFactory () {
public static ClientFactory DEFAULT = new ClientFactory() {
public Class<? extends PresentsClient> getClientClass (AuthRequest areq) {
return PresentsClient.class;
}
@@ -42,7 +42,10 @@ import com.threerings.presents.data.ClientObject;
import com.threerings.presents.net.AuthRequest;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.Credentials;
import com.threerings.presents.server.net.*;
import com.threerings.presents.server.net.AuthingConnection;
import com.threerings.presents.server.net.Connection;
import com.threerings.presents.server.net.ConnectionManager;
import com.threerings.presents.server.net.ConnectionObserver;
import static com.threerings.presents.Log.log;
@@ -323,8 +326,8 @@ public class ClientManager
}
/**
* Renames a currently connected client from <code>oldname</code> to <code>newname</code>
*
* Renames a currently connected client from <code>oldname</code> to <code>newname</code>.
*
* @return true if the client was found and renamed.
*/
protected boolean renameClientObject (Name oldname, Name newname)
@@ -548,16 +551,16 @@ public class ClientManager
protected Injector _injector;
/** A mapping from auth username to client instances. */
protected Map<Name,PresentsClient> _usermap = Maps.newHashMap();
protected Map<Name, PresentsClient> _usermap = Maps.newHashMap();
/** A mapping from connections to client instances. */
protected Map<Connection,PresentsClient> _conmap = Maps.newHashMap();
protected Map<Connection, PresentsClient> _conmap = Maps.newHashMap();
/** A mapping from usernames to client object instances. */
protected Map<Name,ClientObject> _objmap = Maps.newHashMap();
protected Map<Name, ClientObject> _objmap = Maps.newHashMap();
/** A mapping of pending client resolvers. */
protected Map<Name,ClientResolver> _penders = Maps.newHashMap();
protected Map<Name, ClientResolver> _penders = Maps.newHashMap();
/** Lets us know what sort of client classes to use. */
protected ClientFactory _factory = ClientFactory.DEFAULT;