[omniORB] How-to shutdown a Server...

dsam@tid.es dsam@tid.es
Thu Oct 17 16:27:01 2002


Hello

I have impelented a simple example in order to test the server 
shutdown. Therefore Ive compiled an IDL with a method "apagar" in order 
to allow the client to explicitly shutdown the server.The method is 
called correctly but the server doesnt get down. I ve attached the used 
code. Does somebody knows how to shutdown a server correctly?

Thanks in advance
Diego


void Echo_i::apagar(){
  // insert code here and remove the warning
  orb->shutdown(true);
}


int main(int argc, char** argv)
{
  try 
  {
    // Initialise the ORB.
    orb = CORBA::ORB_init(argc, argv);
    cout<<"la ref de ORB: "<<orb<<endl;

    // Obtain a reference to the root POA.
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
    PortableServer::POAManager_var pman = poa->the_POAManager();
     
    //Metemos la politica de persistencia
    CORBA::PolicyList pl;
    pl.length(2);

    pl[0]=poa->create_lifespan_policy(PortableServer::PERSISTENT);
    pl[1]=poa->create_id_assignment_policy (PortableServer::USER_ID);
    PortableServer::POA_var echo_poa = poa-> create_POA 
("EchoPOA",pman,pl);
    
    // We allocate the objects on the heap.  Since these are reference
    // counted objects, they will be deleted by the POA when they are no
    // longer needed.
    Echo_i* myecho = new Echo_i();

    // Activate the objects.  This tells the POA that the objects are
    // ready to accept requests.
    PortableServer::ObjectId_var oid = 
PortableServer::string_to_ObjectId("EchoPOA");
    
    echo_poa->activate_object_with_id(oid,myecho);
      
    CORBA::Object_var echoObj = echo_poa->id_to_reference(oid.in());
        
    
    CORBA::String_var x = orb->object_to_string(echoObj);

    cout<<"IOR:"<<x<<endl;

    if (!bindObjectToName(orb,echoObj))
	return 1;

    cout<<"Despues de binObjectToName"<<endl;
    // OJO. Pq igual esto hay que ponerlo
   //myecho->_remove_ref();

    pman->activate();

    orb->run();
    orb->destroy();
    //Borramos todo
    poa2->destroy(true,true);
    delete myecho;
  }
  catch(CORBA::SystemException&) 
  {
    cerr << "Caught CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) 
  {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) 
  {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) 
  {
    cerr << "Caught unknown exception." << endl;
  }
  return 0;
}