I decided to go hog wild and clean up all the type use in Presents which

required some serious bending and folding of the generic type system, but for
the most part we managed to avoid any mutilating. The gendobj task now
generates properly typed "addToXXX" and "updateXXX" DSet methods based on the
parameterized type of the DSet. This might cause unrecompiled code to break,
but I don't think there are many cases in the base toolkit where people call
DSet adders or updaters. We'll see and I'll add backwards compatibility
versions for cases where we need them to support GG games (everything else we
can just recompile).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4245 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-07-05 00:55:05 +00:00
parent 94b79826d4
commit 8afd0316ec
27 changed files with 269 additions and 212 deletions
@@ -229,7 +229,9 @@ public class ClientManager
// request that the appropriate client object be created by the
// dobject manager which starts the whole business off
PresentsServer.omgr.createObject(clr.getClientObjectClass(), clr);
@SuppressWarnings("unchecked") Class<ClientObject> cclass =
(Class<ClientObject>)clr.getClientObjectClass();
PresentsServer.omgr.createObject(cclass, clr);
} catch (Exception e) {
// let the listener know that we're hosed
@@ -64,7 +64,7 @@ public class ClientResolver extends Invoker.Unit
* Returns the {@link ClientObject} derived class that should be
* created to kick off the resolution process.
*/
public Class getClientObjectClass ()
public Class<? extends ClientObject> getClientObjectClass ()
{
return ClientObject.class;
}
@@ -65,11 +65,12 @@ import com.threerings.presents.dobj.Subscriber;
* the client.
*/
public class InvocationManager
implements Subscriber, EventListener
implements Subscriber<DObject>, EventListener
{
/** The list of services that are to be provided to clients at boot
* time. Don't mess with this list! */
public StreamableArrayList bootlist = new StreamableArrayList();
public StreamableArrayList<InvocationMarshaller> bootlist =
new StreamableArrayList<InvocationMarshaller>();
/**
* Constructs an invocation manager which will use the supplied
@@ -174,8 +175,7 @@ public class InvocationManager
// let any early registered marshallers know about our invoid
while (_lateInitQueue.size() > 0) {
InvocationMarshaller marsh = (InvocationMarshaller)
_lateInitQueue.remove(0);
InvocationMarshaller marsh = _lateInitQueue.remove(0);
marsh.setInvocationOid(_invoid);
}
@@ -222,8 +222,7 @@ public class InvocationManager
}
// look up the dispatcher
InvocationDispatcher disp = (InvocationDispatcher)
_dispatchers.get(invCode);
InvocationDispatcher disp = _dispatchers.get(invCode);
if (disp == null) {
Log.info("Received invocation request but dispatcher " +
"registration was already cleared [code=" + invCode +
@@ -298,8 +297,8 @@ public class InvocationManager
}
// debugging action...
protected static final LRUHashMap _recentRegServices =
new LRUHashMap(10000);
protected static final LRUHashMap<Integer,String> _recentRegServices =
new LRUHashMap<Integer,String>(10000);
/** The distributed object manager with which we're working. */
protected RootDObjectManager _omgr;
@@ -312,12 +311,14 @@ public class InvocationManager
protected int _invCode;
/** A table of invocation dispatchers each mapped by a unique code. */
protected HashIntMap _dispatchers = new HashIntMap();
protected HashIntMap<InvocationDispatcher> _dispatchers =
new HashIntMap<InvocationDispatcher>();
/** Used to keep track of marshallers registered before we had our
* invocation object so that we can fill their invocation id in
* belatedly. */
protected ArrayList _lateInitQueue = new ArrayList();
protected ArrayList<InvocationMarshaller> _lateInitQueue =
new ArrayList<InvocationMarshaller>();
/** The text that is appended to the procedure name when automatically
* generating a failure response. */
@@ -764,7 +764,7 @@ public class PresentsClient
// documentation inherited from interface
public void objectAvailable (DObject object)
{
if (postMessage(new ObjectResponse(object))) {
if (postMessage(new ObjectResponse<DObject>(object))) {
// make a note of this new subscription
mapSubscrip(object);
} else {
@@ -196,7 +196,7 @@ public class PresentsDObjectMgr
*/
public DObject getObject (int oid)
{
return (DObject)_objects.get(oid);
return _objects.get(oid);
}
/**
@@ -324,7 +324,7 @@ public class PresentsDObjectMgr
int ecount = events.size();
// look up the target object
DObject target = (DObject)_objects.get(event.getTargetOid());
DObject target = _objects.get(event.getTargetOid());
if (target == null) {
Log.debug("Compound event target no longer exists " +
"[event=" + event + "].");
@@ -357,7 +357,7 @@ public class PresentsDObjectMgr
protected void processEvent (DEvent event)
{
// look up the target object
DObject target = (DObject)_objects.get(event.getTargetOid());
DObject target = _objects.get(event.getTargetOid());
if (target == null) {
Log.debug("Event target no longer exists " +
"[event=" + event + "].");
@@ -491,7 +491,7 @@ public class PresentsDObjectMgr
}
Reference ref = refs[i];
DObject reffer = (DObject)_objects.get(ref.reffingOid);
DObject reffer = _objects.get(ref.reffingOid);
// ensure that the referencing object is still around
if (reffer != null) {
@@ -857,7 +857,7 @@ public class PresentsDObjectMgr
throws ObjectAccessException
{
// look up the target object
T obj = (T)_objects.get(_oid);
@SuppressWarnings("unchecked") T obj = (T)_objects.get(_oid);
// if we're unsubscribing, take care of that and get on out
if (_action == UNSUBSCRIBE) {
@@ -985,7 +985,7 @@ public class PresentsDObjectMgr
protected boolean _running = true;
/** The event queue via which all events are processed. */
protected Queue _evqueue = new Queue();
protected Queue<Object> _evqueue = new Queue<Object>();
/** The managed distributed objects table. */
protected HashIntMap<DObject> _objects = new HashIntMap<DObject>();
@@ -112,7 +112,8 @@ public class PresentsServer
SignalManager.registerSignalHandler(SignalManager.SIGHUP, this);
// create our list of shutdowners
_downers = new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
_downers = new ObserverList<Shutdowner>(
ObserverList.SAFE_IN_ORDER_NOTIFY);
// create our distributed object manager
omgr = createDObjectManager();
@@ -258,7 +259,7 @@ public class PresentsServer
report.append(max/1024).append("k max\n");
for (int ii = 0; ii < _reporters.size(); ii++) {
Reporter rptr = (Reporter)_reporters.get(ii);
Reporter rptr = _reporters.get(ii);
try {
rptr.appendReport(report, now, sinceLast, reset);
} catch (Throwable t) {
@@ -308,7 +309,7 @@ public class PresentsServer
*/
public void shutdown ()
{
ObserverList downers = _downers;
ObserverList<Shutdowner> downers = _downers;
if (downers == null) {
Log.warning("Refusing repeat shutdown request.");
return;
@@ -322,9 +323,9 @@ public class PresentsServer
}
// shut down all shutdown participants
downers.apply(new ObserverList.ObserverOp() {
public boolean apply (Object observer) {
((Shutdowner)observer).shutdown();
downers.apply(new ObserverList.ObserverOp<Shutdowner>() {
public boolean apply (Shutdowner downer) {
downer.shutdown();
return true;
}
});
@@ -399,10 +400,10 @@ public class PresentsServer
protected static long _lastReportStamp = _serverStartTime;
/** Used to generate "state of server" reports. */
protected static ArrayList _reporters = new ArrayList();
protected static ArrayList<Reporter> _reporters = new ArrayList<Reporter>();
/** A list of shutdown participants. */
protected static ObserverList _downers;;
protected static ObserverList<Shutdowner> _downers;;
/** The frequency with which we generate "state of server" reports. */
protected static final long REPORT_INTERVAL = 15 * 60 * 1000L;
@@ -69,10 +69,11 @@ public class TimeBaseProvider
* base object is created or if the creation fails.
*/
public static void createTimeBase (
final String timeBase, final ResultListener resl)
final String timeBase, final ResultListener<TimeBaseObject> resl)
{
_omgr.createObject(TimeBaseObject.class, new Subscriber () {
public void objectAvailable (DObject object) {
_omgr.createObject(TimeBaseObject.class,
new Subscriber<TimeBaseObject> () {
public void objectAvailable (TimeBaseObject object) {
// stuff it into our table
_timeBases.put(timeBase, object);
// and notify the listener
@@ -95,7 +96,7 @@ public class TimeBaseProvider
*/
public static TimeBaseObject getTimeBase (String timeBase)
{
return (TimeBaseObject)_timeBases.get(timeBase);
return _timeBases.get(timeBase);
}
/**
@@ -116,7 +117,8 @@ public class TimeBaseProvider
}
/** Used to keep track of our time base objects. */
protected static HashMap _timeBases = new HashMap();
protected static HashMap<String,TimeBaseObject> _timeBases =
new HashMap<String,TimeBaseObject>();
/** The invocation manager with which we interoperate. */
protected static InvocationManager _invmgr;
@@ -194,7 +194,7 @@ public class ConnectionManager extends LoopingThread
* Called by the authenticator to indicate that a connection was
* successfully authenticated.
*/
public void connectionDidAuthenticate (Connection conn)
public void connectionDidAuthenticate (AuthingConnection conn)
{
// slap this sucker onto the authenticated connections queue
_authq.append(conn);
@@ -360,7 +360,7 @@ public class ConnectionManager extends LoopingThread
// close any connections that have been queued up to die
Connection dconn;
while ((dconn = (Connection)_deathq.getNonBlocking()) != null) {
while ((dconn = _deathq.getNonBlocking()) != null) {
// it's possible that we caught an EOF trying to read from
// this connection even after it was queued up for death, so
// let's avoid trying to close it twice
@@ -396,10 +396,8 @@ public class ConnectionManager extends LoopingThread
}
// send any messages that are waiting on the outgoing queue
Object obj;
while ((obj = _outq.getNonBlocking()) != null) {
@SuppressWarnings("unchecked") Tuple<Connection,byte[]> tup =
(Tuple<Connection,byte[]>)obj;
Tuple<Connection,byte[]> tup;
while ((tup = _outq.getNonBlocking()) != null) {
Connection conn = tup.left;
// if an overflow queue exists for this client, go ahead and
@@ -423,7 +421,7 @@ public class ConnectionManager extends LoopingThread
// check for connections that have completed authentication
AuthingConnection conn;
while ((conn = (AuthingConnection)_authq.getNonBlocking()) != null) {
while ((conn = _authq.getNonBlocking()) != null) {
try {
// construct a new running connection to handle this
// connections network traffic from here on out
@@ -893,10 +891,11 @@ public class ConnectionManager extends LoopingThread
protected HashMap<SelectionKey,NetEventHandler> _handlers =
new HashMap<SelectionKey,NetEventHandler>();
protected Queue _deathq = new Queue();
protected Queue _authq = new Queue();
protected Queue<Connection> _deathq = new Queue<Connection>();
protected Queue<AuthingConnection> _authq = new Queue<AuthingConnection>();
protected Queue _outq = new Queue();
protected Queue<Tuple<Connection,byte[]>> _outq =
new Queue<Tuple<Connection,byte[]>>();
protected FramingOutputStream _framer;
protected ByteBuffer _outbuf = ByteBuffer.allocateDirect(64 * 1024);