Archived

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

About Ice Best Practices:What is the best way to client locating the servant?

have a question about client locating the servant.


My type sysstem has two servants,which are independent to each other.
for instance,at server side:
FooI Servant:
public class FooI:FooDisp_
{
....//no any api will return BarI proxy
}
BarI Servant:
public class BarI:BarDisp_
{
...//no any api will return FooI proxy

}

Server Application:
public class Server:Ice.Application
{
public override int run(string[] args)
{
Ice.ObjectAdapter adapter=new ....
adapter.add(new FooI(),communicator().stringToIdentity("Foo"));
adapter.add(new FooI(),communicator().stringToIdentity("Bar"));
adapter.activate();
communicator().waitForShutdown();
return 0;

}

public static void Main(string[] args)
{
Server app = new Server();
int status = app.main(args, "config.server");
if (status != 0)
{
System.Environment.Exit(status);
}
}

}


At the client,maybe I need to add below lines to client.config file:
Server.Foo=Foo:tcp -h 127.0.0.1 -p 12345:udp -h 127.0.0.1 -p 12345
Server.Bar=Bar:tcp -h 127.0.0.1 -p 12345:udp -h 127.0.0.1 -p 12345


And write below code:
FooPrx fooPrx = FooPrxHelper.
checkedCast(communicator().propertyToProxy("Server.Foo"));

......//do someting

BarPrx barPrx = BarPrxHelper.
checkedCast(communicator().propertyToProxy("Server.Bar"));

......//do someting

Above steps can work well,but I fell there are some smell in these code.
How can I do better?
What is the best way to client locating the servant?

Comments

  • matthew
    matthew NL, Canada
    I'm afraid there is no absolute answer to this problem. It really depends on your application and deployment environment. What you've done certainly works, but it requires that you modify the configuration files each time the objects move which may or may not be very inconvient.

    A more flexible solution is to use IceGrid and locate these objects as well-known objects -- there are numerous articles in our Newsletter on IceGrid so I recommend reading them for more insights.
  • Thanks very much!

    I will read them .