Demonstrate parameterizing TestService on TestClientObject.
This commit is contained in:
@@ -23,12 +23,12 @@ package com.threerings.presents.client;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.TestClientObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test of the invocation services.
|
* A test of the invocation services.
|
||||||
*/
|
*/
|
||||||
public interface TestService extends InvocationService<ClientObject>
|
public interface TestService extends InvocationService<TestClientObject>
|
||||||
{
|
{
|
||||||
/** Used to dispatch responses to {@link TestService#test} requests. */
|
/** Used to dispatch responses to {@link TestService#test} requests. */
|
||||||
public static interface TestFuncListener extends InvocationListener
|
public static interface TestFuncListener extends InvocationListener
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2012 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://code.google.com/p/narya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.presents.data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to test using a custom client object in invocation services.
|
||||||
|
*/
|
||||||
|
public class TestClientObject extends ClientObject
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ import com.threerings.presents.client.TestService;
|
|||||||
*/
|
*/
|
||||||
@Generated(value={"com.threerings.presents.tools.GenServiceTask"},
|
@Generated(value={"com.threerings.presents.tools.GenServiceTask"},
|
||||||
comments="Derived from TestService.java.")
|
comments="Derived from TestService.java.")
|
||||||
public class TestMarshaller extends InvocationMarshaller<ClientObject>
|
public class TestMarshaller extends InvocationMarshaller<TestClientObject>
|
||||||
implements TestService
|
implements TestService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.util.List;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import com.threerings.presents.client.TestService;
|
import com.threerings.presents.client.TestService;
|
||||||
import com.threerings.presents.data.ClientObject;
|
import com.threerings.presents.data.TestClientObject;
|
||||||
import com.threerings.presents.server.ClientManager;
|
import com.threerings.presents.server.ClientManager;
|
||||||
|
|
||||||
import static com.threerings.presents.Log.log;
|
import static com.threerings.presents.Log.log;
|
||||||
@@ -38,7 +38,7 @@ public class TestManager
|
|||||||
implements TestProvider
|
implements TestProvider
|
||||||
{
|
{
|
||||||
// from interface TestProvider
|
// from interface TestProvider
|
||||||
public void getTestOid (ClientObject caller,
|
public void getTestOid (TestClientObject caller,
|
||||||
TestService.TestOidListener listener)
|
TestService.TestOidListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ public class TestManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from interface TestProvider
|
// from interface TestProvider
|
||||||
public void test (ClientObject caller, String one, int two, List<Integer> three,
|
public void test (TestClientObject caller, String one, int two, List<Integer> three,
|
||||||
TestService.TestFuncListener listener)
|
TestService.TestFuncListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
@@ -62,7 +62,7 @@ public class TestManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from interface TestProvider
|
// from interface TestProvider
|
||||||
public void giveMeThePower (ClientObject caller, TestService.ConfirmListener listener)
|
public void giveMeThePower (TestClientObject caller, TestService.ConfirmListener listener)
|
||||||
{
|
{
|
||||||
log.info("Giving " + caller.who() + " the power!");
|
log.info("Giving " + caller.who() + " the power!");
|
||||||
_clmgr.getClient(caller.username).setIncomingMessageThrottle(20);
|
_clmgr.getClient(caller.username).setIncomingMessageThrottle(20);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import javax.annotation.Generated;
|
|||||||
|
|
||||||
import com.threerings.presents.client.InvocationService;
|
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.TestClientObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the server-side of the {@link TestService}.
|
* Defines the server-side of the {@link TestService}.
|
||||||
@@ -39,18 +39,18 @@ public interface TestProvider extends InvocationProvider
|
|||||||
/**
|
/**
|
||||||
* Handles a {@link TestService#getTestOid} request.
|
* Handles a {@link TestService#getTestOid} request.
|
||||||
*/
|
*/
|
||||||
void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
|
void getTestOid (TestClientObject caller, TestService.TestOidListener arg1)
|
||||||
throws InvocationException;
|
throws InvocationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a {@link TestService#giveMeThePower} request.
|
* Handles a {@link TestService#giveMeThePower} request.
|
||||||
*/
|
*/
|
||||||
void giveMeThePower (ClientObject caller, InvocationService.ConfirmListener arg1)
|
void giveMeThePower (TestClientObject caller, InvocationService.ConfirmListener arg1)
|
||||||
throws InvocationException;
|
throws InvocationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a {@link TestService#test} request.
|
* Handles a {@link TestService#test} request.
|
||||||
*/
|
*/
|
||||||
void test (ClientObject caller, String arg1, int arg2, List<Integer> arg3, TestService.TestFuncListener arg4)
|
void test (TestClientObject caller, String arg1, int arg2, List<Integer> arg3, TestService.TestFuncListener arg4)
|
||||||
throws InvocationException;
|
throws InvocationException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ package com.threerings.presents.server;
|
|||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
import com.threerings.presents.data.ClientObject;
|
||||||
|
import com.threerings.presents.data.TestClientObject;
|
||||||
import com.threerings.presents.data.TestMarshaller;
|
import com.threerings.presents.data.TestMarshaller;
|
||||||
import com.threerings.presents.data.TestObject;
|
import com.threerings.presents.data.TestObject;
|
||||||
|
import com.threerings.presents.net.AuthRequest;
|
||||||
|
import com.threerings.util.Name;
|
||||||
|
|
||||||
public class TestServer extends PresentsServer
|
public class TestServer extends PresentsServer
|
||||||
{
|
{
|
||||||
@@ -40,6 +44,15 @@ public class TestServer extends PresentsServer
|
|||||||
_invmgr.registerProvider(injector.getInstance(TestManager.class),
|
_invmgr.registerProvider(injector.getInstance(TestManager.class),
|
||||||
TestMarshaller.class, "test");
|
TestMarshaller.class, "test");
|
||||||
|
|
||||||
|
_clmgr.setDefaultSessionFactory(new SessionFactory() {
|
||||||
|
@Override public Class<? extends PresentsSession> getSessionClass (AuthRequest areq) {
|
||||||
|
return PresentsSession.class;
|
||||||
|
}
|
||||||
|
@Override public Class<? extends ClientResolver> getClientResolverClass (Name username) {
|
||||||
|
return TestClientResolver.class;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 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());
|
||||||
@@ -52,4 +65,10 @@ public class TestServer extends PresentsServer
|
|||||||
{
|
{
|
||||||
runServer(new PresentsModule(), new PresentsServerModule(TestServer.class));
|
runServer(new PresentsModule(), new PresentsServerModule(TestServer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static class TestClientResolver extends ClientResolver {
|
||||||
|
@Override public ClientObject createClientObject () {
|
||||||
|
return new TestClientObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user