客户端向服务器发出远程调用请求后立即返回,不会阻塞等待;
服务器接收到来自客户端的请求后,把任务放到线程队列中,让工作线程的空闲的时候处理,而不是等待处理。
ICE定义:
#ifndef HELLO_ICE
#define HELLO_ICE
module Demo
{
exception RequestCanceledException
{
};
interface Hello
{
["ami", "amd"] void sayHello(int delay)
throws RequestCanceledException;
idempotent void shutdown();
};
};
#endif
客户端源码:
#include <Ice/Application.h>
#include "Hello.h"
using namespace std;
using namespace Demo;
//*********************************************************************************************************
//异步调用接口的输出参数和返回值
//统统成为了回调对象的输入参数
class AMI_Hello_sayHelloI : public AMI_Hello_sayHello
{
public:
//异步方法调用成功
virtual void ice_response(){cout << "sayHello_async Successfully !" << endl;}
//异步方法调用异常
virtual void ice_exception(const Ice::Exception& ex){cerr << "sayHello_async Failed : " << ex << endl;}
};
//*********************************************************************************************************
class AsyncClient : public Ice::Application
{
public:
virtual int run(int, char*[]);
virtual void interruptCallback(int);
private:
void menu();
};
int main(int argc, char* argv[])
{
AsyncClient app;
return app.main(argc, argv);
}
int AsyncClient::run(int argc, char* argv[])
{
callbackOnInterrupt();
HelloPrx hello = HelloPrx::checkedCast(communicator()->stringToProxy("hello:default -p 10000"));
if(!hello) {
cerr << ar