Added standalone flag and special standalone logoff method to Client, options to BasicDirector to hold off on initializing directors not needed for standalone mode.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3393 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: BasicDirector.java,v 1.4 2004/08/27 02:20:17 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -40,13 +40,18 @@ public class BasicDirector
|
||||
*/
|
||||
protected BasicDirector (PresentsContext ctx)
|
||||
{
|
||||
// save context
|
||||
_ctx = ctx;
|
||||
|
||||
// listen for session start and end
|
||||
Client client = ctx.getClient();
|
||||
client.addClientObserver(this);
|
||||
|
||||
// if we're already logged on, fire off a call to fetch services
|
||||
if (client.isLoggedOn()) {
|
||||
fetchServices(client);
|
||||
if (isAvailable()) {
|
||||
fetchServices(client);
|
||||
}
|
||||
clientObjectUpdated(client);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +59,9 @@ public class BasicDirector
|
||||
// documentation inherited from interface
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
fetchServices(client);
|
||||
if (isAvailable()) {
|
||||
fetchServices(client);
|
||||
}
|
||||
clientObjectUpdated(client);
|
||||
}
|
||||
|
||||
@@ -69,6 +76,43 @@ public class BasicDirector
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this director is available in standalone mode.
|
||||
*/
|
||||
public void setAvailableInStandalone (boolean available)
|
||||
{
|
||||
_availableInStandalone = available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not this director is available in standalone mode
|
||||
* (defaults to false).
|
||||
*/
|
||||
public boolean isAvailableInStandalone ()
|
||||
{
|
||||
return _availableInStandalone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this director is available in the current mode.
|
||||
*/
|
||||
protected boolean isAvailable ()
|
||||
{
|
||||
return isAvailableInStandalone() || !_ctx.getClient().isStandalone();
|
||||
}
|
||||
|
||||
/**
|
||||
* If this director is not currently available, throws a
|
||||
* {@link RuntimeException}.
|
||||
*/
|
||||
protected void assertAvailable ()
|
||||
{
|
||||
if (!isAvailable()) {
|
||||
throw new RuntimeException(getClass().getName() +
|
||||
" not available in standalone mode!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in three circumstances: when a director is created and we've
|
||||
* already logged on; when we first log on and when the client object
|
||||
@@ -81,11 +125,17 @@ public class BasicDirector
|
||||
/**
|
||||
* Derived directors can override this method and obtain any services
|
||||
* they'll need during their operation via calls to {@link
|
||||
* Client#getService}. It will automatically be called when the client
|
||||
* logs on or when the director is constructed if it is constructed
|
||||
* after the client is already logged on.
|
||||
* Client#getService}. If the director is available, it will automatically
|
||||
* be called when the client logs on or when the director is constructed
|
||||
* if it is constructed after the client is already logged on.
|
||||
*/
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
}
|
||||
|
||||
/** The application context. */
|
||||
protected PresentsContext _ctx;
|
||||
|
||||
/** Whether or not this director is available in standalone mode. */
|
||||
protected boolean _availableInStandalone;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,22 @@ public class Client
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not this client is operating in standalone mode.
|
||||
*/
|
||||
public void setStandalone (boolean standalone)
|
||||
{
|
||||
_standalone = standalone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not this client is operating in a standalone mode.
|
||||
*/
|
||||
public boolean isStandalone ()
|
||||
{
|
||||
return _standalone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the client to communicate with the server on the
|
||||
* supplied hostname/port combination.
|
||||
@@ -408,6 +424,16 @@ public class Client
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* For standalone mode, this notifies observers that the client has logged
|
||||
* off and cleans up.
|
||||
*/
|
||||
public void standaloneLogoff ()
|
||||
{
|
||||
notifyObservers(CLIENT_DID_LOGOFF, null);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link ClientDObjectMgr} when our bootstrap
|
||||
* notification arrives. If the client and server are being run in
|
||||
@@ -556,7 +582,7 @@ public class Client
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void communicatorDidExit ()
|
||||
synchronized void cleanup ()
|
||||
{
|
||||
// we know that prior to the call to this method, the observers
|
||||
// were notified with CLIENT_DID_LOGOFF; that may not have been
|
||||
@@ -571,6 +597,7 @@ public class Client
|
||||
_omgr = null;
|
||||
_clobj = null;
|
||||
_cloid = -1;
|
||||
_standalone = false;
|
||||
// and let our invocation director know we're logged off
|
||||
_invdir.cleanup();
|
||||
}
|
||||
@@ -690,6 +717,9 @@ public class Client
|
||||
/** Our client distributed object. */
|
||||
protected ClientObject _clobj;
|
||||
|
||||
/** Whether or not this client is operating in a standalone mode. */
|
||||
protected boolean _standalone;
|
||||
|
||||
/** The game server host. */
|
||||
protected String _hostname;
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ public class Communicator
|
||||
closeChannel();
|
||||
|
||||
// let the client know when we finally go away
|
||||
_client.communicatorDidExit();
|
||||
_client.cleanup();
|
||||
}
|
||||
|
||||
Log.debug("Reader thread exited.");
|
||||
@@ -270,7 +270,7 @@ public class Communicator
|
||||
|
||||
// let the client know when we finally go away
|
||||
if (_reader == null) {
|
||||
_client.communicatorDidExit();
|
||||
_client.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user