From 4b9477ca91a004e3d0680e175ce17fa08f2a4d37 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 8 Nov 2008 00:07:35 +0000 Subject: [PATCH] RunQueue related updatery. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5523 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/bureau/client/TestClient.java | 63 +++---------------- .../threerings/crowd/client/JabberClient.java | 21 +------ .../threerings/crowd/client/TestClient.java | 29 ++------- .../presents/client/TestClient.java | 37 ++--------- 4 files changed, 22 insertions(+), 128 deletions(-) diff --git a/tests/src/java/com/threerings/bureau/client/TestClient.java b/tests/src/java/com/threerings/bureau/client/TestClient.java index 72ce40956..ec6992ca2 100644 --- a/tests/src/java/com/threerings/bureau/client/TestClient.java +++ b/tests/src/java/com/threerings/bureau/client/TestClient.java @@ -21,9 +21,8 @@ package com.threerings.bureau.client; +import com.samskivert.util.BasicRunQueue; import com.samskivert.util.OneLineLogFormatter; -import com.samskivert.util.Queue; -import com.samskivert.util.RunQueue; import com.samskivert.util.StringUtil; import com.threerings.bureau.data.AgentObject; @@ -36,7 +35,7 @@ import static com.threerings.bureau.Log.log; */ public class TestClient extends BureauClient { - public static void main (String args[]) + public static void main (String[] args) throws java.net.MalformedURLException { // make log pretty @@ -52,53 +51,20 @@ public class TestClient extends BureauClient client.logon(); // run it - client.run(); + ((BasicRunQueue)client.getRunQueue()).run(); } /** - * Implements most basic run queue. Required to instantate a client. - */ - static protected class SimpleRunQueue implements RunQueue - { - public void postRunnable (Runnable r) - { - _queue.append(r); - } - - public boolean isDispatchThread () - { - return _main == Thread.currentThread(); - } - - public void run () - { - _main = Thread.currentThread(); - - while (true) { - Runnable r = _queue.get(); - r.run(); - } - } - - protected Thread _main; - protected Queue _queue = new Queue(); - } - - /** - * The agent class used by our director. Does not actually load any code, just logs the + * The agent class used by our director. Does not actually load any code, just logs the * start/stop requests. */ - static protected class TestAgent extends Agent + protected static class TestAgent extends Agent { - @Override - public void start () - { + @Override public void start () { log.info("Starting agent " + StringUtil.toString(_agentObj)); } - @Override - public void stop () - { + @Override public void stop () { log.info("Stopping agent " + StringUtil.toString(_agentObj)); } } @@ -108,15 +74,7 @@ public class TestClient extends BureauClient */ protected TestClient (String token, String bureauId) { - super(token, bureauId, new SimpleRunQueue()); - } - - /** - * Runs the event loop. - */ - protected void run () - { - ((SimpleRunQueue)_runQueue).run(); + super(token, bureauId, new BasicRunQueue()); } // overridden - creates a simple director @@ -126,12 +84,9 @@ public class TestClient extends BureauClient // just use our test agent exclusively - in the real world, the agent created would depend // on the object's type and/or properties return new BureauDirector(_ctx) { - @Override - public Agent createAgent (AgentObject agentObj) { + @Override public Agent createAgent (AgentObject agentObj) { return new TestAgent(); } }; } - } - diff --git a/tests/src/java/com/threerings/crowd/client/JabberClient.java b/tests/src/java/com/threerings/crowd/client/JabberClient.java index d29fb4029..13929a09a 100644 --- a/tests/src/java/com/threerings/crowd/client/JabberClient.java +++ b/tests/src/java/com/threerings/crowd/client/JabberClient.java @@ -24,7 +24,6 @@ package com.threerings.crowd.client; import java.io.IOException; import java.awt.BorderLayout; -import java.awt.EventQueue; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -50,7 +49,7 @@ import com.threerings.crowd.util.CrowdContext; * extended context implementation. */ public class JabberClient - implements RunQueue, SessionObserver + implements SessionObserver { /** * Initializes a new client and provides it with a frame in which to @@ -74,8 +73,7 @@ public class JabberClient // log off when they close the window _frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing (WindowEvent evt) { + @Override public void windowClosing (WindowEvent evt) { // if we're logged on, log off if (_client.isLoggedOn()) { _client.logoff(true); @@ -153,7 +151,7 @@ public class JabberClient throws IOException { // create the handles on our various services - _client = new Client(null, this); + _client = new Client(null, RunQueue.AWT); // create our managers and directors _locdir = new LocationDirector(_ctx); @@ -162,19 +160,6 @@ public class JabberClient _chatdir = new ChatDirector(_ctx, _msgmgr, null); } - // documentation inherited from interface RunQueue - public void postRunnable (Runnable run) - { - // queue it on up on the awt thread - EventQueue.invokeLater(run); - } - - // documentation inherited from interface RunQueue - public boolean isDispatchThread () - { - return EventQueue.isDispatchThread(); - } - /** * The context implementation. This provides access to all of the * objects and services that are needed by the operating client. diff --git a/tests/src/java/com/threerings/crowd/client/TestClient.java b/tests/src/java/com/threerings/crowd/client/TestClient.java index efc4f3b41..eeaeef93d 100644 --- a/tests/src/java/com/threerings/crowd/client/TestClient.java +++ b/tests/src/java/com/threerings/crowd/client/TestClient.java @@ -21,9 +21,8 @@ package com.threerings.crowd.client; +import com.samskivert.util.BasicRunQueue; import com.samskivert.util.Config; -import com.samskivert.util.Queue; -import com.samskivert.util.RunQueue; import com.threerings.util.MessageManager; import com.threerings.util.Name; @@ -39,7 +38,7 @@ import com.threerings.crowd.util.CrowdContext; import static com.threerings.crowd.Log.log; public class TestClient - implements RunQueue, ClientObserver + implements ClientObserver { public TestClient (String username) { @@ -47,8 +46,7 @@ public class TestClient _ctx = createContext(); // create the handles on our various services - _client = new Client( - new UsernamePasswordCreds(new Name(username), "test"), this); + _client = new Client(new UsernamePasswordCreds(new Name(username), "test"), _rqueue); _locdir = new LocationDirector(_ctx); _occdir = new OccupantDirector(_ctx); _chatdir = new ChatDirector(_ctx, new MessageManager("rsrc"), "global"); @@ -62,27 +60,11 @@ public class TestClient public void run () { - _main = Thread.currentThread(); - // log on _client.logon(); // loop over our queue, running the runnables - while (true) { - Runnable run = _queue.get(); - run.run(); - } - } - - public void postRunnable (Runnable run) - { - // queue it on up - _queue.append(run); - } - - public boolean isDispatchThread () - { - return _main == Thread.currentThread(); + _rqueue.run(); } public void clientWillLogon (Client client) @@ -193,6 +175,5 @@ public class TestClient protected OccupantDirector _occdir; protected ChatDirector _chatdir; - protected Thread _main; - protected Queue _queue = new Queue(); + protected BasicRunQueue _rqueue = new BasicRunQueue(); } diff --git a/tests/src/java/com/threerings/presents/client/TestClient.java b/tests/src/java/com/threerings/presents/client/TestClient.java index d38f33536..bbf77babd 100644 --- a/tests/src/java/com/threerings/presents/client/TestClient.java +++ b/tests/src/java/com/threerings/presents/client/TestClient.java @@ -23,9 +23,7 @@ package com.threerings.presents.client; import java.util.ArrayList; -import com.samskivert.util.Queue; -import com.samskivert.util.RunQueue; - +import com.samskivert.util.BasicRunQueue; import com.threerings.util.Name; import com.threerings.presents.data.TestObject; @@ -42,7 +40,7 @@ import static com.threerings.presents.Log.log; * A standalone test client. */ public class TestClient - implements RunQueue, SessionObserver, Subscriber, EventListener, + implements SessionObserver, Subscriber, EventListener, TestService.TestOidListener, TestReceiver { public void setClient (Client client) @@ -50,30 +48,6 @@ 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(); - } - - public void run () - { - _main = Thread.currentThread(); - - // loop over our queue, running the runnables - while (true) { - Runnable run = _queue.get(); - run.run(); - } - } - // from interface SessionObserver public void clientWillLogon (Client client) { @@ -203,16 +177,15 @@ public class TestClient TestClient tclient = new TestClient(); UsernamePasswordCreds creds = new UsernamePasswordCreds(new Name("test"), "test"); - Client client = new Client(creds, tclient); + BasicRunQueue rqueue = new BasicRunQueue(); + Client client = new Client(creds, rqueue); tclient.setClient(client); client.addClientObserver(tclient); client.setServer("localhost", Client.DEFAULT_SERVER_PORTS); client.logon(); // start up our event processing loop - tclient.run(); + rqueue.run(); } - protected Thread _main; - protected Queue _queue = new Queue(); protected Client _client; }