Finished wiring up oid list tracking; made shutdown() work on the cher

server; added an easy mechanism to write test modules and invoke them on
the server.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@192 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-08 00:28:49 +00:00
parent 91d5813b37
commit 6fe9ad8a6e
7 changed files with 410 additions and 24 deletions
@@ -0,0 +1,73 @@
//
// $Id: RefTest.java,v 1.1 2001/08/08 00:28:49 mdb Exp $
package com.threerings.cocktail.cher.server.test;
import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.cher.server.CherServer;
/**
* Tests the oid list reference tracking code.
*/
public class RefTest
implements Runnable, Subscriber
{
public void run ()
{
// create two test objects
CherServer.omgr.createObject(TestObject.class, this, true);
CherServer.omgr.createObject(TestObject.class, this, true);
}
public void objectAvailable (DObject object)
{
// keep references to our test objects
if (_objone == null) {
_objone = (TestObject)object;
} else {
_objtwo = (TestObject)object;
// now that we have both objects, set up the references
_objone.addToList(_objtwo.getOid());
_objtwo.addToList(_objone.getOid());
}
}
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Ack. Unable to create object [cause=" + cause + "].");
}
public boolean handleEvent (DEvent event, DObject target)
{
// Log.info("Got event: " + event);
// once we receive the second object added we can destroy the
// target object to see if the reference is cleaned up
if (event instanceof ObjectAddedEvent && target == _objtwo) {
Log.info("Destroying object two " + _objtwo + ".");
_objtwo.destroy();
} else if (event instanceof ObjectDestroyedEvent) {
if (target == _objtwo) {
Log.info("List won't yet be empty: " + _objone.list);
} else {
Log.info("Other object destroyed.");
// go bye bye
CherServer.shutdown();
}
} else if (event instanceof ObjectRemovedEvent) {
Log.info("List should be empty: " + _objone.list);
// finally destroy the other object to complete the circle
_objone.destroy();
}
return true;
}
protected TestObject _objone;
protected TestObject _objtwo;
}
@@ -1,5 +1,5 @@
//
// $Id: TestObject.dobj,v 1.2 2001/07/19 05:56:20 mdb Exp $
// $Id: TestObject.dobj,v 1.3 2001/08/08 00:28:49 mdb Exp $
package com.threerings.cocktail.cher.server.test;
@@ -12,12 +12,12 @@ import com.threerings.cocktail.cher.dobj.*;
public class TestObject extends DObject
{
public static final String FOO = "foo";
public static final String BAR = "bar";
public static final String LIST = "list";
public int foo;
public static final String BAR = "bar";
public String bar;
public OidList list = new OidList();
public void setFoo (int foo)
{
@@ -29,8 +29,29 @@ public class TestObject extends DObject
requestAttributeChange(BAR, bar);
}
public String toString ()
/**
* Requests that the specified oid be added to the
* <code>list</code> oid list.
*/
public void addToList (int oid)
{
return "[foo=" + foo + ", bar=" + bar + "]";
requestOidAdd(LIST, oid);
}
/**
* Requests that the specified oid be removed from the
* <code>list</code> oid list.
*/
public void removeFromList (int oid)
{
requestOidRemove(LIST, oid);
}
protected void toString (StringBuffer buf)
{
super.toString(buf);
buf.append(", foo=").append(foo);
buf.append(", bar=").append(bar);
buf.append(", list=").append(list);
}
}