don't send create assignment request until connection to DS

This commit is contained in:
Stephen Birarda 2013-09-30 13:57:42 -07:00
parent 774eef1c12
commit b3bd159d09
2 changed files with 46 additions and 29 deletions

View file

@ -13,7 +13,6 @@
#include <QDebug>
#include <QString>
#include <QStringList>
#include <Logging.h>
#include <OctalCode.h>
@ -50,7 +49,8 @@ void attachVoxelNodeDataToNode(Node* newNode) {
VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location location) :
Assignment(command, Assignment::VoxelServerType, location),
_serverTree(true) {
_serverTree(true),
_multiConfigList() {
_argc = 0;
_argv = NULL;
@ -72,7 +72,8 @@ VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location locat
}
VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assignment(dataBuffer, numBytes),
_serverTree(true) {
_serverTree(true),
_multiConfigList() {
_argc = 0;
_argv = NULL;
@ -116,34 +117,11 @@ void VoxelServer::setArguments(int argc, char** argv) {
void VoxelServer::parsePayload() {
if (getNumPayloadBytes() > 0) {
QString multiConfig((const char*)getPayload());
QStringList multiConfigList = multiConfig.split(";");
// There there are multiple configs, then this instance will run the first
// config, and launch Assignment requests for the additional configs.
if (multiConfigList.size() > 1) {
qDebug("Voxel Server received assignment for multiple Configs... config count=%d\n", multiConfigList.size());
// skip 0 - that's the one we'll run
for (int i = 1; i < multiConfigList.size(); i++) {
QString config = multiConfigList.at(i);
qDebug(" config[%d]=%s\n", i, config.toLocal8Bit().constData());
Assignment voxelServerAssignment(Assignment::CreateCommand,
Assignment::VoxelServerType,
getLocation()); // use same location as we were created in.
int payloadLength = config.length() + sizeof(char);
voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength);
qDebug("Requesting additional Voxel Server assignment to handle config %d\n", i);
NodeList::getInstance()->sendAssignment(voxelServerAssignment);
}
}
QString multiConfig((const char*) _payload);
_multiConfigList = multiConfig.split(";");
// Now, parse the first config
QString config = multiConfigList.at(0);
QString config = _multiConfigList.at(0);
QStringList configList = config.split(" ");
int argCount = configList.size() + 1;
@ -166,6 +144,31 @@ void VoxelServer::parsePayload() {
}
}
void VoxelServer::parseOtherServerConfigs() {
// There there are multiple configs, then this instance will run the first
// config, and launch Assignment requests for the additional configs.
if (_multiConfigList.size() > 1) {
qDebug("Voxel Server received assignment for multiple Configs... config count=%d\n", _multiConfigList.size());
// skip 0 - that's the one we'll run
for (int i = 1; i < _multiConfigList.size(); i++) {
QString config = _multiConfigList.at(i);
qDebug(" config[%d]=%s\n", i, config.toLocal8Bit().constData());
Assignment voxelServerAssignment(Assignment::CreateCommand,
Assignment::VoxelServerType,
getLocation()); // use same location as we were created in.
int payloadLength = config.length() + sizeof(char);
voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength);
qDebug("Requesting additional Voxel Server assignment to handle config %d\n", i);
NodeList::getInstance()->sendAssignment(voxelServerAssignment);
}
}
}
//int main(int argc, const char * argv[]) {
void VoxelServer::run() {
@ -354,6 +357,8 @@ void VoxelServer::run() {
_voxelServerPacketProcessor->initialize(true);
}
bool isFirstDomainPacket = true;
// loop to send to nodes requesting data
while (true) {
@ -393,6 +398,14 @@ void VoxelServer::run() {
// If the packet is a ping, let processNodeData handle it.
NodeList::getInstance()->processNodeData(&senderAddress, packetData, packetLength);
} else if (packetData[0] == PACKET_TYPE_DOMAIN) {
if (isFirstDomainPacket) {
// this is the first packet we've received from the DS, parse the other server configs
// so we can make the appropriate create assignment requests
parseOtherServerConfigs();
isFirstDomainPacket = false;
}
NodeList::getInstance()->processNodeData(&senderAddress, packetData, packetLength);
} else if (packetData[0] == PACKET_TYPE_VOXEL_JURISDICTION_REQUEST) {
if (_jurisdictionSender) {

View file

@ -10,6 +10,8 @@
#ifndef __voxel_server__VoxelServer__
#define __voxel_server__VoxelServer__
#include <QStringList>
#include <Assignment.h>
#include <EnvironmentData.h>
@ -78,8 +80,10 @@ private:
EnvironmentData _environmentData[3];
NodeWatcher _nodeWatcher; // used to cleanup AGENT data when agents are killed
QStringList _multiConfigList;
void parsePayload();
void parseOtherServerConfigs();
};
#endif // __voxel_server__VoxelServer__