Further wired up the client side of the distributed object system. Removed
the facilities for fetching (without subscribing to) an object. This is done extremely rarely and the user might as well just subscribe and immediately unsubscribe because the dichotomy between fetching and subscribing just served to overly complicate the internals for no good reason. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@30 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,22 +1,99 @@
|
||||
//
|
||||
// $Id: TestClient.java,v 1.2 2001/05/30 23:58:31 mdb Exp $
|
||||
// $Id: TestClient.java,v 1.3 2001/06/09 23:39:03 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.client.test;
|
||||
|
||||
import com.samskivert.util.Queue;
|
||||
|
||||
import com.threerings.cocktail.cher.Log;
|
||||
import com.threerings.cocktail.cher.net.*;
|
||||
import com.threerings.cocktail.cher.client.*;
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
|
||||
import com.threerings.cocktail.cher.server.test.TestObject;
|
||||
|
||||
/**
|
||||
* A standalone test client.
|
||||
*/
|
||||
public class TestClient
|
||||
implements Client.Invoker, ClientObserver, Subscriber
|
||||
{
|
||||
public void invokeLater (Runnable run)
|
||||
{
|
||||
// queue it on up
|
||||
_queue.append(run);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
// loop over our queue, running the runnables
|
||||
while (true) {
|
||||
Runnable run = (Runnable)_queue.get();
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
Log.info("Client did logon [client=" + client + "].");
|
||||
// try subscribing to a test object
|
||||
client.getDObjectManager().subscribeToObject(1, this);
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
{
|
||||
Log.info("Client failed to logon [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public void clientConnectionFailed (Client client, Exception cause)
|
||||
{
|
||||
Log.info("Client connection failed [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean clientWillLogoff (Client client)
|
||||
{
|
||||
Log.info("Client will logoff [client=" + client + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
Log.info("Client did logoff [client=" + client + "].");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
Log.info("Object available: " + object);
|
||||
((TestObject)object).setBar("lawl!");
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
Log.info("Object unavailable [oid=" + oid +
|
||||
", reason=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
Log.info("Got event [event=" + event + ", target=" + target + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
TestClient tclient = new TestClient();
|
||||
UsernamePasswordCreds creds =
|
||||
new UsernamePasswordCreds("test", "test");
|
||||
Client client = new Client(creds);
|
||||
Client client = new Client(creds, tclient);
|
||||
client.addObserver(tclient);
|
||||
client.setServer("localhost", 4007);
|
||||
client.logon();
|
||||
// start up our event processing loop
|
||||
tclient.run();
|
||||
}
|
||||
|
||||
protected Queue _queue = new Queue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user