tangr206

配置文件格式,比如
# Example config file for Ice

Ice.MessageSizeMax = 2048   # Largest message size is 2MB
Ice.Trace.Network=3          # Highest level of tracing for network
Ice.Trace.Protocol=          # Disable protocol tracing

加载配置方式一:
./server --Ice.Config=/opt/Ice/default_config
这种需要带命令行参数
./server --Ice.UDP.SndSize = 65535 --IceSSL.Trace.Security=2

环境变量来生效
#export ICE_CONFIG=/etc/ice.conf
./server

命令行与配置文件结合的方式,以命令行的配置为优先
也可以指定多个配置文件
比如:
# export ICE_CONFIG=/etc/ice.conf1,/etc/ice.conf2
# ./server
并且ice.conf2中的配置会覆盖ice.conf1中的配置.

如果试用./server --Ice.Config=/etc/ice.conf来运行
那么ice.conf中的配置将会覆盖环境变量中指定的配置文件的配置。

或者说 ./server --Ice.Config=/etc/ice.conf --Ice.MessageSizeMax=4096
后面的配置将会覆盖配置文件中的配置。

./server --Ice.Config=/etc/ice.conf1 --Ice.Config=/etc/ice.conf2等同于
./server --Ice.Config=/etc/ice.conf2

 

  1. Ice::PropertiesPtr prop = ic->getProperties();
  2. string s = prop->getPropertyWithDefault(
  3.     "Ice.Printer","SimplePrinter:default -p 10000");
  4. Ice::ObjectPrx base = ic->stringToProxy(s);

三条指令可以用一条指令代替:

  1. Ice::ObjectPrx base = ic->propertyToProxy("Ice.Printer");

多写几行有时还是有用的,我们可以利用它来读取我们自定义的一些参数^_^(当然还有默认参数功能

上面的命令行里我们取的是"Ice.Printer"属性,注意它的前缀是"Ice.",如果我们改成其它前缀,如"MyProp.",那么Ice初始化时就不认为这是Ice专用参数而不理睬它了。

我们想自定义一些属性用于“私用”的话,使用"Ice."前缀就显得不合理了,这时我们可以使用属性集的parseCommandLineOptions方法来解析指定前缀的参数:

  1. class MyApp: public Ice::Application{
  2. public:
  3.     virtual int run(int argc, char*argv[])
  4.     {
  5.         Ice::CommunicatorPtr ic = communicator();
  6.         Ice::PropertiesPtr prop = Ice::createProperties();
  7.         prop->parseCommandLineOptions("MyProp"
  8.             Ice::argsToStringSeq(argc,argv));
  9.         string s = prop->getPropertyWithDefault(
  10.             "MyProp.Printer","SimplePrinter:default -p 10000");
  11.         Ice::ObjectPrx base = ic->stringToProxy(s);
  12.         PrinterPrx printer =  PrinterPrx::checkedCast(base);
  13.         if(!printer) throw "Invalid Proxy!";
  14.         printer->printString("Hello World!");
  15.         return 0;
  16.     }
  17. };

现在,程序可以解析MyProp.Printer属性了。

 

ICE的ACM
客户端连接服务器,Ice.ACM.Client=num表示客户端到服务器的连接空闲num秒后
就会自动关闭,再次通讯时又会连接上。默认为60秒,一分钟。如果是0,表示ACM不启用
Active Connection Manage­ment
服务端ACM Ice.ACM.Server = N
当客户端到服务端N秒没有数据时,服务端自动关闭连接。默认禁止ACM.

ICE的消息大小,Ice.MessageSizeMax = N
设置ICE未压缩时消息的大小,单位为kb,默认为1024kb(1M),这个大小包括了ICE消息头。

 

 

If you use the Ice.Application helper class, the run method is passed
the cleaned-up argument vector.

 

1.2 Ice的属性和配置

Ice通过各种属性机制让开发者控制Ice应用在运行时的各种行为

1.2.1 Ice可以采用配置文件和控制台配置命令的方式来进行配置,而且后者优先级较前者高,当通过命令行进行配置时,将覆盖前者的配置

1.2.2 Ice有专门读取和设置配置的库函数

1.3 Ice::Application Helper采用的是Singleton的模式,不适用于多个communicators

分类:

技术点:

相关文章: