Apache Mina study notes (3) - IoService
In this chapter, we describe MINA's IoService - a basic class that provides all I/O services on the server and client. It is used to send and receive messages with the peer, manage seions, connections, etc.
It is an interface implemented by IoAcceptor on the server side and IoConnector on the client side.
We will introduce this interface in the following parts:
IoService Introduction
IoService Details
IoAcceptor
IoConnector
IoService Introduction
IoService provides basic I/O services in the Mina framework and manages I/O Sessions. It is a very critical part of Mina.
As mentioned in the above figure, IoService has many responsibilities:
Session management
Filter chain management
Handler call
Statistics management
Listening management
Communication management
Methods in this interface:
getTransportMetadata();
When IoAcceptor or IoConnector is running, this method returns Transmitted metadata, usually including name (nio, apr, txtx), connection type (connection-oriented or connectionless).
addListener
Allows adding an IoServiceListener to listen to specified events
removeListener
Removes a specified IoserviceListener
isDisposing
If the service is Disposed, then return the status of the service
isDisposed
If the service has been Disposed, then return the status of the service
dispose
Used to release all resources requested by the service. Users need to use the above two methods to first check whether the service has been completely disposed. When you want to shut down the service, be sure to call this method
getHandler
Return the method associated with the service
setHandler
Set the IoHandler to solve the problem that the server gets request, the Handler contains your program logic
getSessionConfig
Returns the session configuration
getFilterChainBuilder
Returns to the Filter chain builder, when filtering needs to be added When, this method needs to be called.
IoService Details
Ioservice This interface is implemented by two important classes in MINA: IoAcceptor and IoConnector. On the server side, you need to choose IoAcceptor, and on the client side, you need to choose IoConnector.
IoAcceptor
In MINA, there are some already implemented classes:
NioSocketAcceptor : the non-blocking Socket transport IoAcceptor
NioDatagramAcceptor : the non-blocking UDP transport IoAcceptor
AprSocketAcceptor : the blocking Socket transport IoAcceptor, based on APR
VmPipeSocketAcceptor : the in-VM IoAcceptor
Choose the IoAcceptor you need.
The following figure is the IoAcceptor class and interface
IoConnector
NioSocketConnector : the non-blocking Socket transport IoConnector
NioDatagramConnector : the non-blocking UDP transport IoConnector
AprSocketConnector : the blocking Socket transport IoConnector, based on APR
ProxyConnector : a IoConnector providing proxy support
SerialConnector : a IoConnector for a serial transport
VmPipeConnector : the in-VM IoConnector
For example, when you want to create a TCP server, you You can write code similar to the following
public TcpServer() throws IOException { // Create a TCP acceptor IoAcceptor acceptor = new NioSocketAcceptor(); // Associate the acceptor to an IoHandler instance (your application) acceptor.setHandler(this); // Bind : this will start the server... acceptor.bind(new InetSocketAddress(PORT)); System.out.println("Server started..."); }
To release For this connection, you can call
acceptor.dispose(true)
// Add a logger filter DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder(); chain.addLast("logger", new LoggingFilter()); // And inject the created chain builder in the service acceptor.setFilterChainBuilder(chain);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

There are two ways to export XML to PDF: using XSLT and using XML data binding libraries. XSLT: Create an XSLT stylesheet, specify the PDF format to convert XML data using the XSLT processor. XML Data binding library: Import XML Data binding library Create PDF Document object loading XML data export PDF files. Which method is better for PDF files depends on the requirements. XSLT provides flexibility, while the data binding library is simple to implement; for simple conversions, the data binding library is better, and for complex conversions, XSLT is more suitable.

Apache errors can be diagnosed and resolved by viewing log files. 1) View the error.log file, 2) Use the grep command to filter errors in specific domain names, 3) Clean the log files regularly and optimize the configuration, 4) Use monitoring tools to monitor and alert in real time. Through these steps, Apache errors can be effectively diagnosed and resolved.

There are the following ways to generate a pom.xml file: Use Maven Archetype to provide predefined project templates to automatically generate pom.xml files for specific types of projects. Use the Maven Helper plugin to provide commands to generate pom.xml files. Create manually to customize the pom.xml file for the project.

To set character encoding on the server side to solve the garbled Bootstrap Table, you need to follow the following steps: check the server character encoding; edit the server configuration file; set the character encoding to UTF-8; save and restart the server; verify the encoding.

There are many reasons why XAMPP fails to start MySQL, including port conflicts, configuration file errors, insufficient system permissions, service dependency issues, and installation issues. The troubleshooting steps are as follows: 1) Check port conflicts; 2) Check configuration files; 3) Check system permissions; 4) Check service dependencies; 5) Reinstall MySQL. Follow these steps and you can find and resolve issues that cause MySQL startup to fail.

This article introduces several methods to check the OpenSSL configuration of the Debian system to help you quickly grasp the security status of the system. 1. Confirm the OpenSSL version First, verify whether OpenSSL has been installed and version information. Enter the following command in the terminal: If opensslversion is not installed, the system will prompt an error. 2. View the configuration file. The main configuration file of OpenSSL is usually located in /etc/ssl/openssl.cnf. You can use a text editor (such as nano) to view: sudonano/etc/ssl/openssl.cnf This file contains important configuration information such as key, certificate path, and encryption algorithm. 3. Utilize OPE

The preview methods of Bootstrap pages are: open the HTML file directly in the browser; automatically refresh the browser using the Live Server plug-in; and build a local server to simulate an online environment.
