ICE 学习进阶4-配置属性

ICE 配置机制学习

1. Ice 用的属性 类型的配置,即一组名称-值对。
 Ice.UDP.SndSize=65535

2. 属性配置必须在 初始化ice环境(IceCommunicator)前设置好,否则忽略,需要重启。

3. 属性配置约定格式为:
 <application>.<category>[.<sub-category>]
  其中如下配置名称的前缀是保留字,勿用:
 Ice, IceBox, IceGrid, IcePatch2, IceSSL, IceStorm, Freeze, and Glacier2
4. 配置文件
 # 开头的行是注释
 属性名称中间可有空格,头尾的空格除非有转义符将被忽略,但是是否有“=”? 不允许。
   = marks the end of the property name and the beginning of the property value
   # starts a comment that extends to the end of the line
 重复对一个配置名赋值,只留最后的有效。
 对一个属性名赋空值,将取消该设置,和不提及该属性的效果一样
 配置选项 都用在 Communicator ic = Ice::initialize(int argc,char*argv[]) 中使用。
5. 配置文件的使用方法
 使用配置文件一种的简单方法是用--Ice.Config: ./server --Ice.Config=/opt/Ice/default_config
 另外一个方法是设置ICE_CONFIG环境变量,如下:
  $ export ICE_CONFIG=/opt/Ice/default_config
  $ ./server
 以上两种方法,若有一个参数,将进行配置选项合并,重复的话,后面覆盖前面的
6. 通过命令行参数设置配置属性
 $ ./server --Ice.UDP.SndSize=65535 --IceSSL.Trace.Security=2

7. 几种配置选项的优先级
 命令 
 Ice.Config
 ICE_CONFIG

8. java中的Ice.Config属性,先在class路径查找,然后在本地文件系统中找

9. 版本也可以采用配置机制获得配置信息,
 # Configuration file for file system application
 Filesystem.MaxFileSize=1024 # Max file size in k
 
 通过ICE运行环境的Properties  Communicator::getProperties接口访问,
 getProperty
 getPropertyWithDefault
 getPropertyAsInt
 getPropertiesForPrefix 返回全面的指定开头的 名称-值 属性对
 举例:
  Ice::CommunicatorPtr ic;
  ic = Ice::initialize(argc, argv);
  // Get the maximum file size.
  Ice::PropertiesPtr props = ic->getProperties();
  Ice::Int maxSize
  = props->getPropertyAsIntWithDefault("Filesystem.MaxFileSize",1024);
  
 设置属性
  PropertiesPtr createProperties(const StringConverterPtr& = 0);
  // Get the initialized property set.
  Ice::PropertiesPtr props = Ice::createProperties(argc, argv);
  // Make sure that network and protocol tracing are off.
  props->setProperty("Ice.Trace.Network", "0");
  props->setProperty("Ice.Trace.Protocol", "0");
  // Initialize a communicator with these properties.
  Ice::InitializationData id;
  id.properties = props;
  Ice::CommunicatorPtr ic = Ice::initialize(id);

10. 总结
The Ice property mechanism provides a simple way to configure Ice by setting
properties in configuration files or on the command line. This also applies to your
own applications: you can easily use the Properties interface to access application-
specific properties that you have created for your own needs. The API to
access property values is small and simple, making it easy to retrieve property
values at run time, yet is flexible enough to allow you to work with different property
sets and configuration files if the need arises.

 

你可能感兴趣的:(properties,command,File,Access,NetWork,interface)