Test throttle changing.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5433 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -31,6 +31,7 @@ import com.threerings.util.Name;
|
||||
import com.threerings.presents.data.TestObject;
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.MessageEvent;
|
||||
import com.threerings.presents.dobj.ObjectAccessException;
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
import com.threerings.presents.net.UsernamePasswordCreds;
|
||||
@@ -49,12 +50,14 @@ public class TestClient
|
||||
_client = client;
|
||||
}
|
||||
|
||||
// from interface RunQueue
|
||||
public void postRunnable (Runnable run)
|
||||
{
|
||||
// queue it on up
|
||||
_queue.append(run);
|
||||
}
|
||||
|
||||
// from interface RunQueue
|
||||
public boolean isDispatchThread ()
|
||||
{
|
||||
return _main == Thread.currentThread();
|
||||
@@ -71,11 +74,13 @@ public class TestClient
|
||||
}
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientWillLogon (Client client)
|
||||
{
|
||||
client.addServiceGroup("test");
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
log.info("Client did logon [client=" + client + "].");
|
||||
@@ -103,29 +108,50 @@ public class TestClient
|
||||
service.getTestOid(client, this);
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
log.info("Client object did change [client=" + client + "].");
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
log.info("Client did logoff [client=" + client + "].");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void objectAvailable (TestObject object)
|
||||
// from interface Subscriber
|
||||
public void objectAvailable (final TestObject object)
|
||||
{
|
||||
object.addListener(this);
|
||||
log.info("Object available: " + object);
|
||||
object.postMessage("lawl!");
|
||||
|
||||
// try blowing through our message limit
|
||||
for (int ii = 0; ii < 15*Client.DEFAULT_MSGS_PER_SECOND; ii++) {
|
||||
for (int ii = 0; ii < 4*Client.DEFAULT_MSGS_PER_SECOND; ii++) {
|
||||
object.postMessage("ZOMG!", new Integer(ii));
|
||||
}
|
||||
|
||||
// ask for the power
|
||||
TestService service = _client.requireService(TestService.class);
|
||||
service.giveMeThePower(_client, new TestService.ConfirmListener() {
|
||||
public void requestProcessed () {
|
||||
log.info("We have the power!");
|
||||
// now try blowing through our message limit again
|
||||
for (int ii = 0; ii < 8*Client.DEFAULT_MSGS_PER_SECOND; ii++) {
|
||||
object.postMessage("ZOMG!", new Integer(ii));
|
||||
}
|
||||
// and finally shutdown
|
||||
object.postMessage("shutdown");
|
||||
}
|
||||
public void requestFailed (String cause) {
|
||||
log.warning("Dang, no power! " + cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// from interface Subscriber
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
log.info("Object unavailable [oid=" + oid +
|
||||
@@ -134,12 +160,15 @@ public class TestClient
|
||||
_client.logoff(true);
|
||||
}
|
||||
|
||||
// from interface EventListener
|
||||
public void eventReceived (DEvent event)
|
||||
{
|
||||
log.info("Got event [event=" + event + "].");
|
||||
|
||||
// // request that we log off
|
||||
// _client.logoff(true);
|
||||
if (event instanceof MessageEvent && ((MessageEvent)event).getName().equals("shutdown")) {
|
||||
// request that we log off
|
||||
_client.logoff(true);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A test of the invocation services.
|
||||
@@ -35,10 +35,6 @@ public interface TestService extends InvocationService
|
||||
public void testSucceeded (String one, int two);
|
||||
}
|
||||
|
||||
/** Issues a test request. */
|
||||
public void test (
|
||||
Client client, String one, int two, ArrayList<Integer> three, TestFuncListener listener);
|
||||
|
||||
/** Used to dispatch responses to {@link TestService#getTestOid} requests. */
|
||||
public static interface TestOidListener extends InvocationListener
|
||||
{
|
||||
@@ -46,6 +42,13 @@ public interface TestService extends InvocationService
|
||||
public void gotTestOid (int testOid);
|
||||
}
|
||||
|
||||
/** Issues a test request. */
|
||||
public void test (Client client, String one, int two, List<Integer> three,
|
||||
TestFuncListener listener);
|
||||
|
||||
/** Issues a request for the test oid. */
|
||||
public void getTestOid (Client client, TestOidListener listener);
|
||||
|
||||
/** Tests upping the client's maximum message rate. */
|
||||
public void giveMeThePower (Client client, ConfirmListener listener);
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
|
||||
package com.threerings.presents.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link TestService} interface
|
||||
@@ -120,11 +120,24 @@ public class TestMarshaller extends InvocationMarshaller
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #test} requests. */
|
||||
public static final int TEST = 2;
|
||||
/** The method id used to dispatch {@link #giveMeThePower} requests. */
|
||||
public static final int GIVE_ME_THE_POWER = 2;
|
||||
|
||||
// from interface TestService
|
||||
public void test (Client arg1, String arg2, int arg3, ArrayList<java.lang.Integer> arg4, TestService.TestFuncListener arg5)
|
||||
public void giveMeThePower (Client arg1, InvocationService.ConfirmListener arg2)
|
||||
{
|
||||
InvocationMarshaller.ConfirmMarshaller listener2 = new InvocationMarshaller.ConfirmMarshaller();
|
||||
listener2.listener = arg2;
|
||||
sendRequest(arg1, GIVE_ME_THE_POWER, new Object[] {
|
||||
listener2
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #test} requests. */
|
||||
public static final int TEST = 3;
|
||||
|
||||
// from interface TestService
|
||||
public void test (Client arg1, String arg2, int arg3, List<Integer> arg4, TestService.TestFuncListener arg5)
|
||||
{
|
||||
TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
|
||||
listener5.listener = arg5;
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.data.TestMarshaller;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link TestProvider}.
|
||||
@@ -47,7 +47,6 @@ public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
|
||||
return new TestMarshaller();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override // documentation inherited
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
@@ -56,15 +55,19 @@ public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
|
||||
switch (methodId) {
|
||||
case TestMarshaller.GET_TEST_OID:
|
||||
((TestProvider)provider).getTestOid(
|
||||
source,
|
||||
(TestService.TestOidListener)args[0]
|
||||
source, (TestService.TestOidListener)args[0]
|
||||
);
|
||||
return;
|
||||
|
||||
case TestMarshaller.GIVE_ME_THE_POWER:
|
||||
((TestProvider)provider).giveMeThePower(
|
||||
source, (InvocationService.ConfirmListener)args[0]
|
||||
);
|
||||
return;
|
||||
|
||||
case TestMarshaller.TEST:
|
||||
((TestProvider)provider).test(
|
||||
source,
|
||||
(String)args[0], ((Integer)args[1]).intValue(), (ArrayList<java.lang.Integer>)args[2], (TestService.TestFuncListener)args[3]
|
||||
source, (String)args[0], ((Integer)args[1]).intValue(), (List<Integer>)args[2], (TestService.TestFuncListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.ClientManager;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
@@ -32,8 +35,8 @@ public class TestManager
|
||||
}
|
||||
|
||||
// from interface TestProvider
|
||||
public void test (ClientObject caller, String one, int two,
|
||||
ArrayList<Integer> three, TestService.TestFuncListener listener)
|
||||
public void test (ClientObject caller, String one, int two, List<Integer> three,
|
||||
TestService.TestFuncListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
log.info("Test request [one=" + one + ", two=" + two +
|
||||
@@ -42,4 +45,14 @@ public class TestManager
|
||||
// and issue a response to this invocation request
|
||||
listener.testSucceeded(one, two);
|
||||
}
|
||||
|
||||
// from interface TestProvider
|
||||
public void giveMeThePower (ClientObject caller, TestService.ConfirmListener listener)
|
||||
{
|
||||
log.info("Giving " + caller.who() + " the power!");
|
||||
_clmgr.getClient(caller.username).setIncomingMessageThrottle(20);
|
||||
listener.requestProcessed();
|
||||
}
|
||||
|
||||
@Inject protected ClientManager _clmgr;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines the server-side of the {@link TestService}.
|
||||
@@ -34,12 +34,18 @@ public interface TestProvider extends InvocationProvider
|
||||
/**
|
||||
* Handles a {@link TestService#getTestOid} request.
|
||||
*/
|
||||
public void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
|
||||
void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
|
||||
throws InvocationException;
|
||||
|
||||
/**
|
||||
* Handles a {@link TestService#giveMeThePower} request.
|
||||
*/
|
||||
void giveMeThePower (ClientObject caller, InvocationService.ConfirmListener arg1)
|
||||
throws InvocationException;
|
||||
|
||||
/**
|
||||
* Handles a {@link TestService#test} request.
|
||||
*/
|
||||
public void test (ClientObject caller, String arg1, int arg2, ArrayList<java.lang.Integer> arg3, TestService.TestFuncListener arg4)
|
||||
void test (ClientObject caller, String arg1, int arg2, List<Integer> arg3, TestService.TestFuncListener arg4)
|
||||
throws InvocationException;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ public class TestServer extends PresentsServer
|
||||
super.init(injector);
|
||||
|
||||
// register our test provider
|
||||
_invmgr.registerDispatcher(new TestDispatcher(new TestManager()), "test");
|
||||
_invmgr.registerDispatcher(
|
||||
new TestDispatcher(injector.getInstance(TestManager.class)), "test");
|
||||
|
||||
// create a test object
|
||||
testobj = _omgr.registerObject(new TestObject());
|
||||
|
||||
Reference in New Issue
Block a user