Extract BodyObject location into a separate service that can be customized by
extending systems and depended upon by services that need to lookup bodies. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5212 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -34,7 +34,6 @@ import com.threerings.util.TimeUtil;
|
|||||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
import com.threerings.presents.dobj.DObjectManager;
|
|
||||||
|
|
||||||
import com.threerings.presents.server.InvocationException;
|
import com.threerings.presents.server.InvocationException;
|
||||||
import com.threerings.presents.server.InvocationManager;
|
import com.threerings.presents.server.InvocationManager;
|
||||||
@@ -44,7 +43,9 @@ import com.threerings.crowd.data.BodyObject;
|
|||||||
import com.threerings.crowd.data.CrowdCodes;
|
import com.threerings.crowd.data.CrowdCodes;
|
||||||
import com.threerings.crowd.data.OccupantInfo;
|
import com.threerings.crowd.data.OccupantInfo;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
|
import com.threerings.crowd.server.BodyLocator;
|
||||||
import com.threerings.crowd.server.CrowdServer;
|
import com.threerings.crowd.server.CrowdServer;
|
||||||
|
import com.threerings.crowd.server.PlaceRegistry;
|
||||||
|
|
||||||
import com.threerings.crowd.chat.client.ChatService.TellListener;
|
import com.threerings.crowd.chat.client.ChatService.TellListener;
|
||||||
import com.threerings.crowd.chat.client.ChatService;
|
import com.threerings.crowd.chat.client.ChatService;
|
||||||
@@ -140,7 +141,7 @@ public class ChatProvider
|
|||||||
|
|
||||||
// inform the auto-responder if needed
|
// inform the auto-responder if needed
|
||||||
BodyObject targobj;
|
BodyObject targobj;
|
||||||
if (_autoRespond != null && (targobj = CrowdServer.lookupBody(target)) != null) {
|
if (_autoRespond != null && (targobj = _locator.lookupBody(target)) != null) {
|
||||||
_autoRespond.sentTell(source, targobj, message);
|
_autoRespond.sentTell(source, targobj, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,9 +186,8 @@ public class ChatProvider
|
|||||||
broadcastTo(_broadcastObject, from, bundle, msg, attention);
|
broadcastTo(_broadcastObject, from, bundle, msg, attention);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Iterator iter = CrowdServer.plreg.enumeratePlaces();
|
for (Iterator<PlaceObject> iter = _plreg.enumeratePlaces(); iter.hasNext(); ) {
|
||||||
while (iter.hasNext()) {
|
PlaceObject plobj = iter.next();
|
||||||
PlaceObject plobj = (PlaceObject)iter.next();
|
|
||||||
if (plobj.shouldBroadcast()) {
|
if (plobj.shouldBroadcast()) {
|
||||||
broadcastTo(plobj, from, bundle, msg, attention);
|
broadcastTo(plobj, from, bundle, msg, attention);
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ public class ChatProvider
|
|||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
// make sure the target user is online
|
// make sure the target user is online
|
||||||
BodyObject tobj = CrowdServer.lookupBody(target);
|
BodyObject tobj = _locator.lookupBody(target);
|
||||||
if (tobj == null) {
|
if (tobj == null) {
|
||||||
// if we have a forwarder configured, try forwarding the tell
|
// if we have a forwarder configured, try forwarding the tell
|
||||||
if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
|
if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
|
||||||
@@ -277,6 +277,12 @@ public class ChatProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Provides access to place managers. */
|
||||||
|
@Inject protected PlaceRegistry _plreg;
|
||||||
|
|
||||||
|
/** Used to look up body objects by name. */
|
||||||
|
@Inject protected BodyLocator _locator;
|
||||||
|
|
||||||
/** Generates auto-responses to tells. May be null. */
|
/** Generates auto-responses to tells. May be null. */
|
||||||
protected TellAutoResponder _autoRespond;
|
protected TellAutoResponder _autoRespond;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
|
import com.threerings.presents.annotation.EventThread;
|
||||||
|
import com.threerings.presents.server.ClientManager;
|
||||||
|
|
||||||
|
import com.threerings.crowd.data.BodyObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to lookup {@link BodyObject} instances by name.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BodyLocator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the body object for the user with the specified visible name, or null if they are
|
||||||
|
* not online.
|
||||||
|
*/
|
||||||
|
@EventThread
|
||||||
|
public BodyObject lookupBody (Name visibleName)
|
||||||
|
{
|
||||||
|
// by default visibleName is username
|
||||||
|
return (BodyObject)_clmgr.getClientObject(visibleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject protected ClientManager _clmgr;
|
||||||
|
}
|
||||||
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
package com.threerings.crowd.server;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
@@ -31,7 +29,6 @@ import com.samskivert.util.Invoker;
|
|||||||
|
|
||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
import com.threerings.presents.dobj.RootDObjectManager;
|
|
||||||
import com.threerings.presents.net.AuthRequest;
|
import com.threerings.presents.net.AuthRequest;
|
||||||
import com.threerings.presents.server.ClientFactory;
|
import com.threerings.presents.server.ClientFactory;
|
||||||
import com.threerings.presents.server.ClientManager;
|
import com.threerings.presents.server.ClientManager;
|
||||||
@@ -120,33 +117,6 @@ public class CrowdServer extends PresentsServer
|
|||||||
|
|
||||||
// configure the place registry with the injector
|
// configure the place registry with the injector
|
||||||
_plreg.setInjector(injector);
|
_plreg.setInjector(injector);
|
||||||
|
|
||||||
// create our body locator
|
|
||||||
_lookup = createBodyLocator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow derived instances to create a custom {@link BodyLocator}. If the system opts not to
|
|
||||||
* use {@link BodyObject#username} as a user's visible name, it will need to provide a custom
|
|
||||||
* {@link BodyLocator}.
|
|
||||||
*/
|
|
||||||
protected BodyLocator createBodyLocator ()
|
|
||||||
{
|
|
||||||
return new BodyLocator() {
|
|
||||||
public BodyObject get (Name visibleName) {
|
|
||||||
// by default visibleName is username
|
|
||||||
return (BodyObject)_clmgr.getClientObject(visibleName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up the {@link BodyObject} for the user with the specified visible name, returns null
|
|
||||||
* if they are not online. This should only be called from the dobjmgr thread.
|
|
||||||
*/
|
|
||||||
public static BodyObject lookupBody (Name visibleName)
|
|
||||||
{
|
|
||||||
return _lookup.get(visibleName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
@@ -161,15 +131,6 @@ public class CrowdServer extends PresentsServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An interface that allows server extensions to reconfigure the body lookup process. See
|
|
||||||
* {@link #lookupBody}, {@link #createBodyLocator}. */
|
|
||||||
protected static interface BodyLocator
|
|
||||||
{
|
|
||||||
/** Returns the body object for the user with the specified visible name, or null if they
|
|
||||||
* are not online. This will only be called from the dobjmgr thread. */
|
|
||||||
public BodyObject get (Name visibleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Handles the creation and tracking of place managers. */
|
/** Handles the creation and tracking of place managers. */
|
||||||
@Inject protected PlaceRegistry _plreg;
|
@Inject protected PlaceRegistry _plreg;
|
||||||
|
|
||||||
@@ -182,9 +143,6 @@ public class CrowdServer extends PresentsServer
|
|||||||
/** Provides chat-related invocation services. */
|
/** Provides chat-related invocation services. */
|
||||||
@Inject protected ChatProvider _chatprov;
|
@Inject protected ChatProvider _chatprov;
|
||||||
|
|
||||||
/** Used to look up {@link BodyObject} instance for online users. See {@link #lookupBody}. */
|
|
||||||
protected static BodyLocator _lookup;
|
|
||||||
|
|
||||||
/** The config key for our list of invocation provider mappings. */
|
/** The config key for our list of invocation provider mappings. */
|
||||||
protected final static String PROVIDERS_KEY = "providers";
|
protected final static String PROVIDERS_KEY = "providers";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import com.threerings.crowd.data.Place;
|
|||||||
import com.threerings.crowd.data.PlaceConfig;
|
import com.threerings.crowd.data.PlaceConfig;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
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.SpeakDispatcher;
|
||||||
import com.threerings.crowd.chat.server.SpeakHandler;
|
import com.threerings.crowd.chat.server.SpeakHandler;
|
||||||
|
|
||||||
@@ -174,12 +173,13 @@ public class PlaceManager
|
|||||||
/**
|
/**
|
||||||
* Called by the place registry after creating this place manager.
|
* Called by the place registry after creating this place manager.
|
||||||
*/
|
*/
|
||||||
public void init (PlaceRegistry registry, InvocationManager invmgr,
|
public void init (PlaceRegistry registry, InvocationManager invmgr, RootDObjectManager omgr,
|
||||||
RootDObjectManager omgr, PlaceConfig config)
|
BodyLocator locator, PlaceConfig config)
|
||||||
{
|
{
|
||||||
_registry = registry;
|
_registry = registry;
|
||||||
_invmgr = invmgr;
|
_invmgr = invmgr;
|
||||||
_omgr = omgr;
|
_omgr = omgr;
|
||||||
|
_locator = locator;
|
||||||
_config = config;
|
_config = config;
|
||||||
|
|
||||||
// initialize our delegates
|
// initialize our delegates
|
||||||
@@ -246,7 +246,7 @@ public class PlaceManager
|
|||||||
// we usually want to create and register a speaker service instance that clients can use
|
// we usually want to create and register a speaker service instance that clients can use
|
||||||
// to speak in this place
|
// to speak in this place
|
||||||
if (shouldCreateSpeakService()) {
|
if (shouldCreateSpeakService()) {
|
||||||
plobj.setSpeakService((SpeakMarshaller)_invmgr.registerDispatcher(
|
plobj.setSpeakService(_invmgr.registerDispatcher(
|
||||||
new SpeakDispatcher(new SpeakHandler(plobj, this))));
|
new SpeakDispatcher(new SpeakHandler(plobj, this))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,6 +703,9 @@ public class PlaceManager
|
|||||||
/** A distributed object manager for doing dobj stuff. */
|
/** A distributed object manager for doing dobj stuff. */
|
||||||
protected RootDObjectManager _omgr;
|
protected RootDObjectManager _omgr;
|
||||||
|
|
||||||
|
/** Used to look up body objects by name. */
|
||||||
|
protected BodyLocator _locator;
|
||||||
|
|
||||||
/** A reference to the place object that we manage. */
|
/** A reference to the place object that we manage. */
|
||||||
protected PlaceObject _plobj;
|
protected PlaceObject _plobj;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import com.threerings.presents.server.InvocationException;
|
|||||||
import com.threerings.presents.server.InvocationManager;
|
import com.threerings.presents.server.InvocationManager;
|
||||||
import com.threerings.presents.server.ShutdownManager;
|
import com.threerings.presents.server.ShutdownManager;
|
||||||
|
|
||||||
import com.threerings.crowd.data.CrowdCodes;
|
|
||||||
import com.threerings.crowd.data.Place;
|
import com.threerings.crowd.data.Place;
|
||||||
import com.threerings.crowd.data.PlaceConfig;
|
import com.threerings.crowd.data.PlaceConfig;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
@@ -202,7 +201,7 @@ public class PlaceRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
// let the pmgr know about us and its configuration
|
// let the pmgr know about us and its configuration
|
||||||
pmgr.init(this, _invmgr, _omgr, config);
|
pmgr.init(this, _invmgr, _omgr, _locator, config);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warning(e);
|
log.warning(e);
|
||||||
@@ -274,6 +273,9 @@ public class PlaceRegistry
|
|||||||
/** The distributed object manager with which we operate. */
|
/** The distributed object manager with which we operate. */
|
||||||
@Inject protected RootDObjectManager _omgr;
|
@Inject protected RootDObjectManager _omgr;
|
||||||
|
|
||||||
|
/** Used to look body objects up by name. */
|
||||||
|
@Inject protected BodyLocator _locator;
|
||||||
|
|
||||||
/** We use this to inject dependencies into place managers that we create. */
|
/** We use this to inject dependencies into place managers that we create. */
|
||||||
protected Injector _injector;
|
protected Injector _injector;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user