Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reincarnation through the ServantManager with Mico

Status
Not open for further replies.

Dominik82

Programmer
Jul 28, 2013
2
DE
I'm using Mico/Corba to Programm a Predictiongame. I've got a Problem with the server. The Problem is the reincarnation of saved files through the ServantManager. The incarnation of new Game Objects works fine also the serialisation and unserialisation does. After restarting the Server i would like to reincarnate the Game Objects. The ServantManager calls the incarnate method once for the first file but thats it. It doesn't hang or throws an exception. I can't figure out why he does it only once. Is there any good documentation for that? I haven't found anything that could help me to find the resolution for this problem.


Code:
::Predictiongame::Game_ptr Gameplay_impl::loadSavedGame() {
	// generate a ObjectID so that the ServantManager can
	// decide what Objekttyp has to be generated
	char oidstr[255];
	sprintf(oidstr,"games//game_%d.dat",gameCnt);
	PortableServer::ObjectId_var tmpoid=PortableServer::string_to_ObjectId(oidstr);

	// Generate a reference for a "virtual" Object.
	// The Servant Manager generates a Object with caling the incarnate() method.
	// But he does it only the first time. Why???
	CORBA::Object_var obj = mypoa->create_reference_with_id (tmpoid,"IDL:Game:1.0");
	assert (!CORBA::is_nil (obj));
	::Predictiongame::Game_ptr aref = ::Predictiongame::Game::_narrow (obj);
	assert (!CORBA::is_nil (aref));
	oid[gameCnt] = mypoa->reference_to_id(aref); // get id of the Game Objekt and save it in a array
	gameCnt ++;
	return aref;	
}



// incarnate-method in the Implementation of the ServantManager
PortableServer::Servant GameManager::incarnate (const PortableServer::ObjectId & oid,PortableServer::POA_ptr poa) {
	CORBA::String_var name = PortableServer::ObjectId_to_string (oid);
	cout << "INCARNATE oid: " << PortableServer::ObjectId_to_string(oid) << endl;
	// anhand der ObjectId kann entschieden werden, welcher Typ erzeugt werden soll
	if(strstr(PortableServer::ObjectId_to_string(oid),"game")){
		Game_impl* game = new Game_impl(name);
		game->unserialize();			
		svGameMap[game] = game;
		return game;
	}
	else if(...
		...

	return NULL;
}


int main (int argc, char *argv[]){
	orb = CORBA::ORB_init (argc, argv);
	CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
	PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
	PortableServer::POAManager_var mgr = poa->the_POAManager();

	CORBA::PolicyList pl;
	pl.length(2);
	pl[0] = poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
	pl[1] = poa->create_lifespan_policy (PortableServer::PERSISTENT);
	PortableServer::POA_var gamepoa = poa->create_POA ("Games", PortableServer::POAManager::_nil(), pl);
	PortableServer::POAManager_var gamemgr = gamepoa->the_POAManager();
	
	// activate ServantManager
	GameManager * am = new GameManager;
	PortableServer::ServantManager_var amref = am->_this ();
	gamepoa->set_servant_manager (amref);

 	...
	
	// generate Gameplay
	Gameplay_impl * predGame = new Gameplay_impl (gamepoa); 
	PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Gameplay");


	gameplaypoa->activate_object_with_id (*oid, predGame);

	...

	// activate POAs
	mgr->activate ();
	gamemgr->activate ();

	int fileCnt = cntFiles("games//");

	// reincarnate all saved Game Objects.
	for(int i = 0;i < fileCnt;i++){
		predGame->loadSavedGame();
	}
	orb->run();

	...

	return 0;
}

Thanks for your help.
 
I've found a solution. The repoid must be unique too.

Code:
::Predictiongame::Game_ptr Gameplay_impl::loadSavedGame() {
	// generate a ObjectID so that the ServantManager can
	// decide what Objekttyp has to be generated
	char repoid[255];
	sprintf(repoid,"IDL:Game:1.%d", gameCnt);
	
	char oidstr[255];
	sprintf(oidstr,"games//game_%d.dat",gameCnt);
	PortableServer::ObjectId_var tmpoid=PortableServer::string_to_ObjectId(oidstr);

	// Generate a reference for a "virtual" Object.
	// The Servant Manager generates a Object with caling the incarnate() method.
	CORBA::Object_var obj = mypoa->create_reference_with_id (tmpoid,repoid);
	assert (!CORBA::is_nil (obj));
	::Predictiongame::Game_ptr aref = ::Predictiongame::Game::_narrow (obj);
	assert (!CORBA::is_nil (aref));
	oid[gameCnt] = mypoa->reference_to_id(aref); // get id of the Game Objekt and save it in a array
	gameCnt ++;
	return aref;	
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top