Active Object pattern in Ace)

Source: Internet
Author: User

Passive objects are normally put there and will not be moved, waiting for other execution threads to call and then will be executed. Active objects generally contain execution threads and can actively execute code.

 

1. The active object is based on the ace_task class and provides the execution thread.

 

2. When some code to be executed is to be executed, it should be put into a queue. Then, when the execution thread finds that the queue is not empty, it will retrieve the objects in the queue from the queue and then execute it. This queue is ace_activation_queue.

 

3. objects placed in ace_activation_queue are called method objects. These objects inherit from ace_method_object. ace_method_object provides a virtual function named "call" (which has only three functions, the other two are a constructor and a constructor), which implements the call function of the method object and can be called in the SVC function of the active object (inherited from the ace_task class.

4. to obtain the result of an asynchronous operation, you also need the ace_future object. After the asynchronous execution is complete, the execution thread sets this object. If you want to obtain the result before setting, it will be blocked until it is set.

Therefore, the process is as follows:

(1) create an active object and call its open function (activate is called in open, and SVC is called ).

(2) Call the dequeue () function of ace_activation_queue cyclically in the active object. If there is no method object in ace_activation_queue, it will be blocked.

(3) If a method object exists in ace_activation_queue at a time, the function will be successfully executed and passed, and it will return the pointer to the method object, then you can call the call function of this method object.

In this way, the method object will be successfully executed.

 

When an active object is used, it is put into ace_activation_queue after initialization of a method object, and other things are completed by the above steps.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.