# coffice-react **Repository Path**: osscd/coffice-react ## Basic Information - **Project Name**: coffice-react - **Description**: 基于Reactor模型设计以及相关的NIO的多路复用器的封装形成开源组件 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2019-09-28 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README <<<<<<< HEAD # net-reactor it's a simple and easy net framework with nio mode written by java # reactor model ![reactor model](reactor.png) # how-to ## just simply like: ``` public class MyHandler implements Handler { private static final Logger LOGGER = LoggerFactory.getLogger(MyHandler.class); private long readSize; /** * The logic to deal with the received data. * * It means that reactor will trigger this function once the data is received. * @throws IOException */ public void handle(FrontendConnection connection) throws IOException { Buffer buff = connection.getReadBuffer(); readSize = +readSize + buff.position(); LOGGER.info(connection.getId() + " connection has receive " + readSize); } } ``` ``` Handler handler = new MyHandler(); ReactorPool reactorPool = new ReactorPool(Runtime.getRuntime().availableProcessors(), handler); new Acceptor(reactorPool, acceptorName, host, port).start(); ``` ## adding a connection event or a connection multi-event: ``` public class RegisterHandler implements ConnectionEventHandler { private static final Logger LOGGER = LoggerFactory .getLogger(RegisterHandler.class); private static int INTERESTED = ConnectionEvents.REGISTE; public void event(FrontendConnection connection) { if ((event & INTERESTED) != 0) { //do something here } } } ``` ``` Handler handler = new NetHandler(); ConnectionEventHandler connectionEventHandler = new RegisterHandler(); ReactorPool reactorPool = new ReactorPool(Runtime.getRuntime().availableProcessors(), handler); Acceptor acceptor = new Acceptor(reactorPool, acceptorName, host, port); acceptor.addConnectionEventHandler(connectionEventHandler); acceptor.start(); ``` ``` public class ConnectionLogHandler implements ConnectionEventHandler { private static final Logger LOGGER = LoggerFactory .getLogger(ConnectionLogHandler.class); private static int INTERESTED = ConnectionEvents.ACCEPT | ConnectionEvents.CLOSE; public void event(Connection connection, int event) { if ((event & INTERESTED) != 0) { if ((event & ConnectionEvents.ACCEPT) != 0) LOGGER.info("accept connection,id is " + connection.getId()); if ((event & ConnectionEvents.CLOSE) != 0) LOGGER.info("close connection,id is " + connection.getId()); } } } ``` ## implements the connection ``` public class XXXConnection extends Connection { private String name; public XXXConnection(SocketChannel channel, long id, Reactor reactor) { super(channel, id, reactor); } public String getName() { return name; } public void setName(String name) { this.name = name; } } ``` ``` public class XXXConnectionFactory implements ConnectionFactory { public XXXConnection createConnection(SocketChannel channel, long id, Reactor reactor) { return new XXXConnection(channel, id, reactor); } } ``` ``` Acceptor acceptor = new Acceptor(reactorPool, acceptorName, host,port); acceptor.setConnectionFactory(new xxxConnectionFactory()); ``` ======= # coffice-reactor #### 介绍 基于Reactor模型设计以及相关的NIO的多路复用器的封装形成开源组件 #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) >>>>>>> 02af8140cd77abdd24f6f727b8fe8f35a372c46b