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:
Michael Bayne
2008-06-08 20:23:49 +00:00
parent eeb2584c0d
commit 0128f6525a
13 changed files with 133 additions and 103 deletions
@@ -21,6 +21,7 @@
package com.threerings.presents.peer.server;
import com.google.inject.Inject;
import com.samskivert.util.Throttle;
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
* manager. This is only done by the {@link PeerClientFactory}.
*/
protected PeerClient (PeerManager peermgr)
@Inject public PeerClient (PeerManager peermgr)
{
_peermgr = peermgr;
}
@@ -31,37 +31,35 @@ import com.threerings.presents.server.PresentsClient;
import com.threerings.presents.peer.net.PeerCreds;
/**
* Handles resolution of peer servers and passes non-peer resolution requests
* through to a normal factory.
* Handles resolution of peer servers and passes non-peer resolution requests through to a normal
* factory.
*/
public class PeerClientFactory implements ClientFactory
{
public PeerClientFactory (PeerManager peermgr, ClientFactory delegate)
public PeerClientFactory (ClientFactory delegate)
{
_peermgr = peermgr;
_delegate = delegate;
}
// documentation inherited from interface ClientFactory
public PresentsClient createClient (AuthRequest areq)
public Class<? extends PresentsClient> getClientClass (AuthRequest areq)
{
if (areq.getCredentials() instanceof PeerCreds) {
return new PeerClient(_peermgr);
return PeerClient.class;
} else {
return _delegate.createClient(areq);
return _delegate.getClientClass(areq);
}
}
// documentation inherited from interface ClientFactory
public ClientResolver createClientResolver (Name username)
public Class<? extends ClientResolver> getClientResolverClass (Name username)
{
if (username.toString().startsWith(PeerCreds.PEER_PREFIX)) {
return new PeerClientResolver();
return PeerClientResolver.class;
} else {
return _delegate.createClientResolver(username);
return _delegate.getClientResolverClass(username);
}
}
protected PeerManager _peermgr;
protected ClientFactory _delegate;
}
@@ -220,7 +220,7 @@ public class PeerManager
// wire ourselves into the server
_conmgr.addChainedAuthenticator(new PeerAuthenticator(this));
_clmgr.setClientFactory(new PeerClientFactory(this, _clmgr.getClientFactory()));
_clmgr.setClientFactory(new PeerClientFactory(_clmgr.getClientFactory()));
// create our node object
_nodeobj = _omgr.registerObject(createNodeObject());