Allow bureau clients to report fatal errors if something goes wrong, like oh I don't know... maybe a disconnection perhaps

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5489 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2008-11-01 00:31:53 +00:00
parent dc99a123ad
commit 055ae0cc98
8 changed files with 71 additions and 2 deletions
@@ -35,6 +35,12 @@ public interface BureauService extends InvocationService
* @see BureauReceiver
*/
void bureauInitialized (Client client, String bureauId);
/**
* Notifies the server that this bureau has encountered a critical error and needs to be shut
* down.
*/
void bureauError (Client client, String message);
/**
* Notify the server that a previosuly requested agent is now created and ready to use.
@@ -68,8 +68,19 @@ public class BureauMarshaller extends InvocationMarshaller
});
}
/** The method id used to dispatch {@link #bureauError} requests. */
public static final int BUREAU_ERROR = 4;
// from interface BureauService
public void bureauError (Client arg1, String arg2)
{
sendRequest(arg1, BUREAU_ERROR, new Object[] {
arg2
});
}
/** The method id used to dispatch {@link #bureauInitialized} requests. */
public static final int BUREAU_INITIALIZED = 4;
public static final int BUREAU_INITIALIZED = 5;
// from interface BureauService
public void bureauInitialized (Client arg1, String arg2)
@@ -70,6 +70,12 @@ public class BureauDispatcher extends InvocationDispatcher<BureauMarshaller>
);
return;
case BureauMarshaller.BUREAU_ERROR:
((BureauProvider)provider).bureauError(
source, (String)args[0]
);
return;
case BureauMarshaller.BUREAU_INITIALIZED:
((BureauProvider)provider).bureauInitialized(
source, (String)args[0]
@@ -45,6 +45,11 @@ public interface BureauProvider extends InvocationProvider
*/
void agentDestroyed (ClientObject caller, int arg1);
/**
* Handles a {@link BureauService#bureauError} request.
*/
void bureauError (ClientObject caller, String arg1);
/**
* Handles a {@link BureauService#bureauInitialized} request.
*/
@@ -101,6 +101,9 @@ public class BureauRegistry
public void bureauInitialized (ClientObject client, String bureauId) {
BureauRegistry.this.bureauInitialized(client, bureauId);
}
public void bureauError (ClientObject caller, String message) {
BureauRegistry.this.bureauError(caller, message);
}
public void agentCreated (ClientObject client, int agentId) {
BureauRegistry.this.agentCreated(client, agentId);
}
@@ -396,6 +399,22 @@ public class BureauRegistry
bureau.summarize();
}
protected void bureauError (ClientObject caller, String message)
{
for (Bureau bureau : _bureaus.values()) {
if (bureau.clientObj == caller) {
log.info(
"Bureau error occurred", "caller", caller.who(), "message", message,
"bureau", bureau.bureauId);
bureau.client.endSession();
return;
}
}
log.warning(
"Bureau error occurred in unregistered bureau", "caller", caller.who(),
"message", message);
}
/**
* Callback for when the bureau client acknowledges the creation of an agent.
*/