1    消息队列

ACE消息队列由三个部分组成:消息队列(ACE_Message_Queue)、消息块(ACE_Message_Block)、数据块(ACE_Data_Block)

1.1    ACE_Data_Block:通过计数器来决定数据块释放时是否被删除。只有计数器为0时,对象才会被删除。

1.1.1  构造函数:

 ACE_Data_Block (size_t size,

                                 ACE_Message_Block::ACE_Message_Type msg_type,

                                 const char *msg_data,

                                 ACE_Allocator *allocator_strategy,

                                 ACE_Lock *locking_strategy,

                                 ACE_Message_Block::Message_Flags flags,

                                 ACE_Allocator *data_block_allocator)

可以由对象自己分配内存(msg_data=0),也可以由使用者分配内存(赋值给msg_data),ACE_Data_Block进行管理。

1.1.2  得到数据块指针:

char *base (void) const;

1.1.3  引用数据块:计算器加1

ACE_Data_Block *duplicate (void);

1.1.4  释放数据块:当计算器减1,当计数器变成0后,就销毁数据块。

ACE_Data_Block *release (ACE_Lock *lock = );

1.2    ACE_Message_Block:数据块的引用。由消息队列管理。

1.2.1  构造函数:

由数据块构造消息块:

ACE_Message_Block (ACE_Data_Block *data_block,

                     Message_Flags flags = ,

                     ACE_Allocator *message_block_allocator = );

直接引用数据:

 ACE_Message_Block (const char *data,

                                       size_t size,

                                       unsigned long priority)

 ACE_Message_Block (size_t size,

                                       ACE_Message_Type msg_type,

                                       ACE_Message_Block *msg_cont,

                                       const char *msg_data,

                                       ACE_Allocator *allocator_strategy,

                                       ACE_Lock *locking_strategy,

                                       unsigned long priority,

                                       const ACE_Time_Value &execution_time,

                                       const ACE_Time_Value &deadline_time,

                                       ACE_Allocator *data_block_allocator,

                                       ACE_Allocator *message_block_allocator)

1.2.2  得到数据块指针:

ACE_Data_Block *data_block()

1.2.3  释放消息块:

ACE_Message_Block *release (void)

1.2.4   析构函数:

会调用内部数据块的release

 ACE_Message_Block::~ACE_Message_Block (void)

 {

   ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block");

   if (ACE_BIT_DISABLED (this->flags_,

                         ACE_Message_Block::DONT_DELETE)&&

       this->data_block ())

     this->data_block ()->release ();

   this->prev_ = ;

   this->next_ = ;

   this->cont_ = ;

 }

1.3         ACE_Message_Queue:消息队列

1.3.1  入列

 enqueue (ACE_Message_Block *new_item, ACE_Time_Value *timeout)

 enqueue_head (ACE_Message_Block *new_item, ACE_Time_Value *timeout)

 enqueue_tail (ACE_Message_Block *new_item, ACE_Time_Value *timeout)

1.3.2   出列

 dequeue (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = );

 dequeue_head (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = );

 dequeue_tail (ACE_Message_Block *&dequeued, ACE_Time_Value *timeout = );

1.4         ACE_Task:封装了消息队列:

 // For the following five method if @a timeout == 0, the caller will

   // block until action is possible, else will wait until the

   // <{absolute}> time specified in *@a timeout elapses).  These calls

   // will return, however, when queue is closed, deactivated, when a

   // signal occurs, or if the time specified in timeout elapses, (in

   // which case errno = EWOULDBLOCK).

   /// Insert message into the message queue.  Note that @a timeout uses

   /// <{absolute}> time rather than <{relative}> time.

   int putq (ACE_Message_Block *, ACE_Time_Value *timeout = );

   /**

    * Extract the first message from the queue (blocking).  Note that

    * @a timeout uses <{absolute}> time rather than <{relative}> time.

    * Returns number of items in queue if the call succeeds or -1 otherwise.

    */

   int getq (ACE_Message_Block *&mb, ACE_Time_Value *timeout = );

   /// Return a message to the queue.  Note that @a timeout uses

   /// <{absolute}> time rather than <{relative}> time.

   int ungetq (ACE_Message_Block *, ACE_Time_Value *timeout = );

   /**

    * Turn the message around, sending it in the opposite direction in

    * the stream. To do this, the message is put onto the task next in

    * the stream after this task's sibling.

    *

    * @param mb Pointer to the block that is used in the reply.

    * @param tv The absolute time at which the put operation used to

    *           send the message block to the next module in the stream

    *           will time out. If 0, this call blocks until it can be

    *           completed.

    */

   int reply (ACE_Message_Block *mb, ACE_Time_Value *tv = );

   /**

    * Transfer message to the adjacent ACE_Task in a ACE_Stream.  Note

    * that @a timeout uses <{absolute}> time rather than <{relative}>

    * time.

    */

   int put_next (ACE_Message_Block *msg, ACE_Time_Value *timeout = );

转自:http://blog.csdn.net/kl222/article/details/8159812

ACE消息队列(转)的更多相关文章

  1. 阿里云ACE共创空间——MQ消息队列产品测试

    一.产品背景消息队列是阿里巴巴集团自主研发的专业消息中间件. 产品基于高可用分布式集群技术,提供消息订阅和发布.消息轨迹查询.定时(延时)消息.资源统计.监控报警等一系列消息云服务,是企业级互联网架构 ...

  2. 【微服务专题之】.Net6下集成消息队列上-RabbitMQ

    ​ 微信公众号:趣编程ACE关注可了解更多的.NET日常实战开发技巧,如需源码 请公众号后台留言 源码;[如果觉得本公众号对您有帮助,欢迎关注] .Net中RabbitMQ的使用 [微服务专题之].N ...

  3. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  4. 消息队列 Kafka 的基本知识及 .NET Core 客户端

    前言 最新项目中要用到消息队列来做消息的传输,之所以选着 Kafka 是因为要配合其他 java 项目中,所以就对 Kafka 了解了一下,也算是做个笔记吧. 本篇不谈论 Kafka 和其他的一些消息 ...

  5. .net 分布式架构之业务消息队列

    开源QQ群: .net 开源基础服务  238543768 开源地址: http://git.oschina.net/chejiangyi/Dyd.BusinessMQ ## 业务消息队列 ##业务消 ...

  6. 【原创经验分享】WCF之消息队列

    最近都在鼓捣这个WCF,因为看到说WCF比WebService功能要强大许多,另外也看了一些公司的招聘信息,貌似一些中.高级的程序员招聘,都有提及到WCF这一块,所以,自己也关心关心一下,虽然目前工作 ...

  7. Java消息队列--ActiveMq 实战

    1.下载安装ActiveMQ ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Un ...

  8. Java消息队列--JMS概述

    1.什么是JMS JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送 ...

  9. 消息队列性能对比——ActiveMQ、RabbitMQ与ZeroMQ(译文)

    Dissecting Message Queues 概述: 我花了一些时间解剖各种库执行分布式消息.在这个分析中,我看了几个不同的方面,包括API特性,易于部署和维护,以及性能质量..消息队列已经被分 ...

随机推荐

  1. Spring ClassPathXmlApplicationContext和FileSystemXmlApplicationContext读取配置文件的方法

    先说:ClassPathXmlApplicationContext 这个类,默认获取的是WEB-INF/classes/下的路径,也就是在myeclipse的src下的路径,所以用这个是获取不到WEB ...

  2. yii2中判断数据表是否存在数据库中(原创)

    分为两步: 第一步,找出数据库中所有表名,表名得到的是二维数组. 第二步,判断表名是否存在二维数组中 下面就贴我的代码咯. $table_name =‘table’; $juge = $handle- ...

  3. Cookie 的运用

    Cookie的原理是通过Set-Cookie响应头和Cookie请求头将会话中产生的数据保存在客户端.--- 底层(SUN公司已经给我们提供了一套API) Cookie是将需要保存的数据保存在了客户端 ...

  4. js中OOP小指南

    js中OOP小指南 在指南中,我将尝试解析以面向对象规范聚焦的es6的新特性. 首先, 什么是设计模式 范例是某个事务的例子或模型,在某种情况下,按照一种模式创建了计算机程序. 什么是面向对象 显然你 ...

  5. 山东省第八届省赛 A:Return of the Nim(尼姆+威佐夫)

    Problem Description Sherlock and Watson are playing the following modified version of Nim game: Ther ...

  6. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  7. 求第N个回文数 模板

    备忘. /*看到n可以取到2*10^9.说明普通方法一个个暴力计算肯定会超时的,那打表呢?打表我们要先写个打表的代码,这里不提供.打完表观察数据,我们会发现数据其实是有规律的.完全不需要暴力的把所有数 ...

  8. (4)java基础知识

    一.注释 java的注释方法主要有三种 1.单行注释 // 2.多行注释 /*  内容 */ 3.文档注释 /** * * */ 这种方法注释用于生成一份API文档,主要说明 方法的功能.参数.返回值 ...

  9. 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律

    转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...

  10. HDU 6213 Chinese Zodiac 【模拟/水题/生肖】

    Problem Description The Chinese Zodiac, known as Sheng Xiao, is based on a twelve-year cycle, each y ...