Bureaucracy
* Fixed signature of Receiver methods * Implemented create/destroy mechanism and bootstrap request in BureauDirector * Added BureauContext class to expose bureau information on top of usual presents stuff * Added BureauContext implementation in BureauClient * Added code to kick off the director when the client logs on * Added credentials for a bureau logon, which is just a token passed to command line launcher * Added concept of bureau types to distinguish between executable and command line arguments; includes interface BureauRegistry.Launcher * Implemented backend for the registry git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5027 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -2,32 +2,127 @@ package com.threerings.bureau.client;
|
||||
|
||||
import com.threerings.presents.client.BasicDirector;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.util.PresentsContext;
|
||||
import com.threerings.bureau.data.BureauCodes;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.threerings.bureau.data.AgentObject;
|
||||
import com.threerings.bureau.Log;
|
||||
import com.threerings.bureau.util.BureauContext;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
import com.threerings.presents.dobj.ObjectAccessException;
|
||||
|
||||
/**
|
||||
* Allows the server to create and destroy agents on a client.
|
||||
* @see BureauRegistry
|
||||
* @see BureauRegistry
|
||||
*/
|
||||
public class BureauDirector extends BasicDirector
|
||||
implements BureauReceiver
|
||||
implements BureauReceiver, Subscriber<AgentObject>
|
||||
{
|
||||
protected BureauDirector (PresentsContext ctx)
|
||||
public BureauDirector (BureauContext ctx)
|
||||
{
|
||||
super(ctx);
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
// from BureauReceiver
|
||||
public synchronized void createAgent (int agentId)
|
||||
{
|
||||
_ctx.getDObjectManager().subscribeToObject(agentId, this);
|
||||
}
|
||||
|
||||
// from BureauReceiver
|
||||
public synchronized void destroyAgent (int agentId)
|
||||
{
|
||||
Agent agent = null;
|
||||
try {
|
||||
agent = _agents.remove(agentId);
|
||||
// TODO: stop the agent somehow
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Log.warning("Could not create agent [id=" + agentId + "]");
|
||||
Log.logStackTrace(t);
|
||||
// TODO: failure notification?
|
||||
return;
|
||||
}
|
||||
|
||||
_ctx.getDObjectManager().unsubscribeFromObject(agentId, this);
|
||||
doStopAgent(agent);
|
||||
_bureauService.agentDestroyed(_ctx.getClient(), agentId);
|
||||
}
|
||||
|
||||
// from Subscriber
|
||||
public synchronized void objectAvailable (AgentObject agentObject)
|
||||
{
|
||||
int oid = agentObject.getOid();
|
||||
try {
|
||||
Agent agent = new Agent();
|
||||
agent.agentObject = agentObject;
|
||||
doStartAgent(agent);
|
||||
_agents.put(oid, agent);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.warning("Could not create agent [obj=" + agentObject + "]");
|
||||
Log.logStackTrace(e);
|
||||
// TODO: failure notification?
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: post to runqueue?
|
||||
_bureauService.agentCreated(_ctx.getClient(), oid);
|
||||
}
|
||||
|
||||
// from Subscriber
|
||||
public synchronized void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
Log.warning("Could not subscribe to agent [oid=" + oid + "]");
|
||||
Log.logStackTrace(cause);
|
||||
}
|
||||
|
||||
@Override // from BasicDirector
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
super.clientDidLogon(client);
|
||||
_bureauService.bureauInitialized(_ctx.getClient(), _ctx.getBureauId());
|
||||
}
|
||||
|
||||
@Override // from BasicDirector
|
||||
protected void registerServices (Client client)
|
||||
{
|
||||
super.registerServices(client);
|
||||
|
||||
// Require the bureau services
|
||||
client.addServiceGroup(BureauCodes.BUREAU_GROUP);
|
||||
|
||||
// Set up our decoder so we can receive method calls
|
||||
// from the server
|
||||
_ctx.getClient().getInvocationDirector().
|
||||
client.getInvocationDirector().
|
||||
registerReceiver(new BureauDecoder(this));
|
||||
}
|
||||
|
||||
// from BureauReceiver
|
||||
public void createAgent (ClientObject client, int agentId)
|
||||
@Override // from BasicDirector
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
super.fetchServices(client);
|
||||
|
||||
_bureauService = client.getService(BureauService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the agent object is ready and it is time to run his code.
|
||||
*/
|
||||
protected void doStartAgent (Agent agent)
|
||||
{
|
||||
}
|
||||
|
||||
// from BureauReceiver
|
||||
public void destroyAgent (ClientObject client, int agentId)
|
||||
/**
|
||||
* Called when the agent object is being destroyed and the client code should stop
|
||||
* processing.
|
||||
*/
|
||||
protected void doStopAgent (Agent agent)
|
||||
{
|
||||
}
|
||||
|
||||
protected BureauContext _ctx;
|
||||
protected BureauService _bureauService;
|
||||
protected HashIntMap<Agent> _agents = new HashIntMap<Agent>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user