From 5d544fdd55b6943ef4a9fb335f10923b66a5b6cc Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 9 May 2008 11:47:38 +0000 Subject: [PATCH] Use Maps and Lists. Unglommed imports. Having them separated into presents and crowd was intentional (with presents on top because it is more "generic"). We must resist Eclipse's desire to squish our imports together into one giant, hard to (visually) parse blob. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5060 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/crowd/server/PlaceManager.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index 2e4af286b..2cc55c470 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -21,26 +21,19 @@ package com.threerings.crowd.server; -import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.logging.Level; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + import com.samskivert.util.HashIntMap; import com.samskivert.util.Interval; import com.samskivert.util.MethodFinder; import com.samskivert.util.StringUtil; -import com.threerings.crowd.Log; -import com.threerings.crowd.chat.data.SpeakMarshaller; -import com.threerings.crowd.chat.server.SpeakDispatcher; -import com.threerings.crowd.chat.server.SpeakHandler; -import com.threerings.crowd.data.BodyObject; -import com.threerings.crowd.data.OccupantInfo; -import com.threerings.crowd.data.Place; -import com.threerings.crowd.data.PlaceConfig; -import com.threerings.crowd.data.PlaceObject; import com.threerings.presents.data.ClientObject; import com.threerings.presents.dobj.AccessController; import com.threerings.presents.dobj.DObject; @@ -58,6 +51,17 @@ import com.threerings.presents.dobj.SetAdapter; import com.threerings.presents.server.InvocationManager; import com.threerings.presents.server.PresentsDObjectMgr; +import com.threerings.crowd.Log; +import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.data.OccupantInfo; +import com.threerings.crowd.data.Place; +import com.threerings.crowd.data.PlaceConfig; +import com.threerings.crowd.data.PlaceObject; + +import com.threerings.crowd.chat.data.SpeakMarshaller; +import com.threerings.crowd.chat.server.SpeakDispatcher; +import com.threerings.crowd.chat.server.SpeakHandler; + /** * The place manager is the server-side entity that handles all place-related interaction. It * subscribes to the place object and reacts to message and other events. Behavior specific to a @@ -76,7 +80,6 @@ import com.threerings.presents.server.PresentsDObjectMgr; public class PlaceManager implements MessageListener, OidListListener, ObjectDeathListener, SpeakHandler.SpeakerValidator { - /** * An interface used to allow the registration of standard message handlers to be invoked by * the place manager when particular types of message events are received. @@ -191,7 +194,7 @@ public class PlaceManager public void addDelegate (PlaceManagerDelegate delegate) { if (_delegates == null) { - _delegates = new ArrayList(); + _delegates = Lists.newArrayList(); } delegate.setPlaceManager(this); _delegates.add(delegate); @@ -327,7 +330,7 @@ public class PlaceManager { // create our handler map if necessary if (_msghandlers == null) { - _msghandlers = new HashMap(); + _msghandlers = Maps.newHashMap(); } _msghandlers.put(name, handler); } @@ -342,8 +345,7 @@ public class PlaceManager } } - // If the message is directed at us, see if it's a request for - // a method invocation + // If the message is directed at us, see if it's a request for a method invocation if (event.isPrivate()) { // aka if (event instanceof ServerMessageEvent) // the first argument should be the client object of the caller or null if it is // a server-originated event @@ -357,7 +359,7 @@ public class PlaceManager nargs[0] = source; System.arraycopy(args, 0, nargs, 1, args.length); } - + // Lazily create our dispatcher now that it's actually getting a message if (_dispatcher == null) { if (!_dispatcherFinders.containsKey(getClass())) { @@ -595,7 +597,7 @@ public class PlaceManager { return (_plobj.occupants.size() == 0); } - + /** * Called when a body's occupant info is updated. */ @@ -702,10 +704,10 @@ public class PlaceManager protected PlaceConfig _config; /** Message handlers are used to process message events. */ - protected HashMap _msghandlers; + protected Map _msghandlers; /** A list of the delegates in use by this manager. */ - protected ArrayList _delegates; + protected List _delegates; /** Used to keep a canonical copy of the occupant info records. */ protected HashIntMap _occInfo = new HashIntMap(); @@ -714,14 +716,11 @@ public class PlaceManager * idility, or null if no interval is currently registered. */ protected Interval _shutdownInterval; - /** - * Maps from a PlaceManager subclass to a MethodFinder for it. When there are many many - * instances of a PlaceManager in existence, having a MethodFinder instance for each gets - * quite expensive. - */ - protected static Map, MethodFinder> _dispatcherFinders = - new HashMap, MethodFinder>(); - /** Used to do method lookup magic when we receive message events. */ protected DynamicListener _dispatcher; + + /** Maps from a PlaceManager subclass to a MethodFinder for it. When there are many many + * instances of a PlaceManager in existence, having a MethodFinder instance for each gets quite + * expensive. */ + protected static Map, MethodFinder> _dispatcherFinders = Maps.newHashMap(); }