Implemented object destruction; wired up some missing stuff; created a
test server to make some testing easier; various other cleanups. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@188 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# $Id: server.properties,v 1.1 2001/08/07 20:38:58 mdb Exp $
|
||||
#
|
||||
# Configuration for the Cher test server
|
||||
|
||||
# These invocation service providers will be registered with the
|
||||
# invocation manager during the server init process
|
||||
providers = \
|
||||
test = com.threerings.cocktail.cher.server.test.TestProvider
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestClient.java,v 1.7 2001/07/19 19:18:06 mdb Exp $
|
||||
// $Id: TestClient.java,v 1.8 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.client.test;
|
||||
|
||||
@@ -18,6 +18,11 @@ import com.threerings.cocktail.cher.server.test.TestObject;
|
||||
public class TestClient
|
||||
implements Client.Invoker, ClientObserver, Subscriber
|
||||
{
|
||||
public void setClient (Client client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public void invokeLater (Runnable run)
|
||||
{
|
||||
// queue it on up
|
||||
@@ -36,13 +41,11 @@ public class TestClient
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
Log.info("Client did logon [client=" + client + "].");
|
||||
// try subscribing to a test object
|
||||
client.getDObjectManager().subscribeToObject(2, this);
|
||||
// register our test notification receiver
|
||||
client.getInvocationManager().registerReceiver(TestService.MODULE,
|
||||
new TestReceiver());
|
||||
// issue a test invocation request
|
||||
TestService.test(client, "foo", 1, this);
|
||||
// get the test object id
|
||||
TestService.getTestOid(client, this);
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
@@ -79,28 +82,41 @@ public class TestClient
|
||||
{
|
||||
Log.info("Object unavailable [oid=" + oid +
|
||||
", reason=" + cause + "].");
|
||||
// nothing to do, so might as well logoff
|
||||
_client.logoff(true);
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
Log.info("Got event [event=" + event + ", target=" + target + "].");
|
||||
// dispatch a second event
|
||||
((TestObject)target).setBar("rofl!");
|
||||
// unsubscribe to the object to make sure we don't get the event
|
||||
return false;
|
||||
if (event instanceof AttributeChangedEvent) {
|
||||
// request to destroy the object
|
||||
target.destroy();
|
||||
} else {
|
||||
// request that we log off
|
||||
_client.logoff(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void handleTestSucceeded (String one, int two)
|
||||
public void handleTestSucceeded (int invid, String one, int two)
|
||||
{
|
||||
Log.info("Got test response [one=" + one + ", two=" + two + "].");
|
||||
}
|
||||
|
||||
public void handleGotTestOid (int invid, int oid)
|
||||
{
|
||||
// subscribe to the test object
|
||||
_client.getDObjectManager().subscribeToObject(oid, this);
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
TestClient tclient = new TestClient();
|
||||
UsernamePasswordCreds creds =
|
||||
new UsernamePasswordCreds("test", "test");
|
||||
Client client = new Client(creds, tclient);
|
||||
tclient.setClient(client);
|
||||
client.addObserver(tclient);
|
||||
client.setServer("localhost", 4007);
|
||||
client.logon();
|
||||
@@ -109,4 +125,5 @@ public class TestClient
|
||||
}
|
||||
|
||||
protected Queue _queue = new Queue();
|
||||
protected Client _client;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestService.java,v 1.1 2001/07/19 07:48:25 mdb Exp $
|
||||
// $Id: TestService.java,v 1.2 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.client.test;
|
||||
|
||||
@@ -22,4 +22,11 @@ public class TestService
|
||||
invmgr.invoke(MODULE, "Test", args, rsptarget);
|
||||
Log.info("Sent test request [one=" + one + ", two=" + two + "].");
|
||||
}
|
||||
|
||||
public static void getTestOid (Client client, Object rsptarget)
|
||||
{
|
||||
InvocationManager invmgr = client.getInvocationManager();
|
||||
Object[] args = new Object[0];
|
||||
invmgr.invoke(MODULE, "GetTestOid", args, rsptarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestProvider.java,v 1.4 2001/07/19 19:18:07 mdb Exp $
|
||||
// $Id: TestProvider.java,v 1.5 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.server.test;
|
||||
|
||||
@@ -27,4 +27,10 @@ public class TestProvider extends InvocationProvider
|
||||
// and issue a response to this invocation request
|
||||
return createResponse("TestSucceeded", one, new Integer(two));
|
||||
}
|
||||
|
||||
public Object[] handleGetTestOidRequest (ClientObject source)
|
||||
{
|
||||
int oid = TestServer.testobj.getOid();
|
||||
return createResponse("GotTestOid", new Integer(oid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// $Id: TestServer.java,v 1.1 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.server.test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.threerings.cocktail.cher.Log;
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
import com.threerings.cocktail.cher.server.*;
|
||||
|
||||
public class TestServer extends CherServer
|
||||
{
|
||||
/** The namespace used for server config properties. */
|
||||
public static final String CONFIG_KEY = "test";
|
||||
|
||||
public static TestObject testobj;
|
||||
|
||||
public void init ()
|
||||
throws IOException
|
||||
{
|
||||
super.init();
|
||||
|
||||
// bind the party server config into the namespace
|
||||
config.bindProperties(CONFIG_KEY, CONFIG_PATH);
|
||||
|
||||
// register our invocation service providers
|
||||
registerProviders(config.getValue(PROVIDERS_KEY, (String[])null));
|
||||
|
||||
// create a test object
|
||||
Subscriber sub = new Subscriber()
|
||||
{
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
testobj = (TestObject)object;
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
Log.warning("Unable to create test object " +
|
||||
"[error=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
omgr.createObject(TestObject.class, sub, false);
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
TestServer server = new TestServer();
|
||||
try {
|
||||
server.init();
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to initialize server.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
// the path to the config file
|
||||
protected final static String CONFIG_PATH =
|
||||
"rsrc/config/cocktail/cher/test/server";
|
||||
|
||||
// the config key for our list of invocation provider mappings
|
||||
protected final static String PROVIDERS_KEY = CONFIG_KEY + ".providers";
|
||||
}
|
||||
Reference in New Issue
Block a user