Use injected dependencies, regened services.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5206 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -114,7 +114,7 @@ public class RegistryTester
|
|||||||
*/
|
*/
|
||||||
public void start ()
|
public void start ()
|
||||||
{
|
{
|
||||||
TestServer.setClientTarget(_clientTarget);
|
_server.setClientTarget(_clientTarget);
|
||||||
|
|
||||||
Thread thread = new Thread("Registry test thread") {
|
Thread thread = new Thread("Registry test thread") {
|
||||||
public void run () {
|
public void run () {
|
||||||
@@ -181,7 +181,7 @@ public class RegistryTester
|
|||||||
_omgr.postRunnable(new Runnable() {
|
_omgr.postRunnable(new Runnable() {
|
||||||
public void run () {
|
public void run () {
|
||||||
for (AgentObject obj : _agents) {
|
for (AgentObject obj : _agents) {
|
||||||
TestServer.breg.destroyAgent(obj);
|
_bureauReg.destroyAgent(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -197,7 +197,7 @@ public class RegistryTester
|
|||||||
(size != 0 && _rng1.nextInt(100) >= _createChance)) {
|
(size != 0 && _rng1.nextInt(100) >= _createChance)) {
|
||||||
AgentObject toRemove = _agents.remove(_rng1.nextInt(size));
|
AgentObject toRemove = _agents.remove(_rng1.nextInt(size));
|
||||||
log.info("Removing agent " + toRemove.getOid());
|
log.info("Removing agent " + toRemove.getOid());
|
||||||
TestServer.breg.destroyAgent(toRemove);
|
_bureauReg.destroyAgent(toRemove);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
AgentObject added = create(_rng1.nextInt(_numBureaus) + 1);
|
AgentObject added = create(_rng1.nextInt(_numBureaus) + 1);
|
||||||
@@ -214,11 +214,12 @@ public class RegistryTester
|
|||||||
AgentObject obj = new AgentObject();
|
AgentObject obj = new AgentObject();
|
||||||
obj.bureauType = "test";
|
obj.bureauType = "test";
|
||||||
obj.bureauId = "test-" + bureau;
|
obj.bureauId = "test-" + bureau;
|
||||||
TestServer.breg.startAgent(obj);
|
_bureauReg.startAgent(obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject protected RootDObjectManager _omgr;
|
@Inject protected RootDObjectManager _omgr;
|
||||||
|
@Inject protected BureauRegistry _bureauReg;
|
||||||
|
|
||||||
protected TestServer _server;
|
protected TestServer _server;
|
||||||
protected boolean _stop;
|
protected boolean _stop;
|
||||||
|
|||||||
@@ -22,7 +22,9 @@
|
|||||||
package com.threerings.bureau.server;
|
package com.threerings.bureau.server;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import com.threerings.presents.server.PresentsServer;
|
import com.threerings.presents.server.PresentsServer;
|
||||||
|
|
||||||
@@ -31,13 +33,9 @@ import static com.threerings.bureau.Log.log;
|
|||||||
/**
|
/**
|
||||||
* Extends a presents server to include a bureau registry.
|
* Extends a presents server to include a bureau registry.
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class TestServer extends PresentsServer
|
public class TestServer extends PresentsServer
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The bureau registry for the server. Will be null until <code>init</code> is called.
|
|
||||||
*/
|
|
||||||
public static BureauRegistry breg;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new server and runs it.
|
* Creates a new server and runs it.
|
||||||
*/
|
*/
|
||||||
@@ -47,7 +45,7 @@ public class TestServer extends PresentsServer
|
|||||||
TestServer server = injector.getInstance(TestServer.class);
|
TestServer server = injector.getInstance(TestServer.class);
|
||||||
try {
|
try {
|
||||||
server.init(injector);
|
server.init(injector);
|
||||||
setClientTarget("bureau-runclient");
|
server.setClientTarget("bureau-runclient");
|
||||||
server.run();
|
server.run();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -55,38 +53,34 @@ public class TestServer extends PresentsServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BureauRegistry.CommandGenerator antCommandGenerator (final String target)
|
||||||
|
{
|
||||||
|
return new BureauRegistry.CommandGenerator() {
|
||||||
|
public String[] createCommand (String serverNameAndPort, String bureauId, String token) {
|
||||||
|
int colon = serverNameAndPort.indexOf(':');
|
||||||
|
return new String[] {
|
||||||
|
"ant",
|
||||||
|
"-DserverName=" + serverNameAndPort.substring(0, colon),
|
||||||
|
"-DserverPort=" + serverNameAndPort.substring(colon + 1),
|
||||||
|
"-DbureauId=" + bureauId,
|
||||||
|
"-Dtoken=" + token,
|
||||||
|
target };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from PresentsServer
|
@Override // from PresentsServer
|
||||||
public void init (Injector injector)
|
public void init (Injector injector)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.init(injector);
|
super.init(injector);
|
||||||
breg = new BureauRegistry("localhost:47624", _invmgr, _omgr, _invoker);
|
_bureauReg.init("localhost:47624");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setClientTarget (String target)
|
|
||||||
{
|
|
||||||
breg.setCommandGenerator("test", antCommandGenerator(target));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BureauRegistry.CommandGenerator antCommandGenerator (
|
|
||||||
final String target)
|
|
||||||
{
|
|
||||||
return new BureauRegistry.CommandGenerator() {
|
|
||||||
public String[] createCommand (
|
|
||||||
String serverNameAndPort,
|
|
||||||
String bureauId,
|
|
||||||
String token) {
|
|
||||||
|
|
||||||
int colon = serverNameAndPort.indexOf(':');
|
|
||||||
String [] cmd = {"ant",
|
|
||||||
"-DserverName=" + serverNameAndPort.substring(0, colon),
|
|
||||||
"-DserverPort=" + serverNameAndPort.substring(colon + 1),
|
|
||||||
"-DbureauId=" + bureauId,
|
|
||||||
"-Dtoken=" + token,
|
|
||||||
target};
|
|
||||||
|
|
||||||
return cmd;
|
public void setClientTarget (String target)
|
||||||
}
|
{
|
||||||
};
|
_bureauReg.setCommandGenerator("test", antCommandGenerator(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject protected BureauRegistry _bureauReg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,21 +12,11 @@ import com.threerings.crowd.data.PlaceObject;
|
|||||||
import static com.threerings.crowd.Log.log;
|
import static com.threerings.crowd.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic server that creates a single room and sticks everyone in it
|
* A basic server that creates a single room and sticks everyone in it where they can chat with one
|
||||||
* where they can chat with one another.
|
* another.
|
||||||
*/
|
*/
|
||||||
public class JabberServer extends CrowdServer
|
public class JabberServer extends CrowdServer
|
||||||
{
|
{
|
||||||
// documentation inherited
|
|
||||||
public void init (Injector injector)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.init(injector);
|
|
||||||
|
|
||||||
// create a single location
|
|
||||||
_pmgr = plreg.createPlace(new JabberConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
Injector injector = Guice.createInjector(new Module());
|
Injector injector = Guice.createInjector(new Module());
|
||||||
@@ -40,5 +30,15 @@ public class JabberServer extends CrowdServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from CrowdServer
|
||||||
|
public void init (Injector injector)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.init(injector);
|
||||||
|
|
||||||
|
// create a single location
|
||||||
|
_pmgr = _plreg.createPlace(new JabberConfig());
|
||||||
|
}
|
||||||
|
|
||||||
protected PlaceManager _pmgr;
|
protected PlaceManager _pmgr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||||
// http://www.threerings.net/code/narya/
|
// http://www.threerings.net/code/narya/
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
@@ -23,8 +23,8 @@ package com.threerings.presents.data;
|
|||||||
|
|
||||||
import com.threerings.presents.client.Client;
|
import com.threerings.presents.client.Client;
|
||||||
import com.threerings.presents.client.TestService;
|
import com.threerings.presents.client.TestService;
|
||||||
import com.threerings.presents.data.InvocationMarshaller;
|
|
||||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||||
|
import com.threerings.presents.net.Transport;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +37,9 @@ import java.util.ArrayList;
|
|||||||
public class TestMarshaller extends InvocationMarshaller
|
public class TestMarshaller extends InvocationMarshaller
|
||||||
implements TestService
|
implements TestService
|
||||||
{
|
{
|
||||||
// documentation inherited
|
/**
|
||||||
|
* Marshalls results to implementations of {@link TestFuncListener}.
|
||||||
|
*/
|
||||||
public static class TestFuncMarshaller extends ListenerMarshaller
|
public static class TestFuncMarshaller extends ListenerMarshaller
|
||||||
implements TestFuncListener
|
implements TestFuncListener
|
||||||
{
|
{
|
||||||
@@ -45,16 +47,16 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
* responses. */
|
* responses. */
|
||||||
public static final int TEST_SUCCEEDED = 1;
|
public static final int TEST_SUCCEEDED = 1;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// from interface TestFuncMarshaller
|
||||||
public void testSucceeded (String arg1, int arg2)
|
public void testSucceeded (String arg1, int arg2)
|
||||||
{
|
{
|
||||||
_invId = null;
|
_invId = null;
|
||||||
omgr.postEvent(new InvocationResponseEvent(
|
omgr.postEvent(new InvocationResponseEvent(
|
||||||
callerOid, requestId, TEST_SUCCEEDED,
|
callerOid, requestId, TEST_SUCCEEDED,
|
||||||
new Object[] { arg1, Integer.valueOf(arg2) }));
|
new Object[] { arg1, Integer.valueOf(arg2) }, transport));
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
@Override // from InvocationMarshaller
|
||||||
public void dispatchResponse (int methodId, Object[] args)
|
public void dispatchResponse (int methodId, Object[] args)
|
||||||
{
|
{
|
||||||
switch (methodId) {
|
switch (methodId) {
|
||||||
@@ -70,7 +72,9 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
/**
|
||||||
|
* Marshalls results to implementations of {@link TestOidListener}.
|
||||||
|
*/
|
||||||
public static class TestOidMarshaller extends ListenerMarshaller
|
public static class TestOidMarshaller extends ListenerMarshaller
|
||||||
implements TestOidListener
|
implements TestOidListener
|
||||||
{
|
{
|
||||||
@@ -78,16 +82,16 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
* responses. */
|
* responses. */
|
||||||
public static final int GOT_TEST_OID = 1;
|
public static final int GOT_TEST_OID = 1;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// from interface TestOidMarshaller
|
||||||
public void gotTestOid (int arg1)
|
public void gotTestOid (int arg1)
|
||||||
{
|
{
|
||||||
_invId = null;
|
_invId = null;
|
||||||
omgr.postEvent(new InvocationResponseEvent(
|
omgr.postEvent(new InvocationResponseEvent(
|
||||||
callerOid, requestId, GOT_TEST_OID,
|
callerOid, requestId, GOT_TEST_OID,
|
||||||
new Object[] { Integer.valueOf(arg1) }));
|
new Object[] { Integer.valueOf(arg1) }, transport));
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
@Override // from InvocationMarshaller
|
||||||
public void dispatchResponse (int methodId, Object[] args)
|
public void dispatchResponse (int methodId, Object[] args)
|
||||||
{
|
{
|
||||||
switch (methodId) {
|
switch (methodId) {
|
||||||
@@ -106,7 +110,7 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
/** The method id used to dispatch {@link #getTestOid} requests. */
|
/** The method id used to dispatch {@link #getTestOid} requests. */
|
||||||
public static final int GET_TEST_OID = 1;
|
public static final int GET_TEST_OID = 1;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// from interface TestService
|
||||||
public void getTestOid (Client arg1, TestService.TestOidListener arg2)
|
public void getTestOid (Client arg1, TestService.TestOidListener arg2)
|
||||||
{
|
{
|
||||||
TestMarshaller.TestOidMarshaller listener2 = new TestMarshaller.TestOidMarshaller();
|
TestMarshaller.TestOidMarshaller listener2 = new TestMarshaller.TestOidMarshaller();
|
||||||
@@ -119,7 +123,7 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
/** The method id used to dispatch {@link #test} requests. */
|
/** The method id used to dispatch {@link #test} requests. */
|
||||||
public static final int TEST = 2;
|
public static final int TEST = 2;
|
||||||
|
|
||||||
// documentation inherited from interface
|
// from interface TestService
|
||||||
public void test (Client arg1, String arg2, int arg3, ArrayList<java.lang.Integer> arg4, TestService.TestFuncListener arg5)
|
public void test (Client arg1, String arg2, int arg3, ArrayList<java.lang.Integer> arg4, TestService.TestFuncListener arg5)
|
||||||
{
|
{
|
||||||
TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
|
TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
|
||||||
@@ -128,5 +132,4 @@ public class TestMarshaller extends InvocationMarshaller
|
|||||||
arg2, Integer.valueOf(arg3), arg4, listener5
|
arg2, Integer.valueOf(arg3), arg4, listener5
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||||
// http://www.threerings.net/code/narya/
|
// http://www.threerings.net/code/narya/
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
@@ -25,14 +25,12 @@ import com.threerings.presents.client.TestService;
|
|||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.data.InvocationMarshaller;
|
import com.threerings.presents.data.InvocationMarshaller;
|
||||||
import com.threerings.presents.data.TestMarshaller;
|
import com.threerings.presents.data.TestMarshaller;
|
||||||
import com.threerings.presents.server.InvocationDispatcher;
|
|
||||||
import com.threerings.presents.server.InvocationException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatches requests to the {@link TestProvider}.
|
* Dispatches requests to the {@link TestProvider}.
|
||||||
*/
|
*/
|
||||||
public class TestDispatcher extends InvocationDispatcher
|
public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a dispatcher that may be registered to dispatch invocation
|
* Creates a dispatcher that may be registered to dispatch invocation
|
||||||
@@ -43,13 +41,14 @@ public class TestDispatcher extends InvocationDispatcher
|
|||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
@Override // documentation inherited
|
||||||
public InvocationMarshaller createMarshaller ()
|
public TestMarshaller createMarshaller ()
|
||||||
{
|
{
|
||||||
return new TestMarshaller();
|
return new TestMarshaller();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") // documentation inherited
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override // documentation inherited
|
||||||
public void dispatchRequest (
|
public void dispatchRequest (
|
||||||
ClientObject source, int methodId, Object[] args)
|
ClientObject source, int methodId, Object[] args)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
//
|
//
|
||||||
// Narya library - tools for developing networked games
|
// Narya library - tools for developing networked games
|
||||||
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
// Copyright (C) 2002-2008 Three Rings Design, Inc., All Rights Reserved
|
||||||
// http://www.threerings.net/code/narya/
|
// http://www.threerings.net/code/narya/
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
@@ -23,8 +23,6 @@ package com.threerings.presents.server;
|
|||||||
|
|
||||||
import com.threerings.presents.client.TestService;
|
import com.threerings.presents.client.TestService;
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.ClientObject;
|
||||||
import com.threerings.presents.server.InvocationException;
|
|
||||||
import com.threerings.presents.server.InvocationProvider;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user