Revamped "persona selection" support. Things now actually work, and in as
sensible a way as we can hope for. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1717 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Client.java,v 1.28 2002/08/14 19:07:54 mdb Exp $
|
||||
// $Id: Client.java,v 1.29 2002/09/19 23:36:59 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -333,20 +333,7 @@ public class Client
|
||||
protected void clockDeltaEstablished ()
|
||||
{
|
||||
// initialize our invocation director
|
||||
ResultListener rl = new ResultListener() {
|
||||
public void requestCompleted (Object result) {
|
||||
// keep this around
|
||||
_clobj = (ClientObject)result;
|
||||
// let the client know that logon has now fully succeeded
|
||||
notifyObservers(Client.CLIENT_DID_LOGON, null);
|
||||
}
|
||||
|
||||
public void requestFailed (Exception cause) {
|
||||
// pass the buck onto the listeners
|
||||
notifyObservers(Client.CLIENT_FAILED_TO_LOGON, cause);
|
||||
}
|
||||
};
|
||||
_invdir.init(_comm.getDObjectManager(), _cloid, rl);
|
||||
_invdir.init(_comm.getDObjectManager(), _cloid, this);
|
||||
|
||||
// we can't quite call initialization completed at this point
|
||||
// because we need for the invocation director to fully initialize
|
||||
@@ -354,6 +341,42 @@ public class Client
|
||||
// client loose to do things like request invocation services
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation director when it successfully subscribes
|
||||
* to the client object immediately following logon.
|
||||
*/
|
||||
protected void gotClientObject (ClientObject clobj)
|
||||
{
|
||||
// keep this around
|
||||
_clobj = clobj;
|
||||
|
||||
// let the client know that logon has now fully succeeded
|
||||
notifyObservers(Client.CLIENT_DID_LOGON, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation director if it fails to subscribe to the
|
||||
* client object after logon.
|
||||
*/
|
||||
protected void getClientObjectFailed (Exception cause)
|
||||
{
|
||||
// pass the buck onto the listeners
|
||||
notifyObservers(Client.CLIENT_FAILED_TO_LOGON, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation director when it discovers that the client
|
||||
* object has changed.
|
||||
*/
|
||||
protected void clientObjectDidChange (ClientObject clobj)
|
||||
{
|
||||
// slip the new client object into the business
|
||||
_clobj = clobj;
|
||||
|
||||
// report to our observers
|
||||
notifyObservers(Client.CLIENT_OBJECT_CHANGED, null);
|
||||
}
|
||||
|
||||
boolean notifyObservers (int code, Exception cause)
|
||||
{
|
||||
final Notifier noty = new Notifier(code, cause);
|
||||
@@ -365,8 +388,11 @@ public class Client
|
||||
}
|
||||
};
|
||||
|
||||
// we need to run immediately if this is WILL_LOGOFF
|
||||
if (code == CLIENT_WILL_LOGOFF) {
|
||||
// we need to run immediately if this is WILL_LOGOFF or if we have
|
||||
// no invoker (which currently only happens in some really obscure
|
||||
// circumstances where we're using a Client instance on the server
|
||||
// so that we can sort of pretend to be a real client)
|
||||
if (code == CLIENT_WILL_LOGOFF || _invoker == null) {
|
||||
unit.run();
|
||||
return noty.getRejected();
|
||||
|
||||
@@ -475,6 +501,12 @@ public class Client
|
||||
}
|
||||
break;
|
||||
|
||||
case CLIENT_OBJECT_CHANGED:
|
||||
if (obs instanceof ClientObserver) {
|
||||
((ClientObserver)obs).clientObjectDidChange(Client.this);
|
||||
}
|
||||
break;
|
||||
|
||||
case CLIENT_CONNECTION_FAILED:
|
||||
if (obs instanceof ClientObserver) {
|
||||
((ClientObserver)obs).clientConnectionFailed(
|
||||
@@ -554,7 +586,8 @@ public class Client
|
||||
// client observer codes
|
||||
static final int CLIENT_DID_LOGON = 0;
|
||||
static final int CLIENT_FAILED_TO_LOGON = 1;
|
||||
static final int CLIENT_CONNECTION_FAILED = 2;
|
||||
static final int CLIENT_WILL_LOGOFF = 3;
|
||||
static final int CLIENT_DID_LOGOFF = 4;
|
||||
static final int CLIENT_OBJECT_CHANGED = 2;
|
||||
static final int CLIENT_CONNECTION_FAILED = 3;
|
||||
static final int CLIENT_WILL_LOGOFF = 4;
|
||||
static final int CLIENT_DID_LOGOFF = 5;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ClientAdapter.java,v 1.3 2001/10/11 04:07:52 mdb Exp $
|
||||
// $Id: ClientAdapter.java,v 1.4 2002/09/19 23:36:59 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -24,6 +24,11 @@ public class ClientAdapter implements ClientObserver
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void clientConnectionFailed (Client client, Exception cause)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ClientObserver.java,v 1.5 2002/05/16 18:17:27 shaper Exp $
|
||||
// $Id: ClientObserver.java,v 1.6 2002/09/19 23:36:59 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -43,6 +43,14 @@ public interface ClientObserver extends SessionObserver
|
||||
*/
|
||||
public void clientFailedToLogon (Client client, Exception cause);
|
||||
|
||||
/**
|
||||
* For systems that allow switching screen names after logon, this
|
||||
* method is called whenever a screen name change takes place to
|
||||
* report that the client object has been replaced to potential
|
||||
* client-side subscribers.
|
||||
*/
|
||||
public void clientObjectDidChange (Client client);
|
||||
|
||||
/**
|
||||
* Called when the connection to the server went away for some
|
||||
* unexpected reason. This will be followed by a call to
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: InvocationDirector.java,v 1.21 2002/08/14 19:07:54 mdb Exp $
|
||||
// $Id: InvocationDirector.java,v 1.22 2002/09/19 23:36:59 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -20,10 +20,12 @@ import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
import com.threerings.presents.dobj.DSet;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.InvocationNotificationEvent;
|
||||
import com.threerings.presents.dobj.InvocationRequestEvent;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
import com.threerings.presents.dobj.MessageEvent;
|
||||
import com.threerings.presents.dobj.ObjectAccessException;
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
|
||||
@@ -41,25 +43,22 @@ public class InvocationDirector
|
||||
* manager will send and receive events.
|
||||
* @param cloid the oid of the object on which invocation
|
||||
* notifications as well as invocation responses will be received.
|
||||
* @param initListener a result listener that will be notified when
|
||||
* the invocation director is up and running (meaning it has
|
||||
* subscribed successfully to the client object and is ready to
|
||||
* process invocation requests); or when initialization has failed.
|
||||
* @param client a reference to the client for whom we're doing our
|
||||
* business.
|
||||
*/
|
||||
public void init (DObjectManager omgr, final int cloid,
|
||||
final ResultListener initListener)
|
||||
public void init (DObjectManager omgr, final int cloid, Client client)
|
||||
{
|
||||
// keep this for later
|
||||
// keep these for later
|
||||
_omgr = omgr;
|
||||
_client = client;
|
||||
|
||||
// add ourselves as a subscriber to the client object
|
||||
_omgr.subscribeToObject(cloid, new Subscriber() {
|
||||
public void objectAvailable (DObject object)
|
||||
{
|
||||
public void objectAvailable (DObject object) {
|
||||
// keep a handle on this bad boy
|
||||
_clobj = (ClientObject)object;
|
||||
|
||||
// add ourselves as a message listener
|
||||
// add ourselves as an event listener
|
||||
_clobj.addListener(InvocationDirector.this);
|
||||
|
||||
// assign a mapping to already registered receivers
|
||||
@@ -67,16 +66,16 @@ public class InvocationDirector
|
||||
|
||||
// let the client know that we're ready to go now that
|
||||
// we've got our subscription to the client object
|
||||
initListener.requestCompleted(object);
|
||||
_client.gotClientObject(_clobj);
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
public void requestFailed (int oid, ObjectAccessException cause) {
|
||||
// aiya! we were unable to subscribe to the client object.
|
||||
// we're hosed, hosed, hosed
|
||||
Log.warning("Invocation director unable to subscribe to " +
|
||||
"client object [cloid=" + cloid + "]!");
|
||||
initListener.requestFailed(cause);
|
||||
"client object [cloid=" + cloid +
|
||||
", cause=" + cause + "]!");
|
||||
_client.getClientObjectFailed(cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -215,6 +214,13 @@ public class InvocationDirector
|
||||
(InvocationNotificationEvent)event;
|
||||
handleInvocationNotification(
|
||||
ine.getReceiverId(), ine.getMethodId(), ine.getArgs());
|
||||
|
||||
} else if (event instanceof MessageEvent) {
|
||||
MessageEvent mevt = (MessageEvent)event;
|
||||
if (mevt.getName().equals(ClientObject.CLOBJ_CHANGED)) {
|
||||
handleClientObjectChanged(
|
||||
((Integer)mevt.getArgs()[0]).intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +289,49 @@ public class InvocationDirector
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server has informed us that our previous client
|
||||
* object is going the way of the Dodo because we're changing screen
|
||||
* names. We subscribe to the new object and report to the client once
|
||||
* we've got our hands on it.
|
||||
*/
|
||||
protected void handleClientObjectChanged (int newCloid)
|
||||
{
|
||||
// subscribe to the new client object
|
||||
_omgr.subscribeToObject(newCloid, new Subscriber() {
|
||||
public void objectAvailable (DObject object) {
|
||||
// grab a reference to our old receiver registrations
|
||||
DSet receivers = _clobj.receivers;
|
||||
|
||||
// replace the client object
|
||||
_clobj = (ClientObject)object;
|
||||
|
||||
// add ourselves as an event listener
|
||||
_clobj.addListener(InvocationDirector.this);
|
||||
|
||||
// reregister our receivers
|
||||
try {
|
||||
_clobj.startTransaction();
|
||||
Iterator iter = receivers.entries();
|
||||
while (iter.hasNext()) {
|
||||
_clobj.addToReceivers((Registration)iter.next());
|
||||
}
|
||||
} finally {
|
||||
_clobj.commitTransaction();
|
||||
}
|
||||
|
||||
// and report the switcheroo back to the client
|
||||
_client.clientObjectDidChange(_clobj);
|
||||
}
|
||||
|
||||
public void requestFailed (int oid, ObjectAccessException cause) {
|
||||
Log.warning("Aiya! Unable to subscribe to changed " +
|
||||
"client object [cloid=" + oid +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to generate monotonically increasing invocation request ids.
|
||||
*/
|
||||
protected synchronized short nextRequestId ()
|
||||
@@ -301,6 +350,9 @@ public class InvocationDirector
|
||||
/** The distributed object manager with which we interact. */
|
||||
protected DObjectManager _omgr;
|
||||
|
||||
/** The client for whom we're working. */
|
||||
protected Client _client;
|
||||
|
||||
/** Our client object; invocation responses and notifications are
|
||||
* received on this object. */
|
||||
protected ClientObject _clobj;
|
||||
|
||||
Reference in New Issue
Block a user