Be sure that we always dispatch subscription responses (success or failure) on

the dobjmgr thread to relieve the caller of the burden of knowing what thread
they are on.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4826 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-09-14 18:17:50 +00:00
parent e4cb816fba
commit 93c89fe0a7
2 changed files with 10 additions and 7 deletions
@@ -820,7 +820,7 @@ public class PresentsClient
// from interface ProxySubscriber // from interface ProxySubscriber
public void requestFailed (int oid, ObjectAccessException cause) public void requestFailed (int oid, ObjectAccessException cause)
{ {
safePostMessage(new FailureResponse(oid, cause.getMessage())); postMessage(new FailureResponse(oid, cause.getMessage()));
} }
// from interface ProxySubscriber // from interface ProxySubscriber
@@ -168,12 +168,8 @@ public class PresentsDObjectMgr
// from interface DObjectManager // from interface DObjectManager
public <T extends DObject> void subscribeToObject (int oid, Subscriber<T> target) public <T extends DObject> void subscribeToObject (int oid, Subscriber<T> target)
{ {
if (oid <= 0) { // queue up an access object event
target.requestFailed(oid, new ObjectAccessException("Invalid oid " + oid + ".")); postEvent(new AccessObjectEvent<T>(oid, target, AccessObjectEvent.SUBSCRIBE));
} else {
// queue up an access object event
postEvent(new AccessObjectEvent<T>(oid, target, AccessObjectEvent.SUBSCRIBE));
}
} }
// from interface DObjectManager // from interface DObjectManager
@@ -804,6 +800,13 @@ public class PresentsDObjectMgr
public boolean applyToObject (DObject target) public boolean applyToObject (DObject target)
throws ObjectAccessException throws ObjectAccessException
{ {
// sanity check; we do this check here rather than in subscribeToObject() to ensure
// that we always dispatch our response on the dobjmgr thread
if (_oid <= 0) {
_target.requestFailed(_oid, new ObjectAccessException("Invalid oid " + _oid + "."));
return false;
}
// look up the target object // look up the target object
@SuppressWarnings("unchecked") T obj = (T)_objects.get(_oid); @SuppressWarnings("unchecked") T obj = (T)_objects.get(_oid);