Files
narya/tests/src/java/com/threerings/presents/server/RefTest.java
T
Michael Bayne 57b2e93ac3 Modified DObjectManager.createObject() to not afford optional subscription
because subscription no longer means receiving events.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@537 542714f4-19e9-0310-aa3c-eee0fc999fb1
2001-10-24 00:36:40 +00:00

77 lines
2.3 KiB
Java

//
// $Id: RefTest.java,v 1.4 2001/10/24 00:36:40 mdb Exp $
package com.threerings.presents.server.test;
import com.threerings.presents.Log;
import com.threerings.presents.dobj.*;
import com.threerings.presents.server.PresentsServer;
/**
* Tests the oid list reference tracking code.
*/
public class RefTest
implements Runnable, Subscriber, EventListener
{
public void run ()
{
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
}
public void objectAvailable (DObject object)
{
// add ourselves as an event listener to our subscribed object
object.addListener(this);
// 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 void eventReceived (DEvent event)
{
// Log.info("Got event: " + event);
int toid = event.getTargetOid();
// 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 &&
toid == _objtwo.getOid()) {
Log.info("Destroying object two " + _objtwo + ".");
_objtwo.destroy();
} else if (event instanceof ObjectDestroyedEvent) {
if (toid == _objtwo.getOid()) {
Log.info("List won't yet be empty: " + _objone.list);
} else {
Log.info("Other object destroyed.");
// go bye bye
PresentsServer.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();
}
}
protected TestObject _objone;
protected TestObject _objtwo;
}