Modified shutdown handling such that the place manager now listens for
place object death and lets the place registry know to unmap it during its shutdown process. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@544 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
//
|
//
|
||||||
// $Id: PlaceManager.java,v 1.20 2001/10/24 00:38:01 mdb Exp $
|
// $Id: PlaceManager.java,v 1.21 2001/10/24 00:57:39 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.crowd.server;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.threerings.presents.dobj.*;
|
import com.threerings.presents.dobj.MessageListener;
|
||||||
|
import com.threerings.presents.dobj.MessageEvent;
|
||||||
|
import com.threerings.presents.dobj.OidListListener;
|
||||||
|
import com.threerings.presents.dobj.ObjectAddedEvent;
|
||||||
|
import com.threerings.presents.dobj.ObjectRemovedEvent;
|
||||||
|
|
||||||
import com.threerings.crowd.Log;
|
import com.threerings.crowd.Log;
|
||||||
import com.threerings.crowd.data.*;
|
import com.threerings.crowd.data.*;
|
||||||
@@ -26,9 +30,9 @@ import com.threerings.crowd.data.*;
|
|||||||
* basis for place-based access control.
|
* basis for place-based access control.
|
||||||
*
|
*
|
||||||
* <p> A derived class is expected to handle initialization, cleanup and
|
* <p> A derived class is expected to handle initialization, cleanup and
|
||||||
* operational functionality via the calldown functions {@link
|
* operational functionality via the calldown functions {@link #didInit},
|
||||||
* #didStartup}, {@link #willShutdown}, and {@link #didShutdown} as well
|
* {@link #didStartup}, and {@link #didShutdown} as well as through event
|
||||||
* as through event listeners.
|
* listeners.
|
||||||
*/
|
*/
|
||||||
public class PlaceManager
|
public class PlaceManager
|
||||||
implements MessageListener, OidListListener
|
implements MessageListener, OidListListener
|
||||||
@@ -119,14 +123,22 @@ public class PlaceManager
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// not called at present but will eventually be part of the shutdown
|
/**
|
||||||
// and cleanup process
|
* Causes the place object being managed by this place manager to be
|
||||||
protected void willShutdown ()
|
* destroyed and the place manager to shut down.
|
||||||
|
*/
|
||||||
|
public void shutdown ()
|
||||||
{
|
{
|
||||||
|
// destroy the object and everything will follow from that
|
||||||
|
CrowdServer.omgr.destroyObject(_plobj.getOid());
|
||||||
}
|
}
|
||||||
|
|
||||||
// not called at present but will eventually be part of the shutdown
|
/**
|
||||||
// and cleanup process
|
* Called when this place has been destroyed and the place manager has
|
||||||
|
* shut down (via a call to {@link #shutdown}). Derived classes can
|
||||||
|
* override this method and perform any necessary shutdown time
|
||||||
|
* processing.
|
||||||
|
*/
|
||||||
protected void didShutdown ()
|
protected void didShutdown ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -282,6 +294,19 @@ public class PlaceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles place destruction. We shut ourselves down and ask the place
|
||||||
|
* registry to unmap us.
|
||||||
|
*/
|
||||||
|
public void objectDestroyed (ObjectDestroyedEvent event)
|
||||||
|
{
|
||||||
|
// unregister ourselves
|
||||||
|
_registry.unmapPlaceManager(this);
|
||||||
|
|
||||||
|
// let our derived classes shut themselves down
|
||||||
|
didShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a string representation of this manager. Does so in a way
|
* Generates a string representation of this manager. Does so in a way
|
||||||
* that makes it easier for derived classes to add to the string
|
* that makes it easier for derived classes to add to the string
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: PlaceRegistry.java,v 1.14 2001/10/24 00:37:24 mdb Exp $
|
// $Id: PlaceRegistry.java,v 1.15 2001/10/24 00:57:39 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.crowd.server;
|
package com.threerings.crowd.server;
|
||||||
|
|
||||||
@@ -12,8 +12,6 @@ import com.samskivert.util.Queue;
|
|||||||
|
|
||||||
import com.threerings.presents.dobj.DObject;
|
import com.threerings.presents.dobj.DObject;
|
||||||
import com.threerings.presents.dobj.ObjectAccessException;
|
import com.threerings.presents.dobj.ObjectAccessException;
|
||||||
import com.threerings.presents.dobj.ObjectDeathListener;
|
|
||||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
|
||||||
import com.threerings.presents.dobj.Subscriber;
|
import com.threerings.presents.dobj.Subscriber;
|
||||||
|
|
||||||
import com.threerings.crowd.Log;
|
import com.threerings.crowd.Log;
|
||||||
@@ -27,7 +25,7 @@ import com.threerings.crowd.data.PlaceObject;
|
|||||||
* places.
|
* places.
|
||||||
*/
|
*/
|
||||||
public class PlaceRegistry
|
public class PlaceRegistry
|
||||||
implements Subscriber, ObjectDeathListener
|
implements Subscriber
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Used to receive a callback when the place object associated with a
|
* Used to receive a callback when the place object associated with a
|
||||||
@@ -170,10 +168,6 @@ public class PlaceRegistry
|
|||||||
CreationObserver observer = (CreationObserver)tuple.right;
|
CreationObserver observer = (CreationObserver)tuple.right;
|
||||||
PlaceObject plobj = (PlaceObject)object;
|
PlaceObject plobj = (PlaceObject)object;
|
||||||
|
|
||||||
// add ourselves as a destruction listener so that we can clean up
|
|
||||||
// after the place manager when it goes away
|
|
||||||
plobj.addListener(this);
|
|
||||||
|
|
||||||
// stick the manager into our table
|
// stick the manager into our table
|
||||||
_pmgrs.put(plobj.getOid(), pmgr);
|
_pmgrs.put(plobj.getOid(), pmgr);
|
||||||
|
|
||||||
@@ -203,33 +197,18 @@ public class PlaceRegistry
|
|||||||
", cause=" + cause + "].");
|
", cause=" + cause + "].");
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public void objectDestroyed (ObjectDestroyedEvent event)
|
|
||||||
{
|
|
||||||
// the place object went away, so we unmap our place manager
|
|
||||||
int placeOid = event.getTargetOid();
|
|
||||||
PlaceManager pmgr = (PlaceManager)_pmgrs.remove(placeOid);
|
|
||||||
if (pmgr == null) {
|
|
||||||
Log.warning("Heard about destruction of object for which " +
|
|
||||||
"no place manager was registered? " +
|
|
||||||
"[oid=" + placeOid + "].");
|
|
||||||
} else {
|
|
||||||
// let our derived classes know what's up
|
|
||||||
placeWasDestroyed(pmgr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the place registry has unmapped a place manager because
|
* Called by the place manager when it has been shut down.
|
||||||
* its associated place object was destroyed. Derived classes may wish
|
|
||||||
* to override this method if they are interested in place (and place
|
|
||||||
* manager) destruction.
|
|
||||||
*
|
|
||||||
* @param pmgr a reference to the place manager that was managing the
|
|
||||||
* destroyed place.
|
|
||||||
*/
|
*/
|
||||||
protected void placeWasDestroyed (PlaceManager pmgr)
|
protected void unmapPlaceManager (PlaceManager pmgr)
|
||||||
{
|
{
|
||||||
|
// remove it from the table
|
||||||
|
if (_pmgrs.remove(pmgr.getPlaceObject().getOid()) == null) {
|
||||||
|
Log.warning("Requested to unmap unmapped place manager " +
|
||||||
|
"[pmgr=" + pmgr + "].");
|
||||||
|
} else {
|
||||||
|
Log.info("Unmapped place manager " + pmgr + ".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A queue of place managers waiting for their place objects. */
|
/** A queue of place managers waiting for their place objects. */
|
||||||
|
|||||||
Reference in New Issue
Block a user