ZeroC ICE的远程调用框架 AMD

继上一篇《ZeroC ICE的远程调用框架》,本篇再来说其中的AMD。(本篇需要重写)

当在ice文件中声明某个接口方法Method为["amd"]后,接口方法在stub类生成的远程调用框架代码不会变,但在skeleton类生成的就不是_iceD_Method和Method,而是_iceD_Method和Method_async。而amd模式和非amd模式的代码生成模板区别在于,_iceD_Method调用Method_async代替Method,并且在调用后不进行out方向参数的处理。另外还会生成AMD_Module_Method类,用于Method_aysnc的参数。

在Ice远程调用中,有两种调用模式,Twoway和Oneway。Twoway的意是一个完整的请求包含一请求以及一应答,Oneway就是不需要这个应答。在Twoway模式下,即使声明接口方法返回void(即不返回结果),并且没有out方向的参数,skeleton类在完成接口调用后,还要写一个应答消息,消息包含应答状态,告诉代理端调用成功或失败。代理端的AsyncResult(即Future)也要阻塞或不阻塞等待这个应答消息。但是在amd模式(即Oneway)中,skeleton类在完成接口调用后,并不需要写回一个应答消息,代理端的AsyncResult也会忽略等待这个请求应答。

void
IceProxy::Ice::Object::_end(const ::Ice::AsyncResultPtr& result, const std::string& operation) const
{
    AsyncResult::check(result, this, operation);
    bool ok = result->waitForResponse();
    if(_reference->getMode() == Reference::ModeTwoway)
    {
        if(!ok)
        {
            try
            {
                result->throwUserException();
            }
            catch(const UserException& ex)
            {
                throw UnknownUserException(__FILE__, __LINE__, ex.ice_id());
            }
        }
        result->readEmptyParams();
    }
}
bool
Test::TestIntf::_iceD_Method(::IceInternal::Incoming& inS, const ::Ice::Current& current)
{
    _iceCheckMode(::Ice::Normal, current.mode);
    inS.readEmptyParams();
    this->Method_async(new IceAsync::Test::AMD_TestIntf_startDispatch(inS), current);
    return true;
}

 

posted on 2017-03-16 20:43  bbqz007  阅读(454)  评论(0编辑  收藏  举报