A problem about IceGrid's replicated servers

in Help Center
If two servers implement differenct interfaces, but they have the same identity(for example: [email protected]), what will happen if they register to IceRegistry ? Can IceRegistry reject the second server's registration ? The following is my demo code:
Printer.ice---
module Demo
{
interface PrinterA
{
void printStringA(string s);
};
interface PrinterB
{
void printStringB(string s);
};
};
ServerA.cpp----
class PrinterAI : public PrinterA {
public:
virtual void printString(const string & s,
const Ice::Current &);
};
int
main(int argc, char* argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter
= ic->createObjectAdapterWithEndpoints("theAdapter", "default -p 10000");
Ice::ObjectPtr object = new PrinterAI;
//objectId: [email protected] - implementation the PrinterA interface
adapter->add(object,
Ice::stringToIdentity("thePrinter"));
adapter->activate();
ic->waitForShutdown();
} catch (const Ice::Exception & e) {
//...
}
}
ServerB.cpp---
class PrinterBI : public PrinterB {
public:
virtual void printString(const string & s,
const Ice::Current &);
};
//...
int
main(int argc, char* argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter
= ic->createObjectAdapterWithEndpoints("theAdapter", "default -p 10001");
Ice::ObjectPtr object = new PrinterBI;
//objectId: [email protected] - implementation the PrinterB interface
adapter->add(object,
Ice::stringToIdentity("thePrinter"));
adapter->activate();
ic->waitForShutdown();
} catch (const Ice::Exception & e) {
//...
}
}
Printer.ice---
module Demo
{
interface PrinterA
{
void printStringA(string s);
};
interface PrinterB
{
void printStringB(string s);
};
};
ServerA.cpp----
class PrinterAI : public PrinterA {
public:
virtual void printString(const string & s,
const Ice::Current &);
};
int
main(int argc, char* argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter
= ic->createObjectAdapterWithEndpoints("theAdapter", "default -p 10000");
Ice::ObjectPtr object = new PrinterAI;
//objectId: [email protected] - implementation the PrinterA interface
adapter->add(object,
Ice::stringToIdentity("thePrinter"));
adapter->activate();
ic->waitForShutdown();
} catch (const Ice::Exception & e) {
//...
}
}
ServerB.cpp---
class PrinterBI : public PrinterB {
public:
virtual void printString(const string & s,
const Ice::Current &);
};
//...
int
main(int argc, char* argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try {
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter
= ic->createObjectAdapterWithEndpoints("theAdapter", "default -p 10001");
Ice::ObjectPtr object = new PrinterBI;
//objectId: [email protected] - implementation the PrinterB interface
adapter->add(object,
Ice::stringToIdentity("thePrinter"));
adapter->activate();
ic->waitForShutdown();
} catch (const Ice::Exception & e) {
//...
}
}
0
Comments
At the object adapter level, IcePack will do the following:
At the object level, there's nothing to prevent you from using the same identity for different objects. You have to ensure that your objects use a different identity. The only case where it makes sense to use the same identity is for a replicated object.
Benoit.
Thank you!
Can IcePack restrict that differenct objects using the same identity must confirm to the same interface ? Maybe this is very useful!
It would be possible to automatically register objects with the IcePack registry and add some checks at the time of the registration. However, this would add some overhead for applications which register many objects...
It's probably better if you ensure at the application level that your objects use a unique identity, you can for example use UUIDs for this purpose.
Benoit.