Fighting for one hour with the ready message being misunderstood by master

This commit is contained in:
samcake 2015-12-01 18:18:18 -08:00
parent b6530b8b30
commit 86af28dbab
2 changed files with 60 additions and 51 deletions

View file

@ -131,21 +131,21 @@ function printDebug(message) {
}; };
MasterController.prototype._processServiceMessage = function(message, senderID) { MasterController.prototype._processServiceMessage = function(message, senderID) {
var message = unpackServiceMessage(message); var service = unpackServiceMessage(message);
if (message.dest == MASTER_ID) { if (service.dest == MASTER_ID) {
if (message.command == AGENT_READY) { if (service.command == AGENT_READY) {
// check to see if we know about this agent // check to see if we know about this agent
var agentIndex = this.knownAgents.indexOf(message.src); var agentIndex = this.knownAgents.indexOf(service.src);
if (agentIndex < 0) { if (agentIndex < 0) {
this._onAgentAvailableForHiring(message.src); this._onAgentAvailableForHiring(service.src);
} else { } else {
// Master think the agent is hired but not the other way around, forget about it // Master think the agent is hired but not the other way around, forget about it
printDebug("New agent still sending ready ? " + message.src + " " + agentIndex + " Forgeting about it"); printDebug("New agent still sending ready ? " + service.src + " " + agentIndex + " Forgeting about it");
this._removeHiredAgent(agentIndex); // this._removeHiredAgent(agentIndex);
} }
} else if (message.command == AGENT_ALIVE) { } else if (service.command == AGENT_ALIVE) {
// check to see if we know about this agent // check to see if we know about this agent
var agentIndex = this.knownAgents.indexOf(message.src); var agentIndex = this.knownAgents.indexOf(service.src);
if (agentIndex >= 0) { if (agentIndex >= 0) {
// yes so reset its alive beat // yes so reset its alive beat
this.hiredActors[agentIndex].alive(); this.hiredActors[agentIndex].alive();
@ -171,8 +171,10 @@ function printDebug(message) {
newActor.agentID = agentID; newActor.agentID = agentID;
this.hiredActors.push(newActor); this.hiredActors.push(newActor);
printDebug("New agent available to be hired " + agentID + " " + indexOfNewAgent); printDebug("New agent available to be hired " + agentID + " " + indexOfNewAgent);
Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(agentID, MASTER_HIRE_AGENT, MASTER_ID)); var serviceMessage = packServiceMessage(agentID, MASTER_HIRE_AGENT, MASTER_ID);
printDebug("serviceMessage = " + serviceMessage);
Messages.sendMessage(SERVICE_CHANNEL, serviceMessage);
printDebug("message sent calling the actor" + JSON.stringify(newActor) ); printDebug("message sent calling the actor" + JSON.stringify(newActor) );
newActor.onHired(newActor); newActor.onHired(newActor);
@ -276,7 +278,6 @@ function printDebug(message) {
//--------------------------------- //---------------------------------
var AgentController = function() { var AgentController = function() {
this.subscribed = false; this.subscribed = false;
this._init(); this._init();
this.onHired = function() {}; this.onHired = function() {};
@ -325,40 +326,42 @@ function printDebug(message) {
}; };
AgentController.prototype._processServiceMessage = function(message, senderID) { AgentController.prototype._processServiceMessage = function(message, senderID) {
var announce = unpackServiceMessage(message); var service = unpackServiceMessage(message);
//printDebug("Client " + this.agentUUID + " Received Announcement = " + message); printDebug("Client " + this.agentUUID + " Received message = " + message);
if (announce.dest == this.agentUUID) { if (service.dest == this.agentUUID) {
if (announce.command != AGENT_READY) { if (service.command != AGENT_READY) {
var parts = announce.command.split(".");
// this is potnetially a message to hire me if i m not already // this is potentially a message to hire me if i m not already
if (!this.isHired && (parts[0] == MASTER_HIRE_AGENT)) { if (!this.isHired && (service.command == MASTER_HIRE_AGENT)) {
printDebug(announce.command); printDebug(service.command);
this.isHired = true; this.isHired = true;
printDebug("Client Hired by master UUID" + senderID); printDebug("Client Hired by master UUID" + service.src);
this.onHired(); this.onHired();
this.alive();
return; return;
} }
if (this.isHired && (parts[0] == MASTER_FIRE_AGENT)) { // Or maybe a message to fire me if i m not hired
if (this.isHired && (service.command == MASTER_FIRE_AGENT)) {
printDebug("Client Fired by master UUID" + senderID); printDebug("Client Fired by master UUID" + senderID);
this.fired(); this.fired();
return; return;
} }
} }
} else if (announce.src == MASTER_ID && announce.command == MASTER_ALIVE) { } else if ((service.src == MASTER_ID) && (service.command == MASTER_ALIVE)) {
this.numCyclesWithoutAlive = 0; this.numCyclesWithoutAlive = 0;
return; return;
} }
} }
AgentController.prototype._processCommandMessage = function(message, senderID) { AgentController.prototype._processCommandMessage = function(message, senderID) {
var command = unpackCommandMessage(message); // ONly work if hired
if ((command.dest_key == this.agentUUID) || (command.dest_key == BROADCAST_AGENTS)) { if (this.isHired) {
printDebug("Command received = " + JSON.stringify(command) + senderID); var command = unpackCommandMessage(message);
this.onCommand(command); if ((command.dest_key == this.agentUUID) || (command.dest_key == BROADCAST_AGENTS)) {
} else { printDebug("Command received = " + JSON.stringify(command) + senderID);
// ignored this.onCommand(command);
}
} }
}; };
@ -370,9 +373,9 @@ function printDebug(message) {
if (!this.isHired) { if (!this.isHired) {
Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(MASTER_ID, AGENT_READY, this.agentUUID)); Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(MASTER_ID, AGENT_READY, this.agentUUID));
//printDebug("Client Ready" + SERVICE_CHANNEL + AGENT_READY); //printDebug("Client Ready" + SERVICE_CHANNEL + AGENT_READY);
} else { } else {
// Send alive beat // Send alive beat
printDebug("beat !");
Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(MASTER_ID, AGENT_ALIVE, this.agentUUID)); Messages.sendMessage(SERVICE_CHANNEL, packServiceMessage(MASTER_ID, AGENT_ALIVE, this.agentUUID));
// Listen for master beat // Listen for master beat

View file

@ -275,28 +275,34 @@ Director.prototype.moveUI = function(pos) {
Director.prototype.reloadPerformance = function() { Director.prototype.reloadPerformance = function() {
this.requestPerformanceLoad = false; this.requestPerformanceLoad = false;
var urlpartition = this.performanceURL.split(".");
print(urlpartition[0]);
print(urlpartition[1]);
if ((urlpartition.length > 1) && (urlpartition[urlpartition.length - 1] === "hfr")) { if (this.performanceURL[0] == '{') {
print("detected a unique clip url"); var jsonPerformance = JSON.parse(this.performanceURL);
var oneClipPerformance = new Object(); this.onPerformanceLoaded(jsonPerformance);
oneClipPerformance.avatarClips = new Array(); } else {
oneClipPerformance.avatarClips[0] = input_text;
print(JSON.stringify(oneClipPerformance)); var urlpartition = this.performanceURL.split(".");
print(urlpartition[0]);
print(urlpartition[1]);
// we make a local simple performance file with a single clip and pipe in directly if ((urlpartition.length > 1) && (urlpartition[urlpartition.length - 1] === "hfr")) {
this.onPerformanceLoaded(oneClipPerformance); print("detected a unique clip url");
return true; var oneClipPerformance = new Object();
} else { oneClipPerformance.avatarClips = new Array();
// FIXME: I cannot pass directly this.onPerformanceLoaded, is that exepected ? oneClipPerformance.avatarClips[0] = input_text;
var localThis = this;
Assets.downloadData(input_text, function(data) { localThis.onPerformanceLoaded(JSON.parse(data)); }); print(JSON.stringify(oneClipPerformance));
}
// we make a local simple performance file with a single clip and pipe in directly
this.onPerformanceLoaded(oneClipPerformance);
return true;
} else {
// FIXME: I cannot pass directly this.onPerformanceLoaded, is that exepected ?
var localThis = this;
Assets.downloadData(input_text, function(data) { localThis.onPerformanceLoaded(JSON.parse(data)); });
}
}
} }
Director.prototype.onPerformanceLoaded = function(performanceJSON) { Director.prototype.onPerformanceLoaded = function(performanceJSON) {