We love to revamp! Created a set of listener interfaces which are used
with distributed objects rather than having a single handleEvent() by which all subscribers are forced to hear about all events. Now one subscribes separately and then adds onesself as any of a few types of listener once they have access to the subscribed object reference. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@439 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDirector.java,v 1.10 2001/10/11 04:07:51 mdb Exp $
|
||||
// $Id: ChatDirector.java,v 1.11 2001/10/12 00:03:02 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.chat;
|
||||
|
||||
@@ -19,7 +19,8 @@ import com.threerings.crowd.util.CrowdContext;
|
||||
* messaging.
|
||||
*/
|
||||
public class ChatDirector
|
||||
implements LocationObserver, Subscriber, InvocationReceiver, ChatCodes
|
||||
implements LocationObserver, MessageListener, InvocationReceiver,
|
||||
ChatCodes
|
||||
{
|
||||
/**
|
||||
* Creates a chat director and initializes it with the supplied
|
||||
@@ -110,54 +111,39 @@ public class ChatDirector
|
||||
return ChatService.tell(_ctx.getClient(), target, message, this);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public boolean locationMayChange (int placeId)
|
||||
{
|
||||
// we accept all location change requests
|
||||
return true;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void locationDidChange (PlaceObject place)
|
||||
{
|
||||
if (_place != null) {
|
||||
// unsubscribe from our old object
|
||||
_place.removeSubscriber(this);
|
||||
// unlisten to our old object
|
||||
_place.removeListener(this);
|
||||
}
|
||||
|
||||
// subscribe to the new object
|
||||
// listen to the new object
|
||||
_place = place;
|
||||
_place.addSubscriber(this);
|
||||
_place.addListener(this);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void locationChangeFailed (int placeId, String reason)
|
||||
{
|
||||
// nothing we care about
|
||||
}
|
||||
|
||||
public void objectAvailable (DObject object)
|
||||
// documentation inherited
|
||||
public void messageReceived (MessageEvent event)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
// we only care about message events
|
||||
if (!(event instanceof MessageEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// and only those of proper name
|
||||
MessageEvent mevt = (MessageEvent)event;
|
||||
String name = mevt.getName();
|
||||
String name = event.getName();
|
||||
if (name.equals(ChatService.SPEAK_NOTIFICATION)) {
|
||||
handleSpeakMessage(mevt.getArgs());
|
||||
handleSpeakMessage(event.getArgs());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +202,5 @@ public class ChatDirector
|
||||
|
||||
protected CrowdContext _ctx;
|
||||
protected PlaceObject _place;
|
||||
|
||||
protected ArrayList _displays = new ArrayList();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LocationDirector.java,v 1.11 2001/10/11 04:07:51 mdb Exp $
|
||||
// $Id: LocationDirector.java,v 1.12 2001/10/12 00:03:02 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
@@ -201,11 +201,6 @@ public class LocationDirector
|
||||
"object; all has gone horribly wrong" +
|
||||
"[cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int cloid = client.getClientOid();
|
||||
client.getDObjectManager().subscribeToObject(cloid, sub);
|
||||
@@ -326,12 +321,6 @@ public class LocationDirector
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
// nothing to do here, but remain subscribed
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void notifyFailure (int placeId, String reason)
|
||||
{
|
||||
for (int i = 0; i < _observers.size(); i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: OccupantManager.java,v 1.6 2001/10/11 04:07:51 mdb Exp $
|
||||
// $Id: OccupantManager.java,v 1.7 2001/10/12 00:03:02 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.threerings.crowd.util.CrowdContext;
|
||||
* what's in the cache.
|
||||
*/
|
||||
public class OccupantManager
|
||||
implements LocationObserver, Subscriber
|
||||
implements LocationObserver, OidListListener
|
||||
{
|
||||
/**
|
||||
* Constructs a new occupant manager with the supplied context.
|
||||
@@ -73,16 +73,16 @@ public class OccupantManager
|
||||
// inherit documentation
|
||||
public void locationDidChange (PlaceObject place)
|
||||
{
|
||||
// unsubscribe from the old place object if there was one
|
||||
// unlisten to the old place object if there was one
|
||||
if (_place != null) {
|
||||
_place.removeSubscriber(this);
|
||||
_place.removeListener(this);
|
||||
// clear out the occupant cache for the previous location
|
||||
_ocache.clear();
|
||||
}
|
||||
|
||||
// subscribe to the new one
|
||||
// listen to the new one
|
||||
_place = place;
|
||||
_place.addSubscriber(this);
|
||||
_place.addListener(this);
|
||||
|
||||
// cache the occupant info for the occupants in this room
|
||||
Iterator iter = _place.occupantInfo.elements();
|
||||
@@ -98,43 +98,17 @@ public class OccupantManager
|
||||
// nothing to do here either
|
||||
}
|
||||
|
||||
// inherit documentation
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
// nothing doing
|
||||
}
|
||||
|
||||
// inherit documentation
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
// nothing doing
|
||||
}
|
||||
|
||||
// inherit documentation
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
// we care about occupant added and removed events only
|
||||
if (event instanceof ObjectAddedEvent) {
|
||||
ObjectAddedEvent oe = (ObjectAddedEvent)event;
|
||||
if (oe.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
handleOccupantAdded(oe.getOid());
|
||||
}
|
||||
|
||||
} else if (event instanceof ObjectRemovedEvent) {
|
||||
ObjectRemovedEvent oe = (ObjectRemovedEvent)event;
|
||||
if (oe.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
handleOccupantRemoved(oe.getOid());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deals with all of the processing when an occupant shows up.
|
||||
*/
|
||||
protected void handleOccupantAdded (int bodyOid)
|
||||
public void objectAdded (ObjectAddedEvent event)
|
||||
{
|
||||
// bail if this isn't for the OCCUPANTS field
|
||||
if (!event.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int bodyOid = event.getOid();
|
||||
Object key = new Integer(bodyOid);
|
||||
|
||||
// get the occupant info from the place object
|
||||
@@ -158,8 +132,14 @@ public class OccupantManager
|
||||
/**
|
||||
* Deals with all of the processing when an occupant leaves.
|
||||
*/
|
||||
protected void handleOccupantRemoved (int bodyOid)
|
||||
public void objectRemoved (ObjectRemovedEvent event)
|
||||
{
|
||||
// bail if this isn't for the OCCUPANTS field
|
||||
if (!event.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int bodyOid = event.getOid();
|
||||
// see if we have an occupant object for this body
|
||||
OccupantInfo info = (OccupantInfo)_ocache.get(bodyOid);
|
||||
if (info == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlaceManager.java,v 1.17 2001/10/11 04:07:51 mdb Exp $
|
||||
// $Id: PlaceManager.java,v 1.18 2001/10/12 00:03:02 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
@@ -28,9 +28,10 @@ import com.threerings.crowd.data.*;
|
||||
* <p> A derived class is expected to handle initialization, cleanup and
|
||||
* operational functionality via the calldown functions {@link
|
||||
* #didStartup}, {@link #willShutdown}, and {@link #didShutdown} as well
|
||||
* as through additions to {@link #handleEvent}.
|
||||
* as through event listeners.
|
||||
*/
|
||||
public class PlaceManager implements Subscriber
|
||||
public class PlaceManager
|
||||
implements MessageListener, OidListListener
|
||||
{
|
||||
/**
|
||||
* Returns a reference to our place configuration object.
|
||||
@@ -101,11 +102,8 @@ public class PlaceManager implements Subscriber
|
||||
// configure the occupant info set
|
||||
plobj.occupantInfo.setElementType(getOccupantInfoClass());
|
||||
|
||||
// we'll want to be included among the place object's subscribers;
|
||||
// we know that we can call addSubscriber() directly because the
|
||||
// place manager is doing all of our initialization on the dobjmgr
|
||||
// thread
|
||||
plobj.addSubscriber(this);
|
||||
// we'll need to hear about place object events
|
||||
plobj.addListener(this);
|
||||
|
||||
// let our derived classes do their thang
|
||||
didStartup();
|
||||
@@ -225,47 +223,48 @@ public class PlaceManager implements Subscriber
|
||||
_msghandlers.put(name, handler);
|
||||
}
|
||||
|
||||
// nothing doing
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
}
|
||||
|
||||
// nothing doing
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
/**
|
||||
* Dispatches message events to registered message handlers. Derived
|
||||
* classes should probably register message handlers rather than
|
||||
* override this method directly.
|
||||
*/
|
||||
public void messageReceived (MessageEvent event)
|
||||
{
|
||||
MessageHandler handler = null;
|
||||
if (_msghandlers != null) {
|
||||
handler = (MessageHandler)_msghandlers.get(event.getName());
|
||||
}
|
||||
if (handler != null) {
|
||||
handler.handleEvent(event, _plobj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes can override this to handle events, but they must
|
||||
* be sure to pass unknown events up to their super class.
|
||||
* Handles occupant arrival into the place. Derived classes may need
|
||||
* to override this method to handle other oid lists in their derived
|
||||
* place objects. They should be sure to call
|
||||
* <code>super.objectAdded</code> if the event is one they don't
|
||||
* explicitly handle.
|
||||
*/
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
public void objectAdded (ObjectAddedEvent event)
|
||||
{
|
||||
// if this is a message event, see if we have a handler for it
|
||||
if (event instanceof MessageEvent) {
|
||||
MessageEvent mevt = (MessageEvent)event;
|
||||
MessageHandler handler = null;
|
||||
if (_msghandlers != null) {
|
||||
handler = (MessageHandler)_msghandlers.get(mevt.getName());
|
||||
}
|
||||
if (handler != null) {
|
||||
handler.handleEvent(mevt, (PlaceObject)target);
|
||||
}
|
||||
|
||||
} else if (event instanceof ObjectAddedEvent) {
|
||||
ObjectAddedEvent oae = (ObjectAddedEvent)event;
|
||||
if (oae.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
bodyEntered(oae.getOid());
|
||||
}
|
||||
|
||||
} else if (event instanceof ObjectRemovedEvent) {
|
||||
ObjectRemovedEvent ore = (ObjectRemovedEvent)event;
|
||||
if (ore.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
bodyLeft(ore.getOid());
|
||||
}
|
||||
if (event.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
bodyEntered(event.getOid());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
/**
|
||||
* Handles occupant departure from the place. Derived classes may need
|
||||
* to override this method to handle other oid lists in their derived
|
||||
* place objects. They should be sure to call
|
||||
* <code>super.objectRemoved</code> if the event is one they don't
|
||||
* explicitly handle.
|
||||
*/
|
||||
public void objectRemoved (ObjectRemovedEvent event)
|
||||
{
|
||||
if (event.getName().equals(PlaceObject.OCCUPANTS)) {
|
||||
bodyLeft(event.getOid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PlaceRegistry.java,v 1.11 2001/10/11 04:07:51 mdb Exp $
|
||||
// $Id: PlaceRegistry.java,v 1.12 2001/10/12 00:03:02 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
@@ -173,13 +173,6 @@ public class PlaceRegistry implements Subscriber
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
// this shouldn't be called because we don't subscribe to
|
||||
// anything, we just want to hear about object creation
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Queue _createq = new Queue();
|
||||
protected HashIntMap _pmgrs = new HashIntMap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user