ICE 学习进阶2-AMI 方式
来源:互联网 发布:常州一名网络女主播 编辑:程序博客网 时间:2024/06/05 23:45
1. AMI :
When a client issues an AMI request, the Ice run time hands the message off to the local transport buffer or, if the buffer is currently full, queues the request for later delivery. The application can then continue its activities and poll or wait for completion of the invocation, or receive a callback when the invocation completes.
AMI is transparent to the server: there is no way for the server to tell whether a client sent a request synchronously or asynchronously.
2. ICE 支持AMI方式,即为每个接口Func,自动增加begin_Func() 和 end_Func()两个接口,如下示例:
Ice::AsyncResultPtr r = APrintPrx->begin_PrintString("hello,world"); // 不阻塞
APrintPrx->end_PrintString(r); //因为PrintString没有返回值 //阻塞
Note that begin_getName returns a value of type AsyncResultPtr.The AsyncResult associated with this smart pointer contains the state that the Ice run time requires to keep track of the asynchronous invocation. You must pass the AsyncResultPtr that is returned by the begin_ method to the corresponding end_ method.
The begin_ method has one parameter for each in-parameter of the corresponding Slice operation. Similarly, the end_ method has one out-parameter for each out-parameter of the corresponding Slice operation (plus the AsyncResultPtr
parameter).
begin_函数和end_函数要捕获 CommunicatorDestroyedException.异常; 而且end_函数还有捕获函数执行的异常
3. AsyncResult 类介绍
The AsyncResult that is returned by the begin_ method encapsulates the state of the asynchronous invocation,有如下几个接口
waitForCompleted(): This method blocks the caller until the result of an invocation becomes available.
void waitForSent() : This method blocks the calling thread until a request has been written to the client-side transport
CommunicatorPtr getCommunicator() const :This method returns the communicator that sent the invocation.
virtual ConnectionPtr getConnection() const :This method returns the connection that was used for the invocation.
virtual ObjectPrx getProxy() const :This method returns the proxy that was used to call the begin_ method.
const string& getOperation() const :This method returns the name of the operation.
LocalObjectPtr getCookie() const:This method returns the cookie that was passed to the begin_ method ,If you did not pass a cookie to the begin_ method, the return value is null.
bool isCompleted() const:This method returns true if, at the time it is called, the result of an invocation is available,indicating that a call to the end_ method will not block the caller.Otherwise, if the result is not yet available, the method returns false.
bool sentSynchronously() const:This method returns true if a request was written to the client-side transport without first being queued. If the request was initially queued, sentSynchronously returns false
bool isSent() const: isSent returns true if, at the time it is called, the request has been written to the local transport (whether it was initially queued or not). Otherwise, if the
request is still queued, isSent returns false.
4 一个异步调用,提高系统性能的例子:
//////////////
FileHandle file = open(...);
FileTransferPrx ft = ...;
const int chunkSize = ...;
Ice::Int offset = 0;
list<Ice::AsyncResultPtr> results;
const int numRequests = 5;
while (!file.eof()) {
ByteSeq bs;
bs = file.read(chunkSize);
// Send up to numRequests + 1 chunks asynchronously.
Ice::AsyncResultPtr r = ft->begin_send(offset, bs);
offset += bs.size();
// Wait until this request has been passed to the transport.
r->waitForSent();
results.push_back(r);
// Once there are more than numRequests, wait for the least
// recent one to complete.
while (results.size() > numRequests) {
Ice::AsyncResultPtr r = results.front();
results.pop_front();
r->waitForCompleted();
}
}
// Wait for any remaining requests to complete.
while (!results.empty()) {
Ice::AsyncResultPtr r = results.front();
results.pop_front();
r->waitForCompleted();
}
/////////////
5. 将异步请求,批量请求
Applications that send batched requests (see Section 32.16) can either flush a
batch explicitly or allow the Ice run time to flush automatically. The proxy method
ice_flushBatchRequests performs an immediate flush using the synchronous
invocation model and may block the calling thread until the entire message
can be sent. Ice also provides asynchronous versions of this method so you can
flush batch requests asynchronously.
begin_ice_flushBatchRequests and
end_ice_flushBatchRequests are proxy methods that flush any batch
requests queued by that proxy.
- ICE 学习进阶2-AMI 方式
- ICE学习(八)-异步方法调用AMI
- ICE 学习进阶3-注意事项
- ICE的AMI方法调用
- Ice异步程序设计----AMI,AMD
- ICE异步程序设计-----AMI/AMD
- ICE 学习进阶1-Printer Demo开发
- ICE 学习进阶4-配置属性
- Ice客户端的同步及AMI异步模式-JAVA
- 学习ICE——2
- ICE学习
- ICE专题:学习ICE 3.0
- Asterisk学习笔记之 -- AMI篇
- ICE学习(一) ICE 编程模型
- ICE学习(二)-Ice编程 C++
- ICE学习(三)-Ice Services介绍
- ICE学习(四)-Ice Box介绍
- ICE学习(五)-Ice Storm介绍
- 角色价值取决于社会评价和个人能力
- 修改注册表挖掘IE的潜力
- LPC2478中几个时钟频率的解释
- 在 Linux 下用户空间与内核空间数据交换的方式,第 2 部分: procfs、seq_file、debugfs和relayfs
- Symbian改变默认背景,默认字体颜色(转载)
- ICE 学习进阶2-AMI 方式
- lca&rmq
- 写一个函数,把数组里的奇数放前面。偶数放后面。比如[1, 2, 3, 4, 5],处理后得到[1, 3, 5, 2, 4]。
- Qt4 model/view结构之实现自定义模型
- 滑块控件 (Slider Control) 样式
- 发布:Visual Studio 2010 一站式示例代码搜索扩展
- hibernate框架初学
- Win7开启wifi热点
- 数组中的方括号([ ])三种使用方法