processTree, textProcessTree

This commit is contained in:
Tony Garnock-Jones 2014-07-21 16:06:51 -07:00
parent 340d32e33c
commit 2aa44a9142
1 changed files with 36 additions and 0 deletions

View File

@ -323,6 +323,42 @@ World.prototype.handleEvent = function (e) {
}
};
World.prototype.processTree = function () {
var kids = [];
for (var pid in this.processTable) {
var p = this.processTable[pid];
if (p.behavior instanceof World) {
kids.push([pid, p.behavior.processTree()]);
} else {
kids.push([pid, p]);
}
}
return kids;
};
World.prototype.textProcessTree = function (ownPid) {
var lines = [];
function dumpProcess(prefix, pid, p) {
if (p instanceof Array) {
lines.push(prefix + '--+ ' + pid);
for (var i = 0; i < p.length; i++) {
dumpProcess(prefix + ' |', p[i][0], p[i][1]);
}
lines.push(prefix);
} else {
var label = p.behavior.name || p.behavior.constructor.name || '';
lines.push(prefix + '-- ' + pid + ': ' + label +
JSON.stringify(p.behavior, function (k, v) {
return k === 'name' ? undefined : v;
}));
}
}
dumpProcess('', ownPid || '', this.processTree());
return lines.join('\n');
};
/*---------------------------------------------------------------------------*/
/* Utilities: matching demand for some service */