reactor design pattern

详见:http://en.wikipedia.org/wiki/Reactor_pattern

The reactor design pattern is ??an event handling pattern for handling service requests delivered(交付的)concurrently(并行的) to a service handler by one or more inputs. ??The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.

Properties

All reactor systems are single threaded by definition, but can exist in a multithreaded environment.

Benefits

The reactor pattern completely separates application specific code from the reactor implementation, which means that application components can be divided into modular(模块化), reusable(可复用的) parts. Also, due to the synchronous calling of request handlers, the reactor pattern allows for simple coarse-grain concurrency while not adding the complexity of multiple threads to the system.

Limitations

The reactor pattern can be more difficult to debug than a procedural pattern due to the inverted flow of control. Also, by only calling request handlers synchronously, the reactor pattern limits maximum concurrency, especially on Symmetric multiprocessing hardware. The scalability of the reactor pattern is limited not only by calling request handlers synchronously, but also by the demultiplexer. 

最后看一个在网络编程中的Reactor模式示意图,

=========================END=========================

时间: 2024-08-01 10:46:59

reactor design pattern的相关文章

DP什么意思 design pattern 设计模式

DP  design pattern 大话设计模式  中的DP 是设计模式的意思 设计模式的书 ,最经典最原始的就是 GOF 的<设计模式>了. 设计模式的书基本上大多是以这 20 多个模式分开讲.含<大话设计模式> 学了 OOL 写的程序基本上是 OB 的. 只有慢慢掌握了 DP 才能写出真正的 OO 程序. 思想 -> 设计原则 -> DP -> OOD

Head First Design Pattern 读书笔记(2) 观察者模式

Head First Design Pattern 读书笔记(2) Observer Pattern 观察者模式 Observer Pattern 类图 定义 观察者模式:在对象间定义一个一对多的关系,当其中一个的对象发生改变时,所有依赖于这个对象的对象(即观察者们)都会自动更新或做执行某些行为. 几个OO的原测 尽量以松耦合的方式处理对象间关系–>软件工程时候学的"高內聚,低耦合"的好处 关于观察者模式 被观察对象通知观察者可以使用推送的方式(类图中带参数的notifyActi

Design Pattern Singleton 单一模式

单一模式的几个注意点: 一) 设计单一模式,首先需要把构造函数给私有化了,不让外界访问,那么外界只能通过提供的函数获取一个新的类. 二) C++的单一模式,记得要在类外初始化一个类,否则或内存出错的. 三) 这个唯一的类必须是要静态的 程序: #ifndef _SINGLETON_H #define _SINGLETON_H #include <iostream> #include <string> using namespace std; class DuGuJiuJian {

Design Pattern 设计模式1 - Strategy 1

实现 : Defferent Heros attack Defferently. - 不同的英雄使用不用的招数 Strategy设计的思路: 基类A,更加小的基类B,新的继承类C: 1 从基类A中抽出一个更加小的基类B 2 利用这个更加小的基类B实现不同的效果 3 把这个更加小的基类B包含进基类A中去 4 新的继承类C只需要和基类A打交道,设计不同行为,不需要理会更加小的基类B #pragma once #ifndef _STRATEGY_HEROS_H #define _STRATEGY_HE

简单工厂设计模式(Simple Factory Design Pattern)

[引言]最近在Youtub上面看到一个讲解.net设计模式的视频,其中作者的一个理解让我印象很深刻:所谓的设计模式其实就是运用面向对象编程的思想来解决平时代码中的紧耦合,低扩展的问题.另外一点比较有见解的是,区分了设计模式(Design Pattern),结构模式(Architecture Pattern),架构类型(Architecture Style). 如下图所示 Design Pattern:是基于代码层面的,就是针对解决功能模块之间的问题而采用恰当的设计模式,比如依赖注入,简单工厂,适

Design Pattern —— Singleton

Design Pattern —— Singleton   强力推荐枚举和类级内部类方式实现单例模式 单例模式是开发中非常常用的一种模式,简单的说,我们希望一个类永远都只有一个对象. 主要有两个用途: 1.存储一些进程内共享的值(不是很推荐,大部分情况下还是应该用局部变量,互相传递值的方式) 2.任何时候都不变的操作 单例模式的实现目前已知的有五种: 1.饿汉式 2.懒汉式 3.双重验证 4.类级内部类 5.枚举 一.饿汉式 类加载时就创建好对象,以空间换时间.这样外部调用EagerSingle

Head First Design Pattern 读书笔记(1) 策略模式

Head First Design Pattern 读书笔记(1) Strategy Pattern 策略模式 这几天为了锻炼看英语文档的能力,开着有道硬着头皮看 <Head First Desgin Pattern>的原版书,顺便做下笔记,把里面提到的每个模式通过回忆的方式画出来复习并记下来总结下学习成果=.= 关于设计模式 使用设计模式是为了增强程序的复用性,拓展性,易维护性. 设计模式会增加程序代码的复杂度,并不是所有情况都必须使用设计模式,需要根据需求以及经验评估使用场景. 学习并掌握

State Design Pattern 状态设计模式

设置好内部状态,然后根据不同的函数作为行为模式,进行状态转换. 有点像Finite Automata算法,两者的思想是一样的. 会Finite Automata,那么这个设计模式就很容易了. #pragma once #include <stdlib.h> #include <math.h> #include <random> #include <time.h> enum STATES { FULLY_RENTED, WAITING, GOT_APPLICA

UML for Design Pattern

************************************************************************************* ************************************************************************************* ******************************************************************************