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) //获得代理的超时时间
示例代码:
- Filesystem::FilePrx myFile = ...;
- FileSystem::FilePrx timeoutFile
- = FileSystem::FilePrx::uncheckedCast(
- myFile->ice_timeout(5000));
- try {
- Lines text = timeoutFile->read(); // Read with timeout
- } catch(const Ice::TimeoutException &) {
- cerr << "invocation timed out" << endl;
- }
- 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
:
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
:
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; }