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:
Michael Bayne
2008-10-10 22:43:55 +00:00
parent a4a25674ce
commit ae6e3e883a
7 changed files with 97 additions and 29 deletions
@@ -31,6 +31,7 @@ import com.threerings.util.Name;
import com.threerings.presents.data.TestObject; import com.threerings.presents.data.TestObject;
import com.threerings.presents.dobj.DEvent; import com.threerings.presents.dobj.DEvent;
import com.threerings.presents.dobj.EventListener; import com.threerings.presents.dobj.EventListener;
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.ObjectAccessException; import com.threerings.presents.dobj.ObjectAccessException;
import com.threerings.presents.dobj.Subscriber; import com.threerings.presents.dobj.Subscriber;
import com.threerings.presents.net.UsernamePasswordCreds; import com.threerings.presents.net.UsernamePasswordCreds;
@@ -49,12 +50,14 @@ public class TestClient
_client = client; _client = client;
} }
// from interface RunQueue
public void postRunnable (Runnable run) public void postRunnable (Runnable run)
{ {
// queue it on up // queue it on up
_queue.append(run); _queue.append(run);
} }
// from interface RunQueue
public boolean isDispatchThread () public boolean isDispatchThread ()
{ {
return _main == Thread.currentThread(); return _main == Thread.currentThread();
@@ -71,11 +74,13 @@ public class TestClient
} }
} }
// from interface SessionObserver
public void clientWillLogon (Client client) public void clientWillLogon (Client client)
{ {
client.addServiceGroup("test"); client.addServiceGroup("test");
} }
// from interface SessionObserver
public void clientDidLogon (Client client) public void clientDidLogon (Client client)
{ {
log.info("Client did logon [client=" + client + "]."); log.info("Client did logon [client=" + client + "].");
@@ -103,29 +108,50 @@ public class TestClient
service.getTestOid(client, this); service.getTestOid(client, this);
} }
// from interface SessionObserver
public void clientObjectDidChange (Client client) public void clientObjectDidChange (Client client)
{ {
log.info("Client object did change [client=" + client + "]."); log.info("Client object did change [client=" + client + "].");
} }
// from interface SessionObserver
public void clientDidLogoff (Client client) public void clientDidLogoff (Client client)
{ {
log.info("Client did logoff [client=" + client + "]."); log.info("Client did logoff [client=" + client + "].");
System.exit(0); System.exit(0);
} }
public void objectAvailable (TestObject object) // from interface Subscriber
public void objectAvailable (final TestObject object)
{ {
object.addListener(this); object.addListener(this);
log.info("Object available: " + object); log.info("Object available: " + object);
object.postMessage("lawl!"); object.postMessage("lawl!");
// try blowing through our message limit // 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)); 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) public void requestFailed (int oid, ObjectAccessException cause)
{ {
log.info("Object unavailable [oid=" + oid + log.info("Object unavailable [oid=" + oid +
@@ -134,12 +160,15 @@ public class TestClient
_client.logoff(true); _client.logoff(true);
} }
// from interface EventListener
public void eventReceived (DEvent event) public void eventReceived (DEvent event)
{ {
log.info("Got event [event=" + event + "]."); log.info("Got event [event=" + event + "].");
// // request that we log off if (event instanceof MessageEvent && ((MessageEvent)event).getName().equals("shutdown")) {
// _client.logoff(true); // request that we log off
_client.logoff(true);
}
} }
// documentation inherited from interface // documentation inherited from interface
@@ -21,7 +21,7 @@
package com.threerings.presents.client; package com.threerings.presents.client;
import java.util.ArrayList; import java.util.List;
/** /**
* A test of the invocation services. * A test of the invocation services.
@@ -35,10 +35,6 @@ public interface TestService extends InvocationService
public void testSucceeded (String one, int two); 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. */ /** Used to dispatch responses to {@link TestService#getTestOid} requests. */
public static interface TestOidListener extends InvocationListener public static interface TestOidListener extends InvocationListener
{ {
@@ -46,6 +42,13 @@ public interface TestService extends InvocationService
public void gotTestOid (int testOid); 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. */ /** Issues a request for the test oid. */
public void getTestOid (Client client, TestOidListener listener); 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; package com.threerings.presents.data;
import java.util.ArrayList;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.client.TestService; import com.threerings.presents.client.TestService;
import com.threerings.presents.dobj.InvocationResponseEvent; import com.threerings.presents.dobj.InvocationResponseEvent;
import java.util.List;
/** /**
* Provides the implementation of the {@link TestService} interface * 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. */ /** The method id used to dispatch {@link #giveMeThePower} requests. */
public static final int TEST = 2; public static final int GIVE_ME_THE_POWER = 2;
// from interface TestService // 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(); TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
listener5.listener = arg5; listener5.listener = arg5;
@@ -21,11 +21,11 @@
package com.threerings.presents.server; 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.client.TestService;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.TestMarshaller; import com.threerings.presents.data.TestMarshaller;
import java.util.List;
/** /**
* Dispatches requests to the {@link TestProvider}. * Dispatches requests to the {@link TestProvider}.
@@ -47,7 +47,6 @@ public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
return new TestMarshaller(); return new TestMarshaller();
} }
@SuppressWarnings("unchecked")
@Override // documentation inherited @Override // documentation inherited
public void dispatchRequest ( public void dispatchRequest (
ClientObject source, int methodId, Object[] args) ClientObject source, int methodId, Object[] args)
@@ -56,15 +55,19 @@ public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
switch (methodId) { switch (methodId) {
case TestMarshaller.GET_TEST_OID: case TestMarshaller.GET_TEST_OID:
((TestProvider)provider).getTestOid( ((TestProvider)provider).getTestOid(
source, source, (TestService.TestOidListener)args[0]
(TestService.TestOidListener)args[0] );
return;
case TestMarshaller.GIVE_ME_THE_POWER:
((TestProvider)provider).giveMeThePower(
source, (InvocationService.ConfirmListener)args[0]
); );
return; return;
case TestMarshaller.TEST: case TestMarshaller.TEST:
((TestProvider)provider).test( ((TestProvider)provider).test(
source, source, (String)args[0], ((Integer)args[1]).intValue(), (List<Integer>)args[2], (TestService.TestFuncListener)args[3]
(String)args[0], ((Integer)args[1]).intValue(), (ArrayList<java.lang.Integer>)args[2], (TestService.TestFuncListener)args[3]
); );
return; return;
@@ -3,12 +3,15 @@
package com.threerings.presents.server; 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.samskivert.util.StringUtil;
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.ClientManager;
import static com.threerings.presents.Log.log; import static com.threerings.presents.Log.log;
@@ -32,8 +35,8 @@ public class TestManager
} }
// from interface TestProvider // from interface TestProvider
public void test (ClientObject caller, String one, int two, public void test (ClientObject caller, String one, int two, List<Integer> three,
ArrayList<Integer> three, TestService.TestFuncListener listener) TestService.TestFuncListener listener)
throws InvocationException throws InvocationException
{ {
log.info("Test request [one=" + one + ", two=" + two + log.info("Test request [one=" + one + ", two=" + two +
@@ -42,4 +45,14 @@ public class TestManager
// and issue a response to this invocation request // and issue a response to this invocation request
listener.testSucceeded(one, two); 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; 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.client.TestService;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import java.util.List;
/** /**
* Defines the server-side of the {@link TestService}. * Defines the server-side of the {@link TestService}.
@@ -34,12 +34,18 @@ public interface TestProvider extends InvocationProvider
/** /**
* Handles a {@link TestService#getTestOid} request. * 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; throws InvocationException;
/** /**
* Handles a {@link TestService#test} request. * 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; throws InvocationException;
} }
@@ -39,7 +39,8 @@ public class TestServer extends PresentsServer
super.init(injector); super.init(injector);
// register our test provider // register our test provider
_invmgr.registerDispatcher(new TestDispatcher(new TestManager()), "test"); _invmgr.registerDispatcher(
new TestDispatcher(injector.getInstance(TestManager.class)), "test");
// create a test object // create a test object
testobj = _omgr.registerObject(new TestObject()); testobj = _omgr.registerObject(new TestObject());