Switch to new samskivert logging API.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5134 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-05-27 19:25:38 +00:00
parent 821760366f
commit 919112cf88
80 changed files with 440 additions and 573 deletions
@@ -22,13 +22,14 @@
package com.threerings.bureau.client;
import com.samskivert.util.OneLineLogFormatter;
import com.threerings.bureau.Log;
import com.samskivert.util.Queue;
import com.samskivert.util.StringUtil;
import com.threerings.bureau.client.BureauDirector;
import com.threerings.bureau.data.AgentObject;
import com.samskivert.util.RunQueue;
import static com.threerings.bureau.Log.log;
/**
* Extends bureau client minimally and provides a static main function to create a client and
* connect to a server given by system properties.
@@ -91,12 +92,12 @@ public class TestClient extends BureauClient
{
public void start ()
{
Log.info("Starting agent " + StringUtil.toString(_agentObj));
log.info("Starting agent " + StringUtil.toString(_agentObj));
}
public void stop ()
{
Log.info("Stopping agent " + StringUtil.toString(_agentObj));
log.info("Stopping agent " + StringUtil.toString(_agentObj));
}
}
@@ -21,12 +21,15 @@
package com.threerings.bureau.server;
import com.samskivert.util.OneLineLogFormatter;
import com.google.common.collect.Lists;
import com.threerings.bureau.data.AgentObject;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
import com.threerings.bureau.data.AgentObject;
import static com.threerings.bureau.Log.log;
/**
* Uses a TestServer to pound on the BureauRegistry. Sends random sequences of
* startAgent and destroyAgent. Most aspects of the randomness are configurable using system
@@ -43,11 +46,11 @@ public class RegistryTester
{
String val = System.getProperty(name);
if (val == null) {
TestServer.log.info("Property " + name + " is " + defaultVal);
log.info("Property " + name + " is " + defaultVal);
return defaultVal;
}
int ival = Integer.parseInt(val);
TestServer.log.info("Property " + name + " is " + ival);
log.info("Property " + name + " is " + ival);
return ival;
}
@@ -56,9 +59,6 @@ public class RegistryTester
*/
public static void main (String[] args)
{
// make log pretty
OneLineLogFormatter.configureDefaultHandler();
TestServer server = new TestServer();
RegistryTester tester = new RegistryTester(server);
@@ -68,8 +68,7 @@ public class RegistryTester
server.run();
} catch (Exception e) {
TestServer.log.warning("Unable to initialize server.");
TestServer.logStackTrace(e);
log.warning("Unable to initialize server.", e);
}
}
@@ -95,7 +94,7 @@ public class RegistryTester
// TODO: this is not called on Ctrl-C, need a way to shut down gracefully
TestServer.registerShutdowner(new TestServer.Shutdowner() {
public void shutdown () {
TestServer.log.info("Shutting down tests");
log.info("Shutting down tests");
_stop = true;
}
});
@@ -110,9 +109,9 @@ public class RegistryTester
Thread thread = new Thread("Registry test thread") {
public void run () {
TestServer.log.info(getName() + " started");
log.info(getName() + " started");
runTestThread();
TestServer.log.info(getName() + " stopped");
log.info(getName() + " stopped");
}
};
thread.start();
@@ -139,17 +138,17 @@ public class RegistryTester
_rng1 = new Random(seed);
_rng2 = new Random(seed);
TestServer.log.info("Running tests, seed is " + seed);
log.info("Running tests, seed is " + seed);
// runnable that generates N requests to create or destroy agents
Runnable createOrDestroyAgents = new Runnable() {
public void run () {
int ops = 1 + _rng1.nextInt(_maxOps);
TestServer.log.info("Starting " + ops + " agent requests");
log.info("Starting " + ops + " agent requests");
for (int i = 0; i < ops; ++i) {
randomlyCreateOrDestroyAgent();
}
TestServer.log.info("Finished " + ops + " agent requests");
log.info("Finished " + ops + " agent requests");
}
};
@@ -188,13 +187,13 @@ public class RegistryTester
if (size >= _maxAgents ||
(size != 0 && _rng1.nextInt(100) >= _createChance)) {
AgentObject toRemove = _agents.remove(_rng1.nextInt(size));
TestServer.log.info("Removing agent " + toRemove.getOid());
log.info("Removing agent " + toRemove.getOid());
TestServer.breg.destroyAgent(toRemove);
}
else {
AgentObject added = create(_rng1.nextInt(_numBureaus) + 1);
_agents.add(added);
TestServer.log.info("Added agent " + added.getOid());
log.info("Added agent " + added.getOid());
}
}
@@ -22,36 +22,24 @@
package com.threerings.bureau.server;
import com.threerings.presents.server.PresentsServer;
import com.samskivert.util.OneLineLogFormatter;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.threerings.bureau.Log.log;
/**
* Extends a presents server to include a bureau registry.
*/
public class TestServer extends PresentsServer
{
/** We dispatch our log messages through this logger. */
public static Logger log = Logger.getLogger(TestServer.class.getName());
/**
* The bureau registry for the server. Will be null until <code>init</code> is called.
*/
public static BureauRegistry breg;
public static void logStackTrace (Throwable t)
{
log.log(Level.WARNING, t.getMessage(), t);
}
/**
* Creates a new server and runs it.
*/
public static void main (String[] args)
{
// make log pretty
OneLineLogFormatter.configureDefaultHandler();
final TestServer server = new TestServer();
try {
server.init();
@@ -59,8 +47,7 @@ public class TestServer extends PresentsServer
server.run();
} catch (Exception e) {
log.warning("Unable to initialize server.");
logStackTrace(e);
log.warning("Unable to initialize server.", e);
}
}
@@ -30,7 +30,7 @@ import com.threerings.util.Name;
import com.threerings.presents.client.Client;
import com.threerings.presents.net.UsernamePasswordCreds;
import com.threerings.crowd.Log;
import static com.threerings.crowd.Log.log;
/**
* The main point of entry for the Jabber client application. It creates
@@ -62,7 +62,7 @@ public class JabberApp
Client client = _client.getContext().getClient();
// pass them on to the client
Log.info("Using [server=" + server + "].");
log.info("Using [server=" + server + "].");
client.setServer(server, Client.DEFAULT_SERVER_PORTS);
// configure the client with some credentials and logon
@@ -96,8 +96,7 @@ public class JabberApp
// initialize the app
app.init();
} catch (IOException ioe) {
Log.warning("Error initializing application.");
Log.logStackTrace(ioe);
log.warning("Error initializing application.", ioe);
}
// and run it
@@ -32,10 +32,11 @@ import com.threerings.presents.client.*;
import com.threerings.presents.dobj.DObjectManager;
import com.threerings.presents.net.*;
import com.threerings.crowd.Log;
import com.threerings.crowd.chat.client.ChatDirector;
import com.threerings.crowd.util.CrowdContext;
import static com.threerings.crowd.Log.log;
public class TestClient
implements RunQueue, ClientObserver
{
@@ -89,7 +90,7 @@ public class TestClient
public void clientDidLogon (Client client)
{
Log.info("Client did logon [client=" + client + "].");
log.info("Client did logon [client=" + client + "].");
// request to move to a place
_ctx.getLocationDirector().moveTo(15);
@@ -97,30 +98,30 @@ public class TestClient
public void clientObjectDidChange (Client client)
{
Log.info("Client object did change [client=" + client + "].");
log.info("Client object did change [client=" + client + "].");
}
public void clientFailedToLogon (Client client, Exception cause)
{
Log.info("Client failed to logon [client=" + client +
log.info("Client failed to logon [client=" + client +
", cause=" + cause + "].");
}
public void clientConnectionFailed (Client client, Exception cause)
{
Log.info("Client connection failed [client=" + client +
log.info("Client connection failed [client=" + client +
", cause=" + cause + "].");
}
public boolean clientWillLogoff (Client client)
{
Log.info("Client will logoff [client=" + client + "].");
log.info("Client will logoff [client=" + client + "].");
return true;
}
public void clientDidLogoff (Client client)
{
Log.info("Client did logoff [client=" + client + "].");
log.info("Client did logoff [client=" + client + "].");
System.exit(0);
}
@@ -3,10 +3,11 @@
package com.threerings.crowd.server;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.JabberConfig;
import com.threerings.crowd.data.PlaceObject;
import static com.threerings.crowd.Log.log;
/**
* A basic server that creates a single room and sticks everyone in it
* where they can chat with one another.
@@ -30,8 +31,7 @@ public class JabberServer extends CrowdServer
server.init();
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
log.warning("Unable to initialize server.", e);
}
}
@@ -28,11 +28,12 @@ import com.samskivert.util.RunQueue;
import com.threerings.util.Name;
import com.threerings.presents.Log;
import com.threerings.presents.data.TestObject;
import com.threerings.presents.dobj.*;
import com.threerings.presents.net.*;
import static com.threerings.presents.Log.log;
/**
* A standalone test client.
*/
@@ -74,7 +75,7 @@ public class TestClient
public void clientDidLogon (Client client)
{
Log.info("Client did logon [client=" + client + "].");
log.info("Client did logon [client=" + client + "].");
// register ourselves as a test notification receiver
client.getInvocationDirector().registerReceiver(new TestDecoder(this));
@@ -89,10 +90,10 @@ public class TestClient
three.add(5);
service.test(client, "one", 2, three, new TestService.TestFuncListener() {
public void testSucceeded (String one, int two) {
Log.info("Got test response [one=" + one + ", two=" + two + "].");
log.info("Got test response [one=" + one + ", two=" + two + "].");
}
public void requestFailed (String reason) {
Log.info("Urk! Request failed [reason=" + reason + "].");
log.info("Urk! Request failed [reason=" + reason + "].");
}
});
@@ -102,25 +103,25 @@ public class TestClient
public void clientObjectDidChange (Client client)
{
Log.info("Client object did change [client=" + client + "].");
log.info("Client object did change [client=" + client + "].");
}
public void clientDidLogoff (Client client)
{
Log.info("Client did logoff [client=" + client + "].");
log.info("Client did logoff [client=" + client + "].");
System.exit(0);
}
public void objectAvailable (TestObject object)
{
object.addListener(this);
Log.info("Object available: " + object);
log.info("Object available: " + object);
object.setBar("lawl!");
}
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.info("Object unavailable [oid=" + oid +
log.info("Object unavailable [oid=" + oid +
", reason=" + cause + "].");
// nothing to do, so might as well logoff
_client.logoff(true);
@@ -128,7 +129,7 @@ public class TestClient
public void eventReceived (DEvent event)
{
Log.info("Got event [event=" + event + "].");
log.info("Got event [event=" + event + "].");
// request that we log off
_client.logoff(true);
@@ -144,13 +145,13 @@ public class TestClient
// documentation inherited from interface
public void requestFailed (String reason)
{
Log.info("Urk! Request failed [reason=" + reason + "].");
log.info("Urk! Request failed [reason=" + reason + "].");
}
// documentation inherited from interface
public void receivedTest (int one, String two)
{
Log.info("Received test notification [one=" + one +
log.info("Received test notification [one=" + one +
", two=" + two + "].");
}
@@ -24,10 +24,11 @@ package com.threerings.presents.server;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.presents.Log;
import com.threerings.presents.data.TestObject;
import com.threerings.presents.dobj.*;
import static com.threerings.presents.Log.log;
/**
* Tests that the dobjmgr will not allow a destroyed object to be added to
* an oid list.
@@ -51,7 +52,7 @@ public class DestroyedRefTest extends TestCase
// when we get the attribute change, we can exit
if (event instanceof ObjectDestroyedEvent) {
Log.info("The upcoming object added event should be rejected.");
log.info("The upcoming object added event should be rejected.");
} else if (event instanceof ObjectAddedEvent &&
toid == _objtwo.getOid()) {
@@ -78,7 +79,7 @@ public class DestroyedRefTest extends TestCase
// add object one to object two twice in a row to make sure repeated
// adds don't result in the object being listed twice
_objtwo.addToList(_objone.getOid());
Log.info("The following addToList() should be ignored.");
log.info("The following addToList() should be ignored.");
_objtwo.addToList(_objone.getOid());
// now that we have both objects, try to set up the reference. first
@@ -7,10 +7,11 @@ import java.util.ArrayList;
import com.samskivert.util.StringUtil;
import com.threerings.presents.Log;
import com.threerings.presents.client.TestService;
import com.threerings.presents.data.ClientObject;
import static com.threerings.presents.Log.log;
/**
* Implements the server side of the TestProvider interface.
*/
@@ -22,7 +23,7 @@ public class TestManager
TestService.TestOidListener listener)
throws InvocationException
{
Log.info("Handling get test oid [src=" + caller + "].");
log.info("Handling get test oid [src=" + caller + "].");
// issue a test notification just for kicks
TestSender.sendTest(caller, 1, "two");
@@ -35,7 +36,7 @@ public class TestManager
ArrayList<Integer> three, TestService.TestFuncListener listener)
throws InvocationException
{
Log.info("Test request [one=" + one + ", two=" + two +
log.info("Test request [one=" + one + ", two=" + two +
", three=" + StringUtil.toString(three) + "].");
// and issue a response to this invocation request
@@ -21,10 +21,11 @@
package com.threerings.presents.server;
import com.threerings.presents.Log;
import com.threerings.presents.data.TestObject;
import com.threerings.presents.dobj.*;
import static com.threerings.presents.Log.log;
public class TestServer extends PresentsServer
{
public static TestObject testobj;
@@ -52,8 +53,7 @@ public class TestServer extends PresentsServer
server.init();
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
log.warning("Unable to initialize server.", e);
}
}
}