• 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;
    }
  • 相关阅读:
    比官方文档更易懂的Vue.js教程!包你学会!
    张腾:腾讯云融合通信应用场景及案例分享
    你大概走了假敏捷:《手绘敏捷宝典》在此,还不来收!
    这个PHP无解深坑,你能解出来吗?(听说能解出来的都很秀)
    从小数学就不及格的我,竟然用极坐标系表白了我的女神!(附代码)
    epoll
    hash_map
    BloomFilter
    Wrapper模式(Decorator模式)
    setvbuf
  • 原文地址:https://www.cnblogs.com/bbqzsl/p/6560589.html
Copyright © 2020-2023  润新知