提交 2ff78184 编写于 作者: N Narendra Pathai

Work on #74, added class diagram and index.md

上级 5bacfce7
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="true" nesting-relationships="true">
<class id="1" language="java" name="java.nio.channels.Selector" project="abstract-factory"
file="/opt/Softwares/Eclipses/MARS/eclipse/jre/lib/rt.jar" binary="true" corner="BOTTOM_RIGHT">
<position height="224" width="188" x="1120" y="-50"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="false" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="com.iluwatar.reactor.framework.NioReactor" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/NioReactor.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="760" y="19"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="false" static="true"/>
</display>
</class>
<interface id="3" language="java" name="com.iluwatar.reactor.framework.Dispatcher" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/Dispatcher.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="569" y="279"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="4" language="java" name="com.iluwatar.reactor.framework.SameThreadDispatcher" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/SameThreadDispatcher.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="291" y="562"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="com.iluwatar.reactor.framework.ThreadPoolDispatcher" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/ThreadPoolDispatcher.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="115" width="356" x="341" y="375"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="6" language="java" name="com.iluwatar.reactor.framework.AbstractNioChannel" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/AbstractNioChannel.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="935" y="265"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="false" static="true"/>
</display>
</class>
<class id="7" language="java" name="com.iluwatar.reactor.framework.NioServerSocketChannel" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/NioServerSocketChannel.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="836" y="543"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="8" language="java" name="com.iluwatar.reactor.framework.NioDatagramChannel" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/NioDatagramChannel.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1110" y="539"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="9" language="java" name="java.nio.channels.ServerSocketChannel" project="abstract-factory"
file="/opt/Softwares/Eclipses/MARS/eclipse/jre/lib/rt.jar" binary="true" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="609" y="540"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="false" protected="true" private="false" static="true"/>
<operations public="false" package="true" protected="false" private="true" static="true"/>
</display>
</class>
<class id="10" language="java" name="java.nio.channels.DatagramChannel" project="abstract-factory"
file="/opt/Softwares/Eclipses/MARS/eclipse/jre/lib/rt.jar" binary="true" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1202" y="395"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="false" package="true" protected="false" private="true" static="true"/>
</display>
</class>
<interface id="11" language="java" name="com.iluwatar.reactor.framework.ChannelHandler" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/framework/ChannelHandler.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="303" y="-1"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="12" language="java" name="com.iluwatar.reactor.app.LoggingHandler" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/app/LoggingHandler.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="297" y="147"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="false" static="true"/>
</display>
</class>
<class id="13" language="java" name="com.iluwatar.reactor.app.App" project="reactor"
file="/reactor/src/main/java/com/iluwatar/reactor/app/App.java" binary="false" corner="BOTTOM_RIGHT">
<position height="133" width="148" x="123" y="266"/>
<display autosize="false" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="false" static="true"/>
<operations public="true" package="true" protected="true" private="false" static="true"/>
</display>
</class>
<realization id="14">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="3"/>
</realization>
<association id="15">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="16" name="dispatcher"/>
<multiplicity id="17" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="18">
<bendpoint x="309" y="348"/>
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="3"/>
</realization>
<association id="19">
<bendpoint x="460" y="203"/>
<end type="SOURCE" refId="13" navigable="false">
<attribute id="20" name="reactor"/>
<multiplicity id="21" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="22">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="10"/>
</dependency>
<generalization id="23">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="6"/>
</generalization>
<association id="24">
<end type="SOURCE" refId="6" navigable="false">
<attribute id="25" name="handler"/>
<multiplicity id="26" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="11" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="27">
<end type="SOURCE" refId="6" navigable="false">
<attribute id="28" name="reactor"/>
<multiplicity id="29" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<dependency id="30">
<end type="SOURCE" refId="13"/>
<end type="TARGET" refId="12"/>
</dependency>
<association id="31">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="32" name="selector"/>
<multiplicity id="33" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="34">
<end type="SOURCE" refId="12"/>
<end type="TARGET" refId="11"/>
</realization>
<generalization id="35">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="6"/>
</generalization>
<dependency id="36">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="9"/>
</dependency>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>
\ No newline at end of file
---
layout: pattern
title: Reactor
folder: reactor
permalink: /patterns/reactor/
categories: Architectural
tags:
- Java
- Difficulty-Expert
---
**Intent:** The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients. The application can register specific handlers for processing which are called by reactor on specific events. Dispatching of event handlers is performed by an initiation dispatcher, which manages the registered event handlers. Demultiplexing of service requests is performed by a synchronous event demultiplexer.
![Reactor](./etc/reactor.png "Reactor")
**Applicability:** Use Reactor pattern when
* a server application needs to handle concurrent service requests from multiple clients.
* a server application needs to be available for receiving requests from new clients even when handling older client requests.
* a server must maximize throughput, minimize latency and use CPU efficiently without blocking.
**Real world examples:**
* [Spring Reactor](http://projectreactor.io/)
**Credits**
* [Douglas C. Schmidt - Reactor](https://www.dre.vanderbilt.edu/~schmidt/PDF/Reactor.pdf)
* [Doug Lea - Scalable IO in Java](http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf)
* [Netty](http://netty.io/)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册