Author: elecharny Date: Wed Mar 27 05:53:35 2019 New Revision: 1856370 URL: http://svn.apache.org/viewvc?rev=1856370&view=rev Log: Renamed ch5/6 pages
Added: mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.1-blacklist-filter.mdtext mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.2-buffered-write-filter.mdtext mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.1-apr-transport.mdtext mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.2-serial-transport.mdtext Removed: mina/site/trunk/content/mina-project/userguide/ch6-transports/apr-transport.mdtext mina/site/trunk/content/mina-project/userguide/ch6-transports/serial-transport.mdtext Added: mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.1-blacklist-filter.mdtext URL: http://svn.apache.org/viewvc/mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.1-blacklist-filter.mdtext?rev=1856370&view=auto ============================================================================== --- mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.1-blacklist-filter.mdtext (added) +++ mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.1-blacklist-filter.mdtext Wed Mar 27 05:53:35 2019 @@ -0,0 +1,66 @@ +Title: 5-1 - Blacklist Filter +NavUp: ch5-filters.html +NavUpText: Chapter 5 - Filters +NavPrev: ch5-filters.html +NavPrevText: Chapter 5 - Filters +NavNext: ch5.2-bufferedwritefilter.html +NavNextText: 5.2 - Buffered Write Filter +Notice: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +# 5-1 - Blacklist Filter + +This filter blocks connnections from blacklisted remote addresses. Onee can block addresses or Subnets. In any case, when an event happens on a blocked session, the session will simply be closed. Here are the events this filter handles : + +* event (MINA 2.1) +* messageReceived +* messageSent +* sessionCreated +* sessionIdle +* sessionOpened + +There is no need to handle any other event. + +## Blocking an address + +Any address or subnet can be blocked live, ie it does not matter if a session is already active or not, this dynamicaly activated. +It's enough to add the filter in the chain, and to set (or unset) the addresses to block: + + :::java + ... + BlacklistFilter blackList = new BlacklistFilter(); + blackList.block(InetAddress.getByName("1.2.3.4")); + acceptor.getFilterChain().addLast("blacklist", new BlacklistFilter()); + ... + +Here, the "1.2.3.4" address will be blocked. + +## Unblocking an address + +It's possible to unblock an address, it's just a matter of fetching the filter and remove a previously blocked addres: + + :::java + ... + BlacklistFilter blackList = (BlacklistFilter)session.getFilterChain().get(BlacklistFilter.class); + blackList.unblock(InetAddress.getByName("1.2.3.4")); + ... + +Here, the "1.2.3.4" address will be unblocked. + +## Performances + +Currently, the implementation is not really optimal... We use a List to store the blocked addresses/subnet, so the more of them you have in the list the longer it will take to process any event. Added: mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.2-buffered-write-filter.mdtext URL: http://svn.apache.org/viewvc/mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.2-buffered-write-filter.mdtext?rev=1856370&view=auto ============================================================================== --- mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.2-buffered-write-filter.mdtext (added) +++ mina/site/trunk/content/mina-project/userguide/ch5-filters/ch5.2-buffered-write-filter.mdtext Wed Mar 27 05:53:35 2019 @@ -0,0 +1,27 @@ +Title: 5-2 - Buffered Write Filter +NavUp: ch5-filters.html +NavUpText: Chapter 5 - Filters +NavPrev: ch5.1-blacklist-filter.html +NavPrevText: 5.1 - Blacklist Filter +NavNext: ch6-transports.html +NavNextText: Chapter 6 - Transports +Notice: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +# 5-2 - Buffered Write Filter + +TBD... \ No newline at end of file Added: mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.1-apr-transport.mdtext URL: http://svn.apache.org/viewvc/mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.1-apr-transport.mdtext?rev=1856370&view=auto ============================================================================== --- mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.1-apr-transport.mdtext (added) +++ mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.1-apr-transport.mdtext Wed Mar 27 05:53:35 2019 @@ -0,0 +1,75 @@ +Title: 6.1 - APR Transport +NavUp: ch6-transports.html +NavUpText: Chapter 6 - Transports +NavNext: 6.2 - serial-transport.html +NavNextText: ch6.2-Serial Transport +Notice: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +# 6.1 - APR Transport + +## Introduction + +[APR (Apache Portable Runtime)](https://apr.apache.org/) provide superior scalability, performance, and better integration with native server technologies. APR transport is supported by MINA. In this section, we shall touch base upon how to use APR transport with MINA. We shall the Time Server example for this. + +## Pre-requisite + +<DIV class="info" markdown="1"> + APR transport depends following components<BR> + APR library - Download/install appropriate library for the platform from <A href="https://www.apache.org/dist/tomcat/tomcat-connectors/native/" class="external-link" rel="nofollow">https://www.apache.org/dist/tomcat/tomcat-connectors/native/</A><BR> + JNI wrapper (tomcat-apr-5.5.23.jar) The jar is shipped with release + <P>Put the native library in PATH</P> +</DIV> + +## Using APR Transport + +Refer [Time Server](https://mina.apache.org/mina-project/xref/org/apache/mina/example/gettingstarted/timeserver/) example for complete source + +Lets see how NIO based Time server implementation looks like + + :::java + 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, 10 ); + + acceptor.bind( new InetSocketAddress(PORT) ); + +Lets see how to use APR Transport + + :::java + 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, 10 ); + + acceptor.bind( new InetSocketAddress(PORT) ); + +We just change the NioSocketAcceptor to AprSocketAcceptor. That's it, now our Time Server shall use APR transport. + +Rest complete process remains same. + Added: mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.2-serial-transport.mdtext URL: http://svn.apache.org/viewvc/mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.2-serial-transport.mdtext?rev=1856370&view=auto ============================================================================== --- mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.2-serial-transport.mdtext (added) +++ mina/site/trunk/content/mina-project/userguide/ch6-transports/ch6.2-serial-transport.mdtext Wed Mar 27 05:53:35 2019 @@ -0,0 +1,83 @@ +Title: 6.2 - Serial Transport +NavUp: ch6-transports.html +NavUpText: Chapter 6 - Transports +NavPrev: ch6.1-apr-transport.html +NavPrevText: 6.1 - APR Transport +Notice: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +# 6.2 - Serial Transport + +With the MINA 2.0 you are able to connect to serial port like you use to connect to a TCP/IP port with MINA. + +## Getting MINA 2.0 + +You you can download the latest built version (2.0.2). + +If you prefer to build the code from the trunk, and need assistance to do so, please consult the Developer Guide. + +## Prerequisite + +<DIV class="info" markdown="1"> + <B>Useful Information</B><BR> + Before accessing serial port from a Java program you need a native library (.DLL or .so depending of your OS). MINA use the one from RXTX.org : <A href="ftp://ftp.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip" class="external-link" rel="nofollow">ftp://ftp.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip</A>. <BR> + Just put the good .dll or .so in the jre/lib/i386/ path of your JDK/JRE or use the -Djava.library.path= argument for specify where you placed the native libraries +</DIV> + +<DIV class="info" markdown="1"> + <B>Useful Information</B><BR> + The <B>mina-transport-serial</B> jar is not included in the full distribution. You can download it from <A href="http://repo1.maven.org/maven2/org/apache/mina/mina-transport-serial/2.0.2/" class="external-link" rel="nofollow">here</A> +</DIV> + +## Connecting to a serial port + +Serial communication for MINA provide only an IoConnector, due to the point-to-point nature of the communication media. + +At this point you are supposed to have already read the MINA tutorial. + +Now for connecting to a serial port you need a SerialConnector : + + :::java + // create your connector + IoConnector connector = new SerialConnector() + connector.setHandler( ... here your buisness logic IoHandler ... ); + +Nothing very different of a SocketConnector. + +Let's create an address for connecting to our serial port. + + :::java + SerialAddress portAddress=new SerialAddress( "/dev/ttyS0", 38400, 8, StopBits.BITS_1, Parity.NONE, FlowControl.NONE ); + +The first parameter is your port identifier. For Windows computer, the serial ports are called "COM1", "COM2", etc... For Linux and some other Unix : "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyUSB0". + +The remaining parameters are depending of the device you are driving and the supposed communications characteristics. + +* the baud rate +* the data bits +* the parity +* the flow control mecanism + +Once it's done, connect the connector to the address : + + :::java + ConnectFuture future = connector.connect( portAddress ); + future.await(); + IoSession sessin = future.getSession(); + +And voila ! Everything else is as usual, you can plug your filters and codecs. +for learn more about RS232 : <http://en.wikipedia.org/wiki/RS232>