Modify PresentsClient and ClientResolver creation so that we can inject
dependencies into both. Moved the legacy statics into CrowdServer so that at least Presents can be pure (we should probably eventually move them into BangServer and PiracyServer and fix everything else). Added some useful manager references to PlaceManager delegate (_omgr, _invmgr) that handle the majority of their service needs. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5170 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,16 +27,20 @@ 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;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
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.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.ClientResolver;
|
import com.threerings.presents.server.ClientResolver;
|
||||||
import com.threerings.presents.server.InvocationManager;
|
import com.threerings.presents.server.InvocationManager;
|
||||||
import com.threerings.presents.server.PresentsClient;
|
import com.threerings.presents.server.PresentsClient;
|
||||||
|
import com.threerings.presents.server.PresentsDObjectMgr;
|
||||||
import com.threerings.presents.server.PresentsServer;
|
import com.threerings.presents.server.PresentsServer;
|
||||||
|
import com.threerings.presents.server.net.ConnectionManager;
|
||||||
|
|
||||||
import com.threerings.crowd.chat.server.ChatProvider;
|
import com.threerings.crowd.chat.server.ChatProvider;
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
@@ -58,18 +62,33 @@ public class CrowdServer extends PresentsServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The place registry. */
|
/** OBSOLETE! Don't use me. */
|
||||||
public static PlaceRegistry plreg;
|
public static PlaceRegistry plreg;
|
||||||
|
|
||||||
/** Our chat provider. */
|
/** OBSOLETE! Don't use me. */
|
||||||
public static ChatProvider chatprov;
|
public static ChatProvider chatprov;
|
||||||
|
|
||||||
/** Our body manager. */
|
/** OBSOLETE! Don't use me. */
|
||||||
public static BodyManager bodyman;
|
public static BodyManager bodyman;
|
||||||
|
|
||||||
/** Our location manager. */
|
/** OBSOLETE! Don't use me. */
|
||||||
public static LocationManager locman;
|
public static LocationManager locman;
|
||||||
|
|
||||||
|
/** OBSOLETE! Don't use me. */
|
||||||
|
public static ConnectionManager conmgr;
|
||||||
|
|
||||||
|
/** OBSOLETE! Don't use me. */
|
||||||
|
public static ClientManager clmgr;
|
||||||
|
|
||||||
|
/** OBSOLETE! Don't use me. */
|
||||||
|
public static PresentsDObjectMgr omgr;
|
||||||
|
|
||||||
|
/** OBSOLETE! Don't use me. */
|
||||||
|
public static InvocationManager invmgr;
|
||||||
|
|
||||||
|
/** OBSOLETE! Don't use me. */
|
||||||
|
public static Invoker invoker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all of the server services and prepares for operation.
|
* Initializes all of the server services and prepares for operation.
|
||||||
*/
|
*/
|
||||||
@@ -79,18 +98,23 @@ public class CrowdServer extends PresentsServer
|
|||||||
super.init(injector);
|
super.init(injector);
|
||||||
|
|
||||||
// LEGACY: set up our legacy static references
|
// LEGACY: set up our legacy static references
|
||||||
|
conmgr = _conmgr;
|
||||||
|
clmgr = _clmgr;
|
||||||
|
omgr = _omgr;
|
||||||
|
invmgr = _invmgr;
|
||||||
|
invoker = _invoker;
|
||||||
plreg = _plreg;
|
plreg = _plreg;
|
||||||
chatprov = _chatprov;
|
chatprov = _chatprov;
|
||||||
bodyman = _bodyman;
|
bodyman = _bodyman;
|
||||||
locman = _locman;
|
locman = _locman;
|
||||||
|
|
||||||
// configure the client manager to use our bits
|
// configure the client manager to use our bits
|
||||||
clmgr.setClientFactory(new ClientFactory() {
|
_clmgr.setClientFactory(new ClientFactory() {
|
||||||
public PresentsClient createClient (AuthRequest areq) {
|
public Class<? extends PresentsClient> getClientClass (AuthRequest areq) {
|
||||||
return new CrowdClient();
|
return CrowdClient.class;
|
||||||
}
|
}
|
||||||
public ClientResolver createClientResolver (Name username) {
|
public Class<? extends ClientResolver> getClientResolverClass (Name username) {
|
||||||
return new CrowdClientResolver();
|
return CrowdClientResolver.class;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -111,21 +135,11 @@ public class CrowdServer extends PresentsServer
|
|||||||
return new BodyLocator() {
|
return new BodyLocator() {
|
||||||
public BodyObject get (Name visibleName) {
|
public BodyObject get (Name visibleName) {
|
||||||
// by default visibleName is username
|
// by default visibleName is username
|
||||||
return (BodyObject)clmgr.getClientObject(visibleName);
|
return (BodyObject)_clmgr.getClientObject(visibleName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enumerates the body objects for all active users on the server. This should only be called
|
|
||||||
* from the dobjmgr thread. The caller had best be certain they know what they're doing, since
|
|
||||||
* this should only be necessary for use in rather special circumstances.
|
|
||||||
*/
|
|
||||||
public static Iterator enumerateBodies ()
|
|
||||||
{
|
|
||||||
return clmgr.enumerateClientObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up the {@link BodyObject} for the user with the specified visible name, returns null
|
* 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.
|
* if they are not online. This should only be called from the dobjmgr thread.
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public class PlaceManager
|
|||||||
if (_delegates == null) {
|
if (_delegates == null) {
|
||||||
_delegates = Lists.newArrayList();
|
_delegates = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
delegate.setPlaceManager(this);
|
delegate.init(this, _omgr, _invmgr);
|
||||||
_delegates.add(delegate);
|
_delegates.add(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.crowd.server;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
|
import com.threerings.presents.dobj.RootDObjectManager;
|
||||||
|
import com.threerings.presents.server.InvocationManager;
|
||||||
|
|
||||||
import com.threerings.crowd.data.OccupantInfo;
|
import com.threerings.crowd.data.OccupantInfo;
|
||||||
import com.threerings.crowd.data.PlaceConfig;
|
import com.threerings.crowd.data.PlaceConfig;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
@@ -41,9 +44,11 @@ public class PlaceManagerDelegate
|
|||||||
* Called by the place manager when this delegate is registered with it. This will happen
|
* Called by the place manager when this delegate is registered with it. This will happen
|
||||||
* before any calls to {@link #didInit}, etc.
|
* before any calls to {@link #didInit}, etc.
|
||||||
*/
|
*/
|
||||||
public void setPlaceManager (PlaceManager plmgr)
|
public void init (PlaceManager plmgr, RootDObjectManager omgr, InvocationManager invmgr)
|
||||||
{
|
{
|
||||||
_plmgr = plmgr;
|
_plmgr = plmgr;
|
||||||
|
_omgr = omgr;
|
||||||
|
_invmgr = invmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,4 +110,10 @@ public class PlaceManagerDelegate
|
|||||||
|
|
||||||
/** A reference to the manager for which we are delegating. */
|
/** A reference to the manager for which we are delegating. */
|
||||||
protected PlaceManager _plmgr;
|
protected PlaceManager _plmgr;
|
||||||
|
|
||||||
|
/** A reference to our distributed object manager. */
|
||||||
|
protected RootDObjectManager _omgr;
|
||||||
|
|
||||||
|
/** A reference to our invocation manager. */
|
||||||
|
protected InvocationManager _invmgr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
package com.threerings.presents.peer.server;
|
package com.threerings.presents.peer.server;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.samskivert.util.Throttle;
|
import com.samskivert.util.Throttle;
|
||||||
|
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
@@ -41,7 +42,7 @@ public class PeerClient extends PresentsClient
|
|||||||
* Creates a peer client and provides it with a reference to the peer
|
* Creates a peer client and provides it with a reference to the peer
|
||||||
* manager. This is only done by the {@link PeerClientFactory}.
|
* manager. This is only done by the {@link PeerClientFactory}.
|
||||||
*/
|
*/
|
||||||
protected PeerClient (PeerManager peermgr)
|
@Inject public PeerClient (PeerManager peermgr)
|
||||||
{
|
{
|
||||||
_peermgr = peermgr;
|
_peermgr = peermgr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,37 +31,35 @@ import com.threerings.presents.server.PresentsClient;
|
|||||||
import com.threerings.presents.peer.net.PeerCreds;
|
import com.threerings.presents.peer.net.PeerCreds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles resolution of peer servers and passes non-peer resolution requests
|
* Handles resolution of peer servers and passes non-peer resolution requests through to a normal
|
||||||
* through to a normal factory.
|
* factory.
|
||||||
*/
|
*/
|
||||||
public class PeerClientFactory implements ClientFactory
|
public class PeerClientFactory implements ClientFactory
|
||||||
{
|
{
|
||||||
public PeerClientFactory (PeerManager peermgr, ClientFactory delegate)
|
public PeerClientFactory (ClientFactory delegate)
|
||||||
{
|
{
|
||||||
_peermgr = peermgr;
|
|
||||||
_delegate = delegate;
|
_delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface ClientFactory
|
// documentation inherited from interface ClientFactory
|
||||||
public PresentsClient createClient (AuthRequest areq)
|
public Class<? extends PresentsClient> getClientClass (AuthRequest areq)
|
||||||
{
|
{
|
||||||
if (areq.getCredentials() instanceof PeerCreds) {
|
if (areq.getCredentials() instanceof PeerCreds) {
|
||||||
return new PeerClient(_peermgr);
|
return PeerClient.class;
|
||||||
} else {
|
} else {
|
||||||
return _delegate.createClient(areq);
|
return _delegate.getClientClass(areq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface ClientFactory
|
// documentation inherited from interface ClientFactory
|
||||||
public ClientResolver createClientResolver (Name username)
|
public Class<? extends ClientResolver> getClientResolverClass (Name username)
|
||||||
{
|
{
|
||||||
if (username.toString().startsWith(PeerCreds.PEER_PREFIX)) {
|
if (username.toString().startsWith(PeerCreds.PEER_PREFIX)) {
|
||||||
return new PeerClientResolver();
|
return PeerClientResolver.class;
|
||||||
} else {
|
} else {
|
||||||
return _delegate.createClientResolver(username);
|
return _delegate.getClientResolverClass(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PeerManager _peermgr;
|
|
||||||
protected ClientFactory _delegate;
|
protected ClientFactory _delegate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public class PeerManager
|
|||||||
|
|
||||||
// wire ourselves into the server
|
// wire ourselves into the server
|
||||||
_conmgr.addChainedAuthenticator(new PeerAuthenticator(this));
|
_conmgr.addChainedAuthenticator(new PeerAuthenticator(this));
|
||||||
_clmgr.setClientFactory(new PeerClientFactory(this, _clmgr.getClientFactory()));
|
_clmgr.setClientFactory(new PeerClientFactory(_clmgr.getClientFactory()));
|
||||||
|
|
||||||
// create our node object
|
// create our node object
|
||||||
_nodeobj = _omgr.registerObject(createNodeObject());
|
_nodeobj = _omgr.registerObject(createNodeObject());
|
||||||
|
|||||||
@@ -27,29 +27,30 @@ import com.threerings.presents.data.ClientObject;
|
|||||||
import com.threerings.presents.net.AuthRequest;
|
import com.threerings.presents.net.AuthRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to create a {@link PresentsClient} instance to manage an authenticated
|
* Used to determine what type of {@link PresentsClient} to use to manage an authenticated client
|
||||||
* client.
|
* as well the type of {@link ClientResolver} to use when resolving clients' runtime data.
|
||||||
*/
|
*/
|
||||||
public interface ClientFactory
|
public interface ClientFactory
|
||||||
{
|
{
|
||||||
/** The default client factory. */
|
/** The default client factory. */
|
||||||
public static ClientFactory DEFAULT = new ClientFactory () {
|
public static ClientFactory DEFAULT = new ClientFactory () {
|
||||||
public PresentsClient createClient (AuthRequest areq) {
|
public Class<? extends PresentsClient> getClientClass (AuthRequest areq) {
|
||||||
return new PresentsClient();
|
return PresentsClient.class;
|
||||||
}
|
}
|
||||||
public ClientResolver createClientResolver (Name username) {
|
public Class<? extends ClientResolver> getClientResolverClass (Name username) {
|
||||||
return new ClientResolver();
|
return ClientResolver.class;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an uninitialized client instance for the client that has
|
* Returns the {@link PresentsClient} derived class to use for the session that authenticated
|
||||||
* authenticated using the supplied request.
|
* with the supplied request.
|
||||||
*/
|
*/
|
||||||
public PresentsClient createClient (AuthRequest areq);
|
public Class<? extends PresentsClient> getClientClass (AuthRequest areq);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests a resolver for the client identified by the specified username.
|
* Returns the {@link ClientResolver} derived class to use to resolve a client with the
|
||||||
|
* specified username.
|
||||||
*/
|
*/
|
||||||
public ClientResolver createClientResolver (Name username);
|
public Class <? extends ClientResolver> getClientResolverClass (Name username);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import java.util.Map;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import com.samskivert.util.Interval;
|
import com.samskivert.util.Interval;
|
||||||
@@ -112,6 +113,15 @@ public class ClientManager
|
|||||||
}.schedule(CLIENT_FLUSH_INTERVAL, true);
|
}.schedule(CLIENT_FLUSH_INTERVAL, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the injector we'll use to resolve dependencies for {@link PresentsClient}
|
||||||
|
* instances.
|
||||||
|
*/
|
||||||
|
public void setInjector (Injector injector)
|
||||||
|
{
|
||||||
|
_injector = injector;
|
||||||
|
}
|
||||||
|
|
||||||
// from interface ShutdownManager.Shutdowner
|
// from interface ShutdownManager.Shutdowner
|
||||||
public void shutdown ()
|
public void shutdown ()
|
||||||
{
|
{
|
||||||
@@ -261,7 +271,7 @@ public class ClientManager
|
|||||||
try {
|
try {
|
||||||
// create a client resolver instance which will create our client object, populate it
|
// create a client resolver instance which will create our client object, populate it
|
||||||
// and notify the listeners
|
// and notify the listeners
|
||||||
clr = _factory.createClientResolver(username);
|
clr = _injector.getInstance(_factory.getClientResolverClass(username));
|
||||||
clr.init(username);
|
clr.init(username);
|
||||||
clr.addResolutionListener(this);
|
clr.addResolutionListener(this);
|
||||||
clr.addResolutionListener(listener);
|
clr.addResolutionListener(listener);
|
||||||
@@ -368,8 +378,8 @@ public class ClientManager
|
|||||||
} else {
|
} else {
|
||||||
log.info("Session initiated [username=" + username + ", conn=" + conn + "].");
|
log.info("Session initiated [username=" + username + ", conn=" + conn + "].");
|
||||||
// create a new client and stick'em in the table
|
// create a new client and stick'em in the table
|
||||||
client = _factory.createClient(req);
|
client = _injector.getInstance(_factory.getClientClass(req));
|
||||||
client.startSession(this, req, conn, rsp.authdata);
|
client.startSession(req, conn, rsp.authdata);
|
||||||
|
|
||||||
// map their client instance
|
// map their client instance
|
||||||
synchronized (_usermap) {
|
synchronized (_usermap) {
|
||||||
@@ -534,6 +544,9 @@ public class ClientManager
|
|||||||
protected ClientOp _clop;
|
protected ClientOp _clop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Used to resolve dependencies in {@link PresentClient} instances that we create. */
|
||||||
|
protected Injector _injector;
|
||||||
|
|
||||||
/** A mapping from auth username to client instances. */
|
/** A mapping from auth username to client instances. */
|
||||||
protected Map<Name,PresentsClient> _usermap = Maps.newHashMap();
|
protected Map<Name,PresentsClient> _usermap = Maps.newHashMap();
|
||||||
|
|
||||||
@@ -546,7 +559,7 @@ public class ClientManager
|
|||||||
/** A mapping of pending client resolvers. */
|
/** A mapping of pending client resolvers. */
|
||||||
protected Map<Name,ClientResolver> _penders = Maps.newHashMap();
|
protected Map<Name,ClientResolver> _penders = Maps.newHashMap();
|
||||||
|
|
||||||
/** The client class in use. */
|
/** Lets us know what sort of client classes to use. */
|
||||||
protected ClientFactory _factory = ClientFactory.DEFAULT;
|
protected ClientFactory _factory = ClientFactory.DEFAULT;
|
||||||
|
|
||||||
/** Tracks registered {@link ClientObserver}s. */
|
/** Tracks registered {@link ClientObserver}s. */
|
||||||
|
|||||||
@@ -21,15 +21,20 @@
|
|||||||
|
|
||||||
package com.threerings.presents.server;
|
package com.threerings.presents.server;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import com.samskivert.util.Invoker;
|
import com.samskivert.util.Invoker;
|
||||||
import com.threerings.util.Name;
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
|
import com.threerings.presents.annotation.MainInvoker;
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.data.PermissionPolicy;
|
import com.threerings.presents.data.PermissionPolicy;
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
import com.threerings.presents.dobj.ObjectAccessException;
|
import com.threerings.presents.dobj.ObjectAccessException;
|
||||||
|
import com.threerings.presents.dobj.RootDObjectManager;
|
||||||
|
|
||||||
import static com.threerings.presents.Log.log;
|
import static com.threerings.presents.Log.log;
|
||||||
|
|
||||||
@@ -84,7 +89,7 @@ public class ClientResolver extends Invoker.Unit
|
|||||||
// we've got our object, so shunt ourselves over to the invoker thread to perform database
|
// we've got our object, so shunt ourselves over to the invoker thread to perform database
|
||||||
// loading
|
// loading
|
||||||
_clobj = object;
|
_clobj = object;
|
||||||
PresentsServer.invoker.postUnit(this);
|
_invoker.postUnit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
@@ -128,7 +133,7 @@ public class ClientResolver extends Invoker.Unit
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// destroy the dangling user object
|
// destroy the dangling user object
|
||||||
PresentsServer.omgr.destroyObject(_clobj.getOid());
|
_omgr.destroyObject(_clobj.getOid());
|
||||||
|
|
||||||
// let our listener know that we're hosed
|
// let our listener know that we're hosed
|
||||||
reportFailure(_failure);
|
reportFailure(_failure);
|
||||||
@@ -182,12 +187,14 @@ public class ClientResolver extends Invoker.Unit
|
|||||||
protected Name _username;
|
protected Name _username;
|
||||||
|
|
||||||
/** The entities to notify of success or failure. */
|
/** The entities to notify of success or failure. */
|
||||||
protected ArrayList<ClientResolutionListener> _listeners =
|
protected List<ClientResolutionListener> _listeners = Lists.newArrayList();
|
||||||
new ArrayList<ClientResolutionListener>();
|
|
||||||
|
|
||||||
/** The resolving client object. */
|
/** The resolving client object. */
|
||||||
protected ClientObject _clobj;
|
protected ClientObject _clobj;
|
||||||
|
|
||||||
/** A place to keep an exception around for a moment. */
|
/** A place to keep an exception around for a moment. */
|
||||||
protected Exception _failure;
|
protected Exception _failure;
|
||||||
|
|
||||||
|
@Inject @MainInvoker Invoker _invoker;
|
||||||
|
@Inject RootDObjectManager _omgr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.net.InetAddress;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
import com.samskivert.util.ResultListener;
|
import com.samskivert.util.ResultListener;
|
||||||
import com.samskivert.util.Throttle;
|
import com.samskivert.util.Throttle;
|
||||||
@@ -60,6 +61,7 @@ import com.threerings.presents.net.PongResponse;
|
|||||||
import com.threerings.presents.net.UnsubscribeResponse;
|
import com.threerings.presents.net.UnsubscribeResponse;
|
||||||
|
|
||||||
import com.threerings.presents.server.net.Connection;
|
import com.threerings.presents.server.net.Connection;
|
||||||
|
import com.threerings.presents.server.net.ConnectionManager;
|
||||||
import com.threerings.presents.server.net.MessageHandler;
|
import com.threerings.presents.server.net.MessageHandler;
|
||||||
|
|
||||||
import static com.threerings.presents.Log.log;
|
import static com.threerings.presents.Log.log;
|
||||||
@@ -196,7 +198,7 @@ public class PresentsClient
|
|||||||
log.warning("Client disappeared before we could complete the switch to a " +
|
log.warning("Client disappeared before we could complete the switch to a " +
|
||||||
"new client object [ousername=" + _username +
|
"new client object [ousername=" + _username +
|
||||||
", nusername=" + username + "].");
|
", nusername=" + username + "].");
|
||||||
_cmgr.releaseClientObject(username);
|
_clmgr.releaseClientObject(username);
|
||||||
Exception error = new Exception("Early withdrawal");
|
Exception error = new Exception("Early withdrawal");
|
||||||
resolutionFailed(username, error);
|
resolutionFailed(username, error);
|
||||||
return;
|
return;
|
||||||
@@ -230,7 +232,7 @@ public class PresentsClient
|
|||||||
_clobj.postMessage(ClientObject.CLOBJ_CHANGED, args);
|
_clobj.postMessage(ClientObject.CLOBJ_CHANGED, args);
|
||||||
|
|
||||||
// release our old client object; this will destroy it
|
// release our old client object; this will destroy it
|
||||||
_cmgr.releaseClientObject(_username);
|
_clmgr.releaseClientObject(_username);
|
||||||
|
|
||||||
// update our internal fields
|
// update our internal fields
|
||||||
_username = username;
|
_username = username;
|
||||||
@@ -257,7 +259,7 @@ public class PresentsClient
|
|||||||
};
|
};
|
||||||
|
|
||||||
// resolve the new client object
|
// resolve the new client object
|
||||||
_cmgr.resolveClientObject(username, clr);
|
_clmgr.resolveClientObject(username, clr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,7 +273,7 @@ public class PresentsClient
|
|||||||
*/
|
*/
|
||||||
public boolean updateUsername (Name username)
|
public boolean updateUsername (Name username)
|
||||||
{
|
{
|
||||||
if (_cmgr.renameClientObject(_username, username)) {
|
if (_clmgr.renameClientObject(_username, username)) {
|
||||||
_username = username;
|
_username = username;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -297,7 +299,7 @@ public class PresentsClient
|
|||||||
// go ahead and clear out our connection now to prevent funniness
|
// go ahead and clear out our connection now to prevent funniness
|
||||||
setConnection(null);
|
setConnection(null);
|
||||||
// have the connection manager close our connection when it is next convenient
|
// have the connection manager close our connection when it is next convenient
|
||||||
PresentsServer.conmgr.closeConnection(conn);
|
_conmgr.closeConnection(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't have a client object, we failed to resolve in the first place, in which case
|
// if we don't have a client object, we failed to resolve in the first place, in which case
|
||||||
@@ -311,11 +313,11 @@ public class PresentsClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// release (and destroy) our client object
|
// release (and destroy) our client object
|
||||||
_cmgr.releaseClientObject(_username);
|
_clmgr.releaseClientObject(_username);
|
||||||
}
|
}
|
||||||
|
|
||||||
// let the client manager know that we're audi 5000
|
// let the client manager know that we're audi 5000
|
||||||
_cmgr.clientSessionDidEnd(this);
|
_clmgr.clientSessionDidEnd(this);
|
||||||
|
|
||||||
// clear out the client object so that we know the session is over
|
// clear out the client object so that we know the session is over
|
||||||
_clobj = null;
|
_clobj = null;
|
||||||
@@ -356,7 +358,7 @@ public class PresentsClient
|
|||||||
sendBootstrap();
|
sendBootstrap();
|
||||||
|
|
||||||
// let the client manager know that we're operational
|
// let the client manager know that we're operational
|
||||||
_cmgr.clientSessionDidStart(this);
|
_clmgr.clientSessionDidStart(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from interface ClientResolutionListener
|
// from interface ClientResolutionListener
|
||||||
@@ -420,10 +422,8 @@ public class PresentsClient
|
|||||||
* Initializes this client instance with the specified username, connection instance and client
|
* Initializes this client instance with the specified username, connection instance and client
|
||||||
* object and begins a client session.
|
* object and begins a client session.
|
||||||
*/
|
*/
|
||||||
protected void startSession (
|
protected void startSession (AuthRequest req, Connection conn, Object authdata)
|
||||||
ClientManager cmgr, AuthRequest req, Connection conn, Object authdata)
|
|
||||||
{
|
{
|
||||||
_cmgr = cmgr;
|
|
||||||
_areq = req;
|
_areq = req;
|
||||||
_authdata = authdata;
|
_authdata = authdata;
|
||||||
setConnection(conn);
|
setConnection(conn);
|
||||||
@@ -432,7 +432,7 @@ public class PresentsClient
|
|||||||
assignStartingUsername();
|
assignStartingUsername();
|
||||||
|
|
||||||
// resolve our client object before we get fully underway
|
// resolve our client object before we get fully underway
|
||||||
cmgr.resolveClientObject(_username, this);
|
_clmgr.resolveClientObject(_username, this);
|
||||||
|
|
||||||
// make a note of our session start time
|
// make a note of our session start time
|
||||||
_sessionStamp = System.currentTimeMillis();
|
_sessionStamp = System.currentTimeMillis();
|
||||||
@@ -481,7 +481,7 @@ public class PresentsClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we need to get onto the dobj thread so that we can finalize resumption of the session
|
// we need to get onto the dobj thread so that we can finalize resumption of the session
|
||||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
// now that we're on the dobjmgr thread we can resume our session resumption
|
// now that we're on the dobjmgr thread we can resume our session resumption
|
||||||
finishResumeSession();
|
finishResumeSession();
|
||||||
@@ -516,7 +516,7 @@ public class PresentsClient
|
|||||||
*/
|
*/
|
||||||
protected void safeEndSession ()
|
protected void safeEndSession ()
|
||||||
{
|
{
|
||||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
endSession();
|
endSession();
|
||||||
}
|
}
|
||||||
@@ -679,7 +679,7 @@ public class PresentsClient
|
|||||||
log.warning("Client provided no invocation service boot groups? " + this);
|
log.warning("Client provided no invocation service boot groups? " + this);
|
||||||
data.services = new StreamableArrayList<InvocationMarshaller>();
|
data.services = new StreamableArrayList<InvocationMarshaller>();
|
||||||
} else {
|
} else {
|
||||||
data.services = PresentsServer.invmgr.getBootstrapServices(_areq.getBootGroups());
|
data.services = _invmgr.getBootstrapServices(_areq.getBootGroups());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,7 +699,7 @@ public class PresentsClient
|
|||||||
// that we do this *after* we clear out our connection reference. once the connection ref
|
// that we do this *after* we clear out our connection reference. once the connection ref
|
||||||
// is null, no more subscriptions will be processed (even those that were queued up before
|
// is null, no more subscriptions will be processed (even those that were queued up before
|
||||||
// the connection went away)
|
// the connection went away)
|
||||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
sessionConnectionClosed();
|
sessionConnectionClosed();
|
||||||
}
|
}
|
||||||
@@ -773,7 +773,7 @@ public class PresentsClient
|
|||||||
* the supplied message to this client. */
|
* the supplied message to this client. */
|
||||||
protected final void safePostMessage (final DownstreamMessage msg)
|
protected final void safePostMessage (final DownstreamMessage msg)
|
||||||
{
|
{
|
||||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
postMessage(msg);
|
postMessage(msg);
|
||||||
}
|
}
|
||||||
@@ -851,7 +851,7 @@ public class PresentsClient
|
|||||||
public void objectAvailable (DObject object)
|
public void objectAvailable (DObject object)
|
||||||
{
|
{
|
||||||
if (postMessage(new ObjectResponse<DObject>(object))) {
|
if (postMessage(new ObjectResponse<DObject>(object))) {
|
||||||
_firstEventId = PresentsServer.omgr.getNextEventId(false);
|
_firstEventId = _omgr.getNextEventId(false);
|
||||||
this.object = object;
|
this.object = object;
|
||||||
synchronized (_subscrips) {
|
synchronized (_subscrips) {
|
||||||
// make a note of this new subscription
|
// make a note of this new subscription
|
||||||
@@ -918,7 +918,7 @@ public class PresentsClient
|
|||||||
// log.info("Subscribing [client=" + client + ", oid=" + req.getOid() + "].");
|
// log.info("Subscribing [client=" + client + ", oid=" + req.getOid() + "].");
|
||||||
|
|
||||||
// forward the subscribe request to the omgr for processing
|
// forward the subscribe request to the omgr for processing
|
||||||
PresentsServer.omgr.subscribeToObject(req.getOid(), client.createProxySubscriber());
|
client._omgr.subscribeToObject(req.getOid(), client.createProxySubscriber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,7 +965,7 @@ public class PresentsClient
|
|||||||
// log.info("Forwarding event [client=" + client + ", event=" + fevt + "].");
|
// log.info("Forwarding event [client=" + client + ", event=" + fevt + "].");
|
||||||
|
|
||||||
// forward the event to the omgr for processing
|
// forward the event to the omgr for processing
|
||||||
PresentsServer.omgr.postEvent(fevt);
|
client._omgr.postEvent(fevt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -994,7 +994,11 @@ public class PresentsClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClientManager _cmgr;
|
@Inject protected ClientManager _clmgr;
|
||||||
|
@Inject protected ConnectionManager _conmgr;
|
||||||
|
@Inject protected PresentsDObjectMgr _omgr;
|
||||||
|
@Inject protected InvocationManager _invmgr;
|
||||||
|
|
||||||
protected AuthRequest _areq;
|
protected AuthRequest _areq;
|
||||||
protected Object _authdata;
|
protected Object _authdata;
|
||||||
protected Name _username;
|
protected Name _username;
|
||||||
|
|||||||
@@ -65,21 +65,6 @@ public class PresentsServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** OBSOLETE! Don't use me. */
|
|
||||||
public static ConnectionManager conmgr;
|
|
||||||
|
|
||||||
/** OBSOLETE! Don't use me. */
|
|
||||||
public static ClientManager clmgr;
|
|
||||||
|
|
||||||
/** OBSOLETE! Don't use me. */
|
|
||||||
public static PresentsDObjectMgr omgr;
|
|
||||||
|
|
||||||
/** OBSOLETE! Don't use me. */
|
|
||||||
public static InvocationManager invmgr;
|
|
||||||
|
|
||||||
/** OBSOLETE! Don't use me. */
|
|
||||||
public static Invoker invoker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default entry point for the server.
|
* The default entry point for the server.
|
||||||
*/
|
*/
|
||||||
@@ -120,13 +105,6 @@ public class PresentsServer
|
|||||||
public void init (Injector injector)
|
public void init (Injector injector)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// populate our legacy statics
|
|
||||||
conmgr = _conmgr;
|
|
||||||
clmgr = _clmgr;
|
|
||||||
omgr = _omgr;
|
|
||||||
invmgr = _invmgr;
|
|
||||||
invoker = _invoker;
|
|
||||||
|
|
||||||
// output general system information
|
// output general system information
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
log.info("Starting up server [os=" + si.osToString() + ", jvm=" + si.jvmToString() +
|
log.info("Starting up server [os=" + si.osToString() + ", jvm=" + si.jvmToString() +
|
||||||
@@ -150,11 +128,14 @@ public class PresentsServer
|
|||||||
_invoker.start();
|
_invoker.start();
|
||||||
_authInvoker.start();
|
_authInvoker.start();
|
||||||
|
|
||||||
|
// provide our client manager with the injector it needs
|
||||||
|
_clmgr.setInjector(injector);
|
||||||
|
|
||||||
// configure our connection manager
|
// configure our connection manager
|
||||||
_conmgr.init(getListenPorts(), getDatagramPorts());
|
_conmgr.init(getListenPorts(), getDatagramPorts());
|
||||||
|
|
||||||
// initialize the time base services
|
// initialize the time base services
|
||||||
TimeBaseProvider.init(invmgr, omgr);
|
TimeBaseProvider.init(_invmgr, _omgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,14 +170,14 @@ public class PresentsServer
|
|||||||
{
|
{
|
||||||
// post a unit that will start up the connection manager when everything else in the
|
// post a unit that will start up the connection manager when everything else in the
|
||||||
// dobjmgr queue is processed
|
// dobjmgr queue is processed
|
||||||
omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
// start up the connection manager
|
// start up the connection manager
|
||||||
_conmgr.start();
|
_conmgr.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// invoke the dobjmgr event loop
|
// invoke the dobjmgr event loop
|
||||||
omgr.run();
|
_omgr.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class TestServer extends PresentsServer
|
|||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.init(injector);
|
super.init(injector);
|
||||||
breg = new BureauRegistry("localhost:47624", invmgr, omgr, invoker);
|
breg = new BureauRegistry("localhost:47624", _invmgr, _omgr, _invoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setClientTarget (String target)
|
public static void setClientTarget (String target)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class TestServer extends PresentsServer
|
|||||||
_invmgr.registerDispatcher(new TestDispatcher(new TestManager()), "test");
|
_invmgr.registerDispatcher(new TestDispatcher(new TestManager()), "test");
|
||||||
|
|
||||||
// create a test object
|
// create a test object
|
||||||
testobj = omgr.registerObject(new TestObject());
|
testobj = _omgr.registerObject(new TestObject());
|
||||||
testobj.longs.add(System.currentTimeMillis());
|
testobj.longs.add(System.currentTimeMillis());
|
||||||
long value = Integer.MAX_VALUE;
|
long value = Integer.MAX_VALUE;
|
||||||
value++;
|
value++;
|
||||||
|
|||||||
Reference in New Issue
Block a user