Revamped distributed object creation. There was no particular reason to create

distributed objects by reflection since we don't allow clients to create
objects, furthermore we needn't do it asynchronously. The object creation
methods were moved into the server-side only interface and made "immediate", so
the caller creates a derived instance of DObject and registers it with the
system instead of creating it with a Subscriber callback.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4342 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-08-23 23:46:48 +00:00
parent 1f204669c4
commit bc9f53396c
19 changed files with 304 additions and 589 deletions
@@ -20,13 +20,7 @@ public class JabberServer extends CrowdServer
super.init();
// create a single location
plreg.createPlace(
new JabberConfig(), new PlaceRegistry.CreationObserver() {
public void placeCreated (PlaceObject place, PlaceManager pmgr) {
Log.info("Created chat room " + pmgr.where() + ".");
_place = pmgr;
}
});
_pmgr = plreg.createPlace(new JabberConfig());
}
public static void main (String[] args)
@@ -41,5 +35,5 @@ public class JabberServer extends CrowdServer
}
}
protected PlaceManager _place;
protected PlaceManager _pmgr;
}
@@ -110,14 +110,8 @@ public class TestClient
{
Log.info("Got event [event=" + event + "].");
if (event instanceof AttributeChangedEvent) {
// request to destroy the object
_client.getDObjectManager().destroyObject(event.getTargetOid());
} else {
// request that we log off
_client.logoff(true);
}
// request that we log off
_client.logoff(true);
}
// documentation inherited from interface
@@ -31,45 +31,13 @@ import com.threerings.presents.dobj.*;
* A simple test case for the dobjmgr.
*/
public class DOMTest extends TestCase
implements Subscriber<TestObject>, AttributeChangeListener,
ElementUpdateListener
implements AttributeChangeListener, ElementUpdateListener
{
public DOMTest ()
{
super(DOMTest.class.getName());
}
public void objectAvailable (TestObject object)
{
// add ourselves as a listener
_test = object;
_test.addListener(this);
// test transactions
_test.startTransaction();
_test.setFoo(99);
_test.setBar("hoopie");
_test.commitTransaction();
// set some elements
_test.setIntsAt(15, 3);
_test.setIntsAt(5, 2);
_test.setIntsAt(1, 0);
_test.setStringsAt("Hello", 0);
_test.setStringsAt("Goodbye", 1);
_test.setStringsAt(null, 1);
// now set some values straight up
_test.setFoo(25);
_test.setBar("howdy");
}
public void requestFailed (int oid, ObjectAccessException cause)
{
fail("Request failed: " + cause);
_omgr.harshShutdown();
}
public void attributeChanged (AttributeChangedEvent event)
{
assertTrue(fields[_fcount] + " == " + values[_fcount],
@@ -91,11 +59,29 @@ public class DOMTest extends TestCase
public void runTest ()
{
// request that a new TestObject be created
_omgr.createObject(TestObject.class, this);
// request that a new TestObject be registered
_test = _omgr.registerObject(new TestObject());
// or for fun you can try this bogus create request
// _omgr.createObject(Integer.class, sub);
// add ourselves as a listener
_test.addListener(this);
// test transactions
_test.startTransaction();
_test.setFoo(99);
_test.setBar("hoopie");
_test.commitTransaction();
// set some elements
_test.setIntsAt(15, 3);
_test.setIntsAt(5, 2);
_test.setIntsAt(1, 0);
_test.setStringsAt("Hello", 0);
_test.setStringsAt("Goodbye", 1);
_test.setStringsAt(null, 1);
// now set some values straight up
_test.setFoo(25);
_test.setBar("howdy");
// and run the object manager
_omgr.run();
@@ -33,47 +33,18 @@ import com.threerings.presents.dobj.*;
* an oid list.
*/
public class DestroyedRefTest extends TestCase
implements Subscriber<TestObject>, EventListener
implements EventListener
{
public static Test suite ()
{
return new DestroyedRefTest();
}
public DestroyedRefTest ()
{
super(DestroyedRefTest.class.getName());
}
public void objectAvailable (TestObject object)
{
// add ourselves as an event listener
object.addListener(this);
// keep references to our test objects
if (_objone == null) {
_objone = object;
} else {
_objtwo = object;
// 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.");
_objtwo.addToList(_objone.getOid());
// now that we have both objects, try to set up the reference.
// first we queue up a destroy event for object two, then we
// try to reference it on object one's oid list
_objtwo.destroy();
_objone.addToList(_objtwo.getOid());
// finally dispatch an event on which we can trigger our exit
_objone.setFoo(1);
}
}
public void requestFailed (int oid, ObjectAccessException cause)
{
fail("Ack. Unable to create object [cause=" + cause + "].");
}
public void eventReceived (DEvent event)
{
int toid = event.getTargetOid();
@@ -99,20 +70,31 @@ public class DestroyedRefTest extends TestCase
public void runTest ()
{
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
_objone = _omgr.registerObject(new TestObject());
_objone.addListener(this);
_objtwo = _omgr.registerObject(new TestObject());
_objtwo.addListener(this);
// 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.");
_objtwo.addToList(_objone.getOid());
// now that we have both objects, try to set up the reference. first
// we queue up a destroy event for object two, then we try to reference
// it on object one's oid list
_objtwo.destroy();
_objone.addToList(_objtwo.getOid());
// finally dispatch an event on which we can trigger our exit
_objone.setFoo(1);
// and run the object manager
_omgr.run();
}
public static Test suite ()
{
return new DestroyedRefTest();
}
protected TestObject _objone;
protected TestObject _objtwo;
protected TestObject _objone, _objtwo;
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -31,35 +31,18 @@ import com.threerings.presents.dobj.*;
* Tests the oid list reference tracking code.
*/
public class RefTest extends TestCase
implements Subscriber<TestObject>, EventListener
implements EventListener
{
public static Test suite ()
{
return new RefTest();
}
public RefTest ()
{
super(RefTest.class.getName());
}
public void objectAvailable (TestObject object)
{
// add ourselves as an event listener to our subscribed object
object.addListener(this);
// keep references to our test objects
if (_objone == null) {
_objone = object;
} else {
_objtwo = 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)
{
fail("Ack. Unable to create object [cause=" + cause + "].");
}
public void eventReceived (DEvent event)
{
// Log.info("Got event: " + event);
@@ -93,18 +76,19 @@ public class RefTest extends TestCase
public void runTest ()
{
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
_objone = _omgr.registerObject(new TestObject());
_objone.addListener(this);
_objtwo = _omgr.registerObject(new TestObject());
_objtwo.addListener(this);
// now that we have both objects, set up the references
_objone.addToList(_objtwo.getOid());
_objtwo.addToList(_objone.getOid());
// and run the object manager
_omgr.run();
}
public static Test suite ()
{
return new RefTest();
}
protected TestObject _objone;
protected TestObject _objtwo;
@@ -38,16 +38,7 @@ public class TestServer extends PresentsServer
invmgr.registerDispatcher(new TestDispatcher(new TestProvider()), true);
// create a test object
Subscriber<TestObject> sub = new Subscriber<TestObject>() {
public void objectAvailable (TestObject object) {
testobj = object;
}
public void requestFailed (int oid, ObjectAccessException cause) {
Log.warning("Unable to create test object " +
"[error=" + cause + "].");
}
};
omgr.createObject(TestObject.class, sub);
testobj = omgr.registerObject(new TestObject());
}
public static void main (String[] args)