Bureaucracy smoke test and resulting bug fixes
* Added RegistryTester smoke test which randomly creates and destroys agents in batches * Fixed bug where correct agent id was never making it to client * Implemented Bureau.toString (+refactored summarize method) * Fixed nasty bug due to my assumption that SafeSubscriber =~ Subscriber, they are in fact completely different git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5032 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -49,8 +49,12 @@ public abstract class BureauDirector extends BasicDirector
|
||||
}
|
||||
};
|
||||
|
||||
_subscriber = new SafeSubscriber<AgentObject>(agentId, delegator);
|
||||
_subscriber.subscribe(_ctx.getDObjectManager());
|
||||
Log.info("Subscribing to object " + agentId);
|
||||
|
||||
SafeSubscriber<AgentObject> subscriber =
|
||||
new SafeSubscriber<AgentObject>(agentId, delegator);
|
||||
_subscribers.put(agentId, subscriber);
|
||||
subscriber.subscribe(_ctx.getDObjectManager());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +66,7 @@ public abstract class BureauDirector extends BasicDirector
|
||||
agent = _agents.remove(agentId);
|
||||
|
||||
if (agent == null) {
|
||||
Log.warning("Lost an agent, id " + agentId);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
@@ -71,7 +76,13 @@ public abstract class BureauDirector extends BasicDirector
|
||||
Log.warning("Stopping an agent caused an exception");
|
||||
Log.logStackTrace(t);
|
||||
}
|
||||
_subscriber.unsubscribe(_ctx.getDObjectManager());
|
||||
SafeSubscriber<AgentObject> subscriber = _subscribers.remove(agentId);
|
||||
if (subscriber == null) {
|
||||
Log.warning("Lost a subscriber for agent " + agent);
|
||||
}
|
||||
else {
|
||||
subscriber.unsubscribe(_ctx.getDObjectManager());
|
||||
}
|
||||
_bureauService.agentDestroyed(_ctx.getClient(), agentId);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +93,9 @@ public abstract class BureauDirector extends BasicDirector
|
||||
protected synchronized void objectAvailable (AgentObject agentObject)
|
||||
{
|
||||
int oid = agentObject.getOid();
|
||||
|
||||
Log.info("Object " + oid + " now available");
|
||||
|
||||
Agent agent;
|
||||
try {
|
||||
agent = createAgent(agentObject);
|
||||
@@ -151,5 +165,6 @@ public abstract class BureauDirector extends BasicDirector
|
||||
protected BureauContext _ctx;
|
||||
protected BureauService _bureauService;
|
||||
protected IntMap<Agent> _agents = IntMaps.newHashIntMap();
|
||||
protected SafeSubscriber<AgentObject> _subscriber;
|
||||
protected IntMap<SafeSubscriber<AgentObject>> _subscribers =
|
||||
IntMaps.newHashIntMap();
|
||||
}
|
||||
|
||||
@@ -123,12 +123,12 @@ public class BureauRegistry
|
||||
Bureau bureau = _bureaus.get(agent.bureauId);
|
||||
if (bureau != null && bureau.ready()) {
|
||||
|
||||
_omgr.registerObject(agent);
|
||||
|
||||
Log.info("Bureau ready, sending createAgent " +
|
||||
StringUtil.toString(agent));
|
||||
|
||||
BureauSender.createAgent(bureau.clientObj, agent.getOid());
|
||||
// !TODO: is this the right place to register the object?
|
||||
_omgr.registerObject(agent);
|
||||
bureau.agentStates.put(agent, Bureau.STARTED);
|
||||
|
||||
bureau.summarize();
|
||||
@@ -193,7 +193,7 @@ public class BureauRegistry
|
||||
return;
|
||||
}
|
||||
|
||||
Log.warning("Destroying agent " + StringUtil.toString(agent));
|
||||
Log.info("Destroying agent " + StringUtil.toString(agent));
|
||||
|
||||
// transition the agent to a new state and perform the effect of the transition
|
||||
switch (found.state) {
|
||||
@@ -480,35 +480,48 @@ public class BureauRegistry
|
||||
// The states of the various agents allocated to this bureau
|
||||
Map<AgentObject, Integer> agentStates = Maps.newHashMap();
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[Bureau id=").append(bureauId).append(", client=");
|
||||
if (clientObj == null) {
|
||||
builder.append("null");
|
||||
}
|
||||
else {
|
||||
builder.append(clientObj.getOid());
|
||||
}
|
||||
builder.append(", process=").append(process);
|
||||
builder.append(", totalAgents=").append(agentStates.size());
|
||||
agentSummary(builder.append(", ")).append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
boolean ready ()
|
||||
{
|
||||
return clientObj != null;
|
||||
}
|
||||
|
||||
int countInState (int state)
|
||||
StringBuilder agentSummary (StringBuilder str)
|
||||
{
|
||||
Integer state1 = state;
|
||||
if (!agentStates.containsValue(state1)) {
|
||||
return 0;
|
||||
int counts[] = {0, 0, 0, 0, 0};
|
||||
for (Map.Entry<AgentObject, Integer> me : agentStates.entrySet()) {
|
||||
counts[me.getValue()]++;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (Map.Entry<AgentObject, Integer> me : agentStates.entrySet()) {
|
||||
if (me.getValue() == state1) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
str.append(counts[PENDING]).append(" pending, ").
|
||||
append(counts[STARTED]).append(" started, ").
|
||||
append(counts[RUNNING]).append(" running, ").
|
||||
append(counts[DESTROYED]).append(" destroyed, ").
|
||||
append(counts[STILL_BORN]).append(" still born");
|
||||
return str;
|
||||
}
|
||||
|
||||
void summarize ()
|
||||
{
|
||||
Log.info("Bureau " + bureauId + " [" +
|
||||
countInState(PENDING) + " pending, " +
|
||||
countInState(STARTED) + " started, " +
|
||||
countInState(RUNNING) + " running, " +
|
||||
countInState(DESTROYED) + " destroyed, " +
|
||||
countInState(STILL_BORN) + " still born]");
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("Bureau ").append(bureauId).append(" [");
|
||||
agentSummary(str).append("]");
|
||||
Log.info(str.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user