I write two lines in the morning. I write two lines at night.

I write two lines in the afternoon and it makes me feel alright.
I write two lines in times of peace, I write two in times of war.
I write two lines before I write two lines, and then I write two more.

Bringing ActionScript world into line with the Javver.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4556 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-02-11 03:28:48 +00:00
parent b7e16c86f5
commit cb5fd7ff55
11 changed files with 151 additions and 54 deletions
@@ -54,6 +54,13 @@ public class BasicDirector
}
}
// documentation inherited from interface SessionObserver
public function clientWillLogon (event :ClientEvent) :void
{
var client :Client = event.getClient();
registerServices(client);
}
// documentation inherited from interface SessionObserver
public function clientDidLogon (event :ClientEvent) :void
{
@@ -82,6 +89,15 @@ public class BasicDirector
{
}
/**
* If a director makes use of bootstrap invocation services which are part of a bootstrap
* service group, it should register interest in that group here with a call to {@link
* Client#addServiceGroup}.
*/
protected function registerServices (client :Client) :void
{
}
/**
* Derived directors can override this method and obtain any services
* they'll need during their operation via calls to {@link
+49 -36
View File
@@ -11,6 +11,7 @@ import com.threerings.util.MethodQueue;
import com.threerings.util.ObserverList;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.presents.dobj.DObjectManager;
@@ -35,32 +36,25 @@ public class Client extends EventDispatcher
}
/**
* Registers the supplied observer with this client. While registered
* the observer will receive notifications of state changes within the
* client. The function will refuse to register an already registered
* observer.
* Registers the supplied observer with this client. While registered the observer will receive
* notifications of state changes within the client. The function will refuse to register an
* already registered observer.
*
* @see ClientObserver
* @see SessionObserver
*/
public function addClientObserver (observer :SessionObserver) :void
{
addEventListener(ClientEvent.CLIENT_DID_LOGON,
observer.clientDidLogon);
addEventListener(ClientEvent.CLIENT_OBJECT_CHANGED,
observer.clientObjectDidChange);
addEventListener(ClientEvent.CLIENT_DID_LOGOFF,
observer.clientDidLogoff);
addEventListener(ClientEvent.CLIENT_WILL_LOGON, observer.clientWillLogon);
addEventListener(ClientEvent.CLIENT_DID_LOGON, observer.clientDidLogon);
addEventListener(ClientEvent.CLIENT_OBJECT_CHANGED, observer.clientObjectDidChange);
addEventListener(ClientEvent.CLIENT_DID_LOGOFF, observer.clientDidLogoff);
if (observer is ClientObserver) {
var cliObs :ClientObserver = (observer as ClientObserver);
addEventListener(ClientEvent.CLIENT_FAILED_TO_LOGON,
cliObs.clientFailedToLogon);
addEventListener(ClientEvent.CLIENT_CONNECTION_FAILED,
cliObs.clientConnectionFailed);
addEventListener(ClientEvent.CLIENT_WILL_LOGOFF,
cliObs.clientWillLogoff);
addEventListener(ClientEvent.CLIENT_DID_CLEAR,
cliObs.clientDidClear);
addEventListener(ClientEvent.CLIENT_FAILED_TO_LOGON, cliObs.clientFailedToLogon);
addEventListener(ClientEvent.CLIENT_CONNECTION_FAILED, cliObs.clientConnectionFailed);
addEventListener(ClientEvent.CLIENT_WILL_LOGOFF, cliObs.clientWillLogoff);
addEventListener(ClientEvent.CLIENT_DID_CLEAR, cliObs.clientDidClear);
}
}
@@ -71,22 +65,17 @@ public class Client extends EventDispatcher
*/
public function removeClientObserver (observer :SessionObserver) :void
{
removeEventListener(ClientEvent.CLIENT_DID_LOGON,
observer.clientDidLogon);
removeEventListener(ClientEvent.CLIENT_OBJECT_CHANGED,
observer.clientObjectDidChange);
removeEventListener(ClientEvent.CLIENT_DID_LOGOFF,
observer.clientDidLogoff);
removeEventListener(ClientEvent.CLIENT_WILL_LOGON, observer.clientWillLogon);
removeEventListener(ClientEvent.CLIENT_DID_LOGON, observer.clientDidLogon);
removeEventListener(ClientEvent.CLIENT_OBJECT_CHANGED, observer.clientObjectDidChange);
removeEventListener(ClientEvent.CLIENT_DID_LOGOFF, observer.clientDidLogoff);
if (observer is ClientObserver) {
var cliObs :ClientObserver = (observer as ClientObserver);
removeEventListener(ClientEvent.CLIENT_FAILED_TO_LOGON,
cliObs.clientFailedToLogon);
removeEventListener(ClientEvent.CLIENT_CONNECTION_FAILED,
cliObs.clientConnectionFailed);
removeEventListener(ClientEvent.CLIENT_WILL_LOGOFF,
cliObs.clientWillLogoff);
removeEventListener(ClientEvent.CLIENT_DID_CLEAR,
cliObs.clientDidClear);
removeEventListener(ClientEvent.CLIENT_FAILED_TO_LOGON, cliObs.clientFailedToLogon);
removeEventListener(
ClientEvent.CLIENT_CONNECTION_FAILED, cliObs.clientConnectionFailed);
removeEventListener(ClientEvent.CLIENT_WILL_LOGOFF, cliObs.clientWillLogoff);
removeEventListener(ClientEvent.CLIENT_DID_CLEAR, cliObs.clientDidClear);
}
}
@@ -172,6 +161,26 @@ public class Client extends EventDispatcher
return _invdir;
}
/**
* Returns the set of bootstrap service groups needed by this client.
*/
public function getBootGroups () :Array
{
return _bootGroups;
}
/**
* Marks this client as interested in the specified bootstrap services group. Any services
* registered as bootstrap services with the supplied group name will be included in this
* clients bootstrap services set. This must be called before {@link #logon}.
*/
public function addServiceGroup (group :String) :void
{
if (_bootGroups.indexOf(group) == -1) {
_bootGroups.concat(group);
}
}
public function getService (clazz :Class) :InvocationService
{
if (_bstrap != null) {
@@ -205,8 +214,8 @@ public class Client extends EventDispatcher
}
/**
* Requests that this client connect and logon to the server with
* which it was previously configured.
* Requests that this client connect and logon to the server with which it was previously
* configured.
*
* @return false if we're already logged on.
*/
@@ -217,6 +226,8 @@ public class Client extends EventDispatcher
return false;
}
notifyObservers(ClientEvent.CLIENT_WILL_LOGON);
_comm = new Communicator(this);
_comm.logon();
@@ -229,8 +240,7 @@ public class Client extends EventDispatcher
}
/**
* Requests that the client log off of the server to which it is
* connected.
* Requests that the client log off of the server to which it is connected.
*
* @param abortable if true, the client will call clientWillDisconnect
* on allthe client observers and abort the logoff process if any of them
@@ -403,6 +413,9 @@ public class Client extends EventDispatcher
// protected var _observers :ObserverList =
// new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** The set of bootstrap service groups this client cares about. */
protected var _bootGroups :Array = new Array(InvocationCodes.GLOBAL_GROUP);
/** General startup information provided by the server. */
protected var _bstrap :BootstrapData;
@@ -4,6 +4,7 @@ public class ClientAdapter
implements ClientObserver
{
public function ClientAdapter (
clientWillLogon :Function = null,
clientDidLogon :Function = null,
clientObjectDidChange :Function = null,
clientDidLogoff :Function = null,
@@ -12,6 +13,7 @@ public class ClientAdapter
clientWillLogoff :Function = null,
clientDidClear :Function = null)
{
_clientWillLogon = clientWillLogon;
_clientDidLogon = clientDidLogon;
_clientObjectDidChange = clientObjectDidChange;
_clientDidLogoff = clientDidLogoff;
@@ -21,6 +23,14 @@ public class ClientAdapter
_clientDidClear = clientDidClear;
}
// from ClientObserver
public function clientWillLogon (event :ClientEvent) :void
{
if (_clientWillLogon != null) {
_clientWillLogon(event);
}
}
// from ClientObserver
public function clientDidLogon (event :ClientEvent) :void
{
@@ -77,6 +87,7 @@ public class ClientAdapter
}
}
protected var _clientWillLogon :Function;
protected var _clientDidLogon :Function;
protected var _clientObjectDidChange :Function;
protected var _clientDidLogoff :Function;
@@ -4,6 +4,7 @@ import flash.events.Event;
public class ClientEvent extends Event
{
public static const CLIENT_WILL_LOGON :String = "clientWillLogon";
public static const CLIENT_DID_LOGON :String = "clientDidLogon";
public static const CLIENT_FAILED_TO_LOGON :String = "clientFailedLogon";
public static const CLIENT_OBJECT_CHANGED :String = "clobjChanged";
@@ -244,8 +244,8 @@ public class Communicator
{
logonToPort(true);
// well that's great! let's logon
var req :AuthRequest = new AuthRequest(_client.getCredentials(),
_client.getVersion());
var req :AuthRequest = new AuthRequest(
_client.getCredentials(), _client.getVersion(), _client.getBootGroups());
sendMessage(req);
}
@@ -30,6 +30,11 @@ package com.threerings.presents.client {
*/
public interface SessionObserver
{
/**
* Called immediately before a logon is attempted.
*/
function clientWillLogon (event :ClientEvent) :void;
/**
* Called after the client successfully connected to and authenticated
* with the server. The entire object system is up and running by the