ice使用过程遇到的问题

本文主要探讨了ICE中代理超时时间的设置,包括ice_timeout和ice_connectiontimeout,以及如何通过属性设置全局超时。此外,还介绍了定位服务的缓存策略,如LocatorCacheTimeout,以减少定位请求。同时,提到了处理智能指针异常,特别是默认构造的空智能指针可能导致的运行时错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 设置代理超时时间ice_timeout

   ICE的每个连接都有两个超时时间:ice_timeout、ice_connectiontimeout,分别对应消息的超时时间和连接建立
   的超时时间,可以通过在代理上调用上述方法来设置超时,也可以通过属性Ice.Override.Timeout、Ice.Override.ConnectTimeout
   来强制改变超时时间。

示例如下,

MyAdapter.Endpoints=tcp –p 9999 –t 5000

base = __ice_runtime.stringToProxy(settings.CONF_DATA_CENTER_SERVERS).ice_timeout(500) //获得代理的超时时间


 在客户端,我们使用对象代理进行远程调用,就如它们就在本地一样。但有时,网络问题还是要考虑的,于是Ice的对象代理提供了几个包装方法,以支持一些网络特性:

ice_timeout方法,声明为:Ice::ObjectPrx ice_timeout(int) const;返回一个超时代理,当在指定的时间(单位毫秒)内没有得到服务器端响应时,操作终止并抛出Ice::TimeoutException异常。

示例代码
  1. Filesystem::FilePrx myFile = ...;
  2. FileSystem::FilePrx timeoutFile
  3. = FileSystem::FilePrx::uncheckedCast(
  4.         myFile->ice_timeout(5000));
  5. try {
  6.     Lines text = timeoutFile->read(); // Read with timeout
  7. catch(const Ice::TimeoutException &) {
  8.     cerr << "invocation timed out" << endl;
  9. }
  10. Lines text = myFile->read(); // Read without timeout




1设置定位服务缓存超时时间

Ice.Default.LocatorCacheTimeout  

对于定位服务,可以缓存 代理对应的端点地址,这样可以减少定位请求。
Description

Specifies the default locator cache timeout for indirect proxies. If num is set to a value larger than zero, locator cache entries older than num seconds are ignored. If set to 0, the locator cache is not used. If set to -1, locator cache entries do not expire.

Once a cache entry has expired, the Ice run time performs a new locate request to refresh the cache before sending the next invocation; therefore, the invocation is delayed until the run time has refreshed the entry. If you set Ice.BackgroundLocatorCacheUpdates to a non-zero value, the lookup to refresh the cache is still performed but happens in the background; this avoids the delay for the first invocation that follows expiry of a cache entry.


 Ice.BackgroundLocatorCacheUpdates 


2  报异常IceUtil::NullHandleException:

Null Smart Pointers

A null smart pointer contains a null C++ pointer to its underlying instance. This means that if you attempt to dereference a null smart pointer, you get an IceUtil::NullHandleException:

C++
TimeOfDayPtr tod;               // Construct null handle

try {
    tod->minute = 0;            // Dereference null handle
    assert(false);              // Cannot get here
} catch (const IceUtil::NullHandleException&) {
    ; // OK, expected
} catch (...) {
    assert(false);              // Must get NullHandleException
}


Default constructor

You can default-construct a proxy handle. The default constructor creates a proxy that points nowhere (that is, points at no object at all). If you invoke an operation on such a null proxy, you get an IceUtil::NullHandleException:

C++
try {
    SimplePrx s;        // Default-constructed proxy
    s->op();            // Call via nil proxy
    assert(0);          // Can't get here
} catch (const IceUtil::NullHandleException&) {
    cout << "As expected, got a NullHandleException" << endl;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值