快速业务通道

Active Object并发模式在Java中的应用 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-14
e object.    void put (const Message &msg) {      Method_Request *mr = new Put(servant_,msg);      scheduler_.insert (mr);    }    // Return a <Message_Future> as the "future" result of     // an asynchronous <get> method on the active object.    Message_Future get () {      Message_Future result;      Method_Request *mr = new Get (&servant_,result);      scheduler_.insert (mr);      return result;    }    // empty() and full() predicate implementations ... private:    // The servant that implements the active object    // methods and a scheduler for the message queue.    MQ_Servant servant_;    MQ_Scheduler scheduler_; };

Active Object并发模式在Java中的应用(4)

时间:2011-10-22 IBM 李三红

同一个进程中的多个调用者线程可以共享同一个 Proxy。

实现 Method Request,如清单 3 所示:

清单 3. Method_Request

class Method_Request { public:    // Evaluate the synchronization constraint.    virtual bool can_run () const = 0    // Execute the method.    virtual void call () = 0; }; // Inherites from Method_Request class Get : public Method_Request { public:    Get (MQ_Servant *rep, const Message_Future &f)    :servant_ (rep),    result_ (f)    {    }    virtual bool can_run () const {      // Synchronization constraint: cannot call a      // <get> method until queue is not empty.      return !servant_->empty ();    }    virtual void call () {      // Bind dequeued message to the future result.      result_ = servant_->get ();    } private:    MQ_Servant *servant_;    Message_Future result_; };

实现 Activation List,如清单 4 所示:

清单 4. Activation_List

class Activation_List { public:    // Block for an "infinite" amount of time waiting    // for <insert> and <remove> methods to complete.    enum { INFINITE = -1 };    // Define a "trait".    typedef Activation_List_Iterator iterator;    Activation_List ();    // Insert <method_request> into the list, waiting up    // to <timeout> amount of time for space to become    // available in the queue. Throws the <System_Ex>    // exception if <timeout> expires.    void insert (Method_Request *method_request,Time_Value *timeout = 0);    // Remove <method_request> from the list, waiting up    // to <timeout> amount of time for a <method_request>    // to be inserted into the list. Throws the    // <System_Ex> exception if <timeout> expires.    void remove (Method_Request *&method_request, Time_Value *timeout =  0); private:    // Synchronization mechanisms, e.g., condition    // variables and mutexes, and

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号