blob: 7edd2fbbd16db258c5284c4d85dad2cb5b49ec55 [file] [log] [blame]
Title: 6.1 - APR Transport
NavPrev: ch6-transports.html
NavPrevText: Chapter 6 - Transports
NavUp: ch6-transports.html
NavUpText: Chapter 6 - Transports
NavNext: ch6.2-serial-transport.html
NavNextText: 6.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.