Mina APR transmission and serial transmission explanation

Source: Internet
Author: User

Original address: Mina transports (Apache Mina User Guide Chapter6 Transport)

1.1.1. Apr transmission 1.1.1.1. Introduction

APR (Apache portable Runtime) Apache Portable Run-time library provide Zhuo the more scalability, performance, and can be Better to with local server technology integration. Mina supports APR transmissions. In this section, I will not use APR transmission on the basis of Mina. We will use The example of time Server.

1.1.1.2. Prerequisites

Apr Transport relies on the following components:

    • APR Package- Download/install the appropriate platform jar package from http://www.apache.org/dist/tomcat/tomcat-connectors/native/.
    • JNI Wrapper (Tomcat-apr-5.5.23.jar) the release version comes with this package.  

Add the local package to the path path.

1.1.1.3. using Apr transmission

Refer to the time Server complete sample program. Let's see what the time Server implementation based on NiO is like :

Ioacceptor acceptor = new Niosocketacceptor (); Acceptor.getfilterchain (). AddLast ("Logger", New Loggingfilter ()); Acceptor.getfilterchain (). AddLast ("Codec", new Protocolcodecfilter (New Textlinecodecfactory (Charset.forname (" UTF-8 "))); Acceptor.sethandler (  New Timeserverhandler ()); Acceptor.getsessionconfig (). Setreadbuffersize (2048 ); Acceptor.getsessionconfig (). Setidletime (Idlestatus.both_idle); Acceptor.bind (new Inetsocketaddress (PORT));

Let's see how to use APR transmission:

Ioacceptor acceptor = new Aprsocketacceptor (); Acceptor.getfilterchain (). AddLast ("Logger", New Loggingfilter ()); Acceptor.getfilterchain (). AddLast ("Codec", new Protocolcodecfilter (New Textlinecodecfactory (Charset.forname (" UTF-8 "))); Acceptor.sethandler (  New Timeserverhandler ()); Acceptor.getsessionconfig (). Setreadbuffersize (2048 ); Acceptor.getsessionconfig (). Setidletime (Idlestatus.both_idle); Acceptor.bind (new Inetsocketaddress (PORT));

We just turned the niosocketacceptor into aprsocketacceptor . that 's it, now our time Server will be using Apr transfer.

The rest of the complete process is still the same.

1.1.2. Serial Transmission

by Mina 2.0 You can connect to the serial port by using connect to Mina TCP/IP port.

1.1.2.1. Understanding Mina2.0

You can download the latest build version ( currently the latest is 2.0.13). If you like Building Code from a warehouse, consult the Developer's Guide if you need help .

1.1.2.2. Prerequisites

Useful information:

in the accessing the serial port before the Java program needs a local program Library (used by your operating system . ) dll or . So file ). Mina using the rxtx.org from Ftp://ftp.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip Package.

Just need to put you in good condition. DLL or. So file into the jre/lib/i386/path inside your jdk/jre, or use-djava.library.path= to define your local package path.

Useful information:

mina-transport-serial . jar is not included in the full Distribution Bundles . You can download it from here .

1.1.2.3. Connecting a serial port

serial communication mina provide only one ioconnector , because itself is point-to-point communication media. At this time You should have read the mina tutorial. Now connected to the serial port you requires Serialconnector:

Create your Connectorioconnector connector = new Serialconnector () Connector.sethandler (... here your buisness logic Io Handler ...);

No What with Socketconnector Distinct , Let's create an address to connect to the serial port :

Serialaddress portaddress=new serialaddress ("/dev/ttys0", 38400, 8, Stopbits.bits_1, Parity.none, FlowControl.NONE);

The first parameter is your Port ID. the serial port of Windows computer is called "COM1", "COM2" and so on ... Linux and some other Unix are called : "/DEV/TTYS0", "/dev/ttys1", "/dev/ttyusb0".

The remaining parameters are based on the device's Drive and the so-called communication features.

    • · The baud rate
    • · The data bits
    • · The parity
    • · The flow control mecanism

Once done, connect the connector to the address:

Connectfuture future = Connector.connect (portaddress); future.await (); Iosession sessin = Future.getsession ();

Look at it! The others are as usual, you can insert filters and codecs . To learn more about RS232, see:http://en.wikipedia.org/wiki/RS232


Mina APR transmission and serial transmission explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.