Archived

This forum has been archived. Please start a new discussion on GitHub.

syncApplication

hi ice:
I have a problem, i have spend a lot of time in it,but i can't find what is wrong,please help me,thanks.

the following program runs well:
void
RegisterI::Regist(const string& nodeName, const string& serverId, const string& exePath, const string& activation, const string& adapterName, const string& objectIdentity, const string& objectType,const Ice::Current& c)
{
Ice::CommunicatorPtr comm = c.adapter->getCommunicator();
IceGrid::AdminPrx admin = IceGrid::AdminPrx::checkedCast(comm->stringToProxy("DemoIceGrid/Admin"));
if (!admin)
{
cout<<"Could not contact Admin"<<endl;
return;
}

IceGrid::ApplicationDescriptor appDes = (admin->getApplicationDescriptor("tnss"));
IceGrid::NodeDescriptorDict* nDesDict = &(appDes.nodes);
IceGrid::NodeDescriptorDict::iterator itr = nDesDict->find(nodeName);

IceGrid::NodeDescriptor* nDes;
bool isUpdate = false;
if (itr != nDesDict->end())
{
nDes = &(itr->second);
isUpdate = false;
}
else
{
nDes = new IceGrid::NodeDescriptor;
isUpdate = true;
}

IceGrid::ServerDescriptorSeq * sDesSeq = &(nDes->servers);
sDesSeq->clear();

IceGrid::ServerDescriptorPtr sDes = new IceGrid::ServerDescriptor;
sDes->id = serverId;
sDes->exe = exePath;
sDes->activation = activation;


sDesSeq->push_back(sDes);

if(isUpdate)
(*nDesDict)[nodeName] = (*nDes);

try
{
admin->syncApplication(appDes);
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
}

}

but when i add a code segement to it:
void
RegisterI::Regist(const string& nodeName, const string& serverId, const string& exePath, const string& activation, const string& adapterName, const string& objectIdentity, const string& objectType,const Ice::Current& c)
{
Ice::CommunicatorPtr comm = c.adapter->getCommunicator();
IceGrid::AdminPrx admin = IceGrid::AdminPrx::checkedCast(comm->stringToProxy("DemoIceGrid/Admin"));
if (!admin)
{
cout<<"Could not contact Admin"<<endl;
return;
}

IceGrid::ApplicationDescriptor appDes = (admin->getApplicationDescriptor("tnss"));
IceGrid::NodeDescriptorDict* nDesDict = &(appDes.nodes);
IceGrid::NodeDescriptorDict::iterator itr = (*nDesDict).find(nodeName);

IceGrid::NodeDescriptor* nDes;
bool isUpdate = false;
if (itr != nDesDict->end())
{
nDes = &(itr->second);
isUpdate = false;
}
else
{
nDes = new IceGrid::NodeDescriptor;
isUpdate = true;
}

IceGrid::ServerDescriptorSeq * sDesSeq = &(nDes->servers);
sDesSeq->clear();

IceGrid::ServerDescriptorPtr sDes = new IceGrid::ServerDescriptor;
sDes->id = serverId;
sDes->exe = exePath;
sDes->activation = activation;


// added code segement
IceGrid::AdapterDescriptorSeq* aDesSeq = &(sDes->adapters);
aDesSeq->clear();

IceGrid::AdapterDescriptor aDes;
aDes.name = adapterName;

IceGrid::ObjectDescriptor oDes;
oDes.id = comm->stringToIdentity(objectIdentity);
oDes.type = objectType;

aDes.objects.push_back(oDes);

sDes->adapters.push_back(aDes);
// added code segement

sDesSeq->push_back(sDes);

if(isUpdate)
(*nDesDict)[nodeName] = (*nDes);

try
{
admin->syncApplication(appDes);
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
}

}

when it runs, it throw exception:
ex {_file=0x00000000 <错误的指针(error pointer)> _line=0 }

Comments

  • benoit
    benoit Rennes, France
    Hi,

    You should catch the user exceptions that syncApplication might throw to get more information:
    try
    {
       admin->syncApplication(appDes);
    }
    catch(const IceGrid::DeploymentException& ex)
    {
        cerr << ex << ": " << ex.reason << endl;
    }
    catch(const IceGrid::AccessDeniedException& ex)
    {
        cerr << ex << ": " << ex.lockUserId << endl;
    }
    catch(const IceGrid::ApplicationNotExistException& ex)
    {
        cerr << ex << ": " << ex.name << endl;
    }
    catch(const Ice::Exception& ex)
    {
        cerr << ex << endl;
    }
    

    I suspect IceGrid is rejecting your descriptor because the ID of the adapter you're registering is not set.

    Cheers,
    Benoit.
  • thanks

    I modified my program as you said, and then i caught a IceGrid::DeploymentException, it shows
    + reason {"server `MultiName': invalid value for attribute `object adapter id': empty string"}

    but i have a question, in page 1059 of ice-3.1.1.pdf it says:
    Had we omitted the id attribute, IceGrid would have composed a unique value by combining the server name and adapter name to produce the following identifier:
    EncoderServer.EncoderAdapter

    that is to say adapter id is not necessary, so why IceGrid throws IceGrid::DeploymentException?
  • benoit
    benoit Rennes, France
    Hi,

    The default value only applies in the context of XML descriptors (i.e.: if you don't specify the XML attribute "id" in the <adapter> element). Here you programatically register the adapter and you are required to set the adapter id (you could use the same default as the XML descriptors).

    Cheers,
    Benoit.
  • i understand,but trouble you again

    where can i set the endpoints of object adapter, i can't find this field in IceGrid::AdapterDescriptor, i installed ice 3.1.1 for vc7.1
  • benoit
    benoit Rennes, France
    You just need to add a property to set the adapter endpoints (i.e.: the property <adapter name>.Endpoints).

    Cheers,
    Benoit.
  • benoit, thanks for your help

    i have finished my program under your guidance,thanks very much.
    I am a soft engineer in a chinese company, i think ice is of good design so i want to introduce ice to our product.