Activeio :: CORE Framework Guide Guide
Activeio is a lightweight core framework developed based on Java. It is suitable for building high -performance network applications.This article will introduce the guidelines for the Activeio framework and provide some Java code examples.
1. Introduction to Activeio framework
The Activeio framework is an event driving framework based on NIO (Non-Blocking I/O). It provides efficient network communication capabilities and supports the processing of asynchronous events.Activeio uses multi -road reuse technology to monitor multiple network connections through a cycle of events, thereby increasing the throughput and response speed of the system.
Second, the core component of the Activeio framework
1. IOHANDLER (I/O processor): Responsible for handling network I/O events, such as receiving, reading, writing, and closing connections.
2. IOSESSION (I/O session): indicate a network connection.Each IOSESSION is associated with an iOhandler to handle the event on the connection.
3. IoConnector (I/O connector): Used to create client connection.
4. IOACCEPTOR (I/O receiver): It is used to receive and process the connection request of the client.
5. IOFILTER (I/O filter): used to process data conversion before and after I/O event, such as decoding, coding, and encryption.
6. IOSERVICE (I/O service): It is the parent interface of IOACCEPTOR and IoConnector, defining common interfaces and methods.
Third, the use of the Activeio framework
1. Introduction dependencies: Add the dependencies of Activeio in the construction file of the project (such as Pom.xml).
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.3</version>
</dependency>
2. Create IOHANDLER: Write a processor class that implements from the IOHANDLER interface, and implement the corresponding event processing method.
public class MyIoHandler extends IoHandlerAdapter {
@Override
public void sessionOpened(IoSession session) throws Exception {
// Treatment the newly established connection
}
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
// Process the receiving message
}
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
// Treatment anomalous events
}
@Override
public void sessionClosed(IoSession session) throws Exception {
// Handle the connection closing event
}
}
3. Create IOACCEPTOR or IoConnector: According to actual needs, select IoAcceptor or IoConnector on the creation server.
IoAcceptor acceptor = new NioSocketAcceptor();
4. Configure IOACCEPTOR or IoConnector: Set related parameters, such as listening ports, iOhandler, and iOFILTER.
acceptor.setHandler(new MyIoHandler());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory()));
acceptor.getSessionConfig().setReadBufferSize(2048);
5. Binding port or establishment connection: Bind a specific port or establish a connection by calling the Bind () method or the connect () method.
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8080);
acceptor.bind(address);
6. Processing I/O event: Use the Activeio framework to process I/O events by the callback mechanism.
acceptor.setHandler(new MyIoHandler());
7. Close connection: When you need to close the connection, call the close () method of IOSESSION.
session.close();
Fourth, summary
Activeio is a high -performance network application development framework. By using the Activeio framework, we can easily build high -efficiency and reliable network applications.This article introduces the core components and use steps of the Activeio framework, and provides some Java code examples. I hope to help you understand and use the Activeio framework.