Some testing code.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@31 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-06-09 23:39:42 +00:00
parent 6a1de87f2a
commit cd9135171a
2 changed files with 103 additions and 0 deletions
@@ -0,0 +1,59 @@
//
// $Id: DOMTest.java,v 1.1 2001/06/09 23:39:42 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.*;
/**
* A simple test case for the dobjmgr.
*/
public class DOMTest implements Subscriber
{
public void objectAvailable (DObject object)
{
Log.info("Object available: " + object);
// set some values
TestObject to = (TestObject)object;
to.setFoo(25);
to.setBar("howdy");
}
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.info("Request failed: " + cause);
omgr.shutdown();
}
public boolean handleEvent (DEvent event, DObject target)
{
Log.info("Got event [event=" + event + ", target=" + target + "].");
// if this is the second event, request a shutdown
AttributeChangedEvent ace = (AttributeChangedEvent)event;
if (ace.getName().equals(TestObject.BAR)) {
omgr.shutdown();
}
return true;
}
public static CherDObjectMgr omgr = new CherDObjectMgr();
public static void main (String[] args)
{
// create our subscriber who will do things
DOMTest sub = new DOMTest();
// request that a new TestObject be created
omgr.createObject(TestObject.class, sub, true);
// or for fun you can try this bogus create request
// omgr.createObject(Integer.class, sub, true);
// and run the object manager
omgr.run();
}
}
@@ -0,0 +1,44 @@
//
// $Id: TestObject.dobj,v 1.1 2001/06/09 23:39:42 mdb Exp $
package com.threerings.cocktail.cher.server.test;
import com.threerings.cocktail.cher.dobj.*;
/**
* I use this to test until I get the actual DObject generation script
* working.
*/
public class TestObject extends DObject
{
public static final String FOO = "foo";
public int foo;
public static final String BAR = "bar";
public String bar;
public void setFoo (int foo)
{
// generate an attribute changed event
AttributeChangedEvent event = new AttributeChangedEvent(
_oid, FOO, new Integer(foo));
// and dispatch it to our dobjmgr
_mgr.postEvent(event);
}
public void setBar (String bar)
{
// generate an attribute changed event
AttributeChangedEvent event = new AttributeChangedEvent(
_oid, BAR, bar);
// and dispatch it to our dobjmgr
_mgr.postEvent(event);
}
public String toString ()
{
return "[foo=" + foo + ", bar=" + bar + "]";
}
}