zoukankan      html  css  js  c++  java
  • Reactor模式

    文章来源于http://www.blogjava.net/DLevin/archive/2015/09/02/427045.html
    Reactor模式实现

    这是一个简单的例子来理解Reactor。

    Client连接到Logging Server

    1. Logging Server注册LoggingAcceptor到InitiationDispatcher。
    2. Logging Server调用InitiationDispatcher的handle_events()方法启动。
    3. InitiationDispatcher内部调用select()方法(Synchronous Event Demultiplexer),阻塞等待Client连接。
    4. Client连接到Logging Server。
    5. InitiationDisptcher中的select()方法返回,并通知LoggingAcceptor有新的连接到来。
    6. LoggingAcceptor调用accept方法accept这个新连接。
    7. LoggingAcceptor创建新的LoggingHandler。
    8. 新的LoggingHandler注册到InitiationDispatcher中(同时也注册到Synchonous Event Demultiplexer中),等待Client发起写log请求。

    Client向Logging Server写Log

    1. Client发送log到Logging server。
    2. InitiationDispatcher监测到相应的Handle中有事件发生,返回阻塞等待,根据返回的Handle找到LoggingHandler,并回调LoggingHandler中的handle_event()方法。
    3. LoggingHandler中的handle_event()方法中读取Handle中的log信息。
    4. 将接收到的log写入到日志文件、数据库等设备中。
      3.4步骤循环直到当前日志处理完成。
    5. 返回到InitiationDispatcher等待下一次日志写请求。
  • 相关阅读:
    什么是web框架
    编写CGI程序步骤
    web开发 c/s结构 和 b/s结构
    python自带的web服务器
    自制计算器
    条件判断
    模版继承
    参数传递
    异常处理
    【uoj#244】[UER #7]短路 CDQ分治+斜率优化dp
  • 原文地址:https://www.cnblogs.com/noor/p/6195281.html
Copyright © 2011-2022 走看看