Implemented object destruction; wired up some missing stuff; created a
test server to make some testing easier; various other cleanups. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@188 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ClientDObjectMgr.java,v 1.4 2001/07/19 07:09:16 mdb Exp $
|
||||
// $Id: ClientDObjectMgr.java,v 1.5 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.client;
|
||||
|
||||
@@ -75,6 +75,13 @@ public class ClientDObjectMgr
|
||||
_comm.postMessage(new ForwardEventRequest(tevent));
|
||||
}
|
||||
|
||||
// inherit documentation from the interface
|
||||
public void destroyObject (int oid)
|
||||
{
|
||||
// forward an object destroyed event to the server
|
||||
postEvent(new ObjectDestroyedEvent(oid));
|
||||
}
|
||||
|
||||
// inherit documentation from the interface
|
||||
public void removedLastSubscriber (DObject obj)
|
||||
{
|
||||
@@ -154,8 +161,29 @@ public class ClientDObjectMgr
|
||||
return;
|
||||
}
|
||||
|
||||
// have the object pass this event on to its subscribers
|
||||
target.notifySubscribers(event);
|
||||
try {
|
||||
// apply the event to the object
|
||||
boolean notify = event.applyToObject(target);
|
||||
|
||||
// if this is an object destroyed event, we need to remove the
|
||||
// object from our object table
|
||||
if (event instanceof ObjectDestroyedEvent) {
|
||||
Log.info("Uncaching destroyed object " +
|
||||
"[oid=" + target.getOid() + "].");
|
||||
_ocache.remove(target.getOid());
|
||||
}
|
||||
|
||||
// have the object pass this event on to its subscribers if
|
||||
// desired
|
||||
if (notify) {
|
||||
target.notifySubscribers(event);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Failure processing event [event=" + event +
|
||||
", target=" + target + "].");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +221,19 @@ public class ClientDObjectMgr
|
||||
*/
|
||||
protected void notifyFailure (int oid)
|
||||
{
|
||||
Log.info("Get failed: " + oid);
|
||||
// let the penders know that the object is not available
|
||||
PendingRequest req = (PendingRequest)_penders.remove(oid);
|
||||
if (req == null) {
|
||||
Log.warning("Failed to get object, but no one cares?! " +
|
||||
"[oid=" + oid + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < req.targets.size(); i++) {
|
||||
Subscriber target = (Subscriber)req.targets.get(i);
|
||||
// and let them know that the object is in
|
||||
target.requestFailed(oid, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Communicator.java,v 1.12 2001/08/03 02:11:20 mdb Exp $
|
||||
// $Id: Communicator.java,v 1.13 2001/08/07 20:38:58 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.client;
|
||||
|
||||
@@ -91,6 +91,9 @@ public class Communicator
|
||||
return;
|
||||
}
|
||||
|
||||
// post a logoff message
|
||||
postMessage(new LogoffRequest());
|
||||
|
||||
// let our reader and writer know that it's time to go
|
||||
if (_reader != null) {
|
||||
// if logoff() is being called by the client as part of a
|
||||
@@ -110,28 +113,12 @@ public class Communicator
|
||||
if (_writer != null) {
|
||||
// shutting down the writer thread is simpler because we can
|
||||
// post a termination message on the queue and be sure that it
|
||||
// will receive it. we do run the risk that it is in the
|
||||
// middle of trying to send a message when we close the
|
||||
// socket, but in theory the send will fail, it will complain
|
||||
// and then it will cleanly exit. if we were uber paranoid
|
||||
// about JVMs misbehaving on simultaneous close()/write(), we
|
||||
// could wait here for the writer thread to exit, but that
|
||||
// makes me even more nervous because I know that some JVMs
|
||||
// don't handle Thread.join() properly (hopefully no one is
|
||||
// still using those JVMs but one can never be sure)
|
||||
// will receive it. when the writer thread has delivered our
|
||||
// logoff request and exited, we will complete the logoff
|
||||
// process by closing our socket and invoking the
|
||||
// clientDidLogoff callback
|
||||
_writer.shutdown();
|
||||
}
|
||||
|
||||
// close down our socket
|
||||
try {
|
||||
_socket.close();
|
||||
} catch (IOException cle) {
|
||||
Log.warning("Error closing failed socket: " + cle);
|
||||
}
|
||||
_socket = null;
|
||||
|
||||
// let the client observers know that we're logged off
|
||||
_client.notifyObservers(Client.CLIENT_DID_LOGOFF, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,8 +213,20 @@ public class Communicator
|
||||
{
|
||||
// clear out our writer reference
|
||||
_writer = null;
|
||||
|
||||
Log.info("Writer thread exited.");
|
||||
|
||||
// now that the writer thread has gone away, we can safely close
|
||||
// our socket and let the client know that the logoff process has
|
||||
// completed
|
||||
try {
|
||||
_socket.close();
|
||||
} catch (IOException cle) {
|
||||
Log.warning("Error closing failed socket: " + cle);
|
||||
}
|
||||
_socket = null;
|
||||
|
||||
// let the client observers know that we're logged off
|
||||
_client.notifyObservers(Client.CLIENT_DID_LOGOFF, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user