directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r448088 - in /directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser: Main.java ReverseProtocolHandler.java
Date Wed, 20 Sep 2006 06:22:43 GMT
Author: trustin
Date: Tue Sep 19 23:22:42 2006
New Revision: 448088

URL: http://svn.apache.org/viewvc?view=rev&rev=448088
Log:
Applied the best practice of adding filters

Modified:
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java?view=diff&rev=448088&r1=448087&r2=448088
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/Main.java
Tue Sep 19 23:22:42 2006
@@ -20,9 +20,14 @@
 package org.apache.mina.example.reverser;
 
 import java.net.InetSocketAddress;
+import java.nio.charset.Charset;
 
 import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 /**
  * (<b>Entry point</b>) Reverser server which reverses all text lines from
@@ -39,10 +44,19 @@
     {
         IoAcceptor acceptor = new SocketAcceptor();
 
+        // Prepare the configuration
+        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
+        cfg.setReuseAddress( true );
+        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
+        cfg.getFilterChain().addLast(
+                "codec",
+                new ProtocolCodecFilter(
+                        new TextLineCodecFactory( Charset.forName( "UTF-8" ) ) ) );
+
         // Bind
         acceptor.bind(
                 new InetSocketAddress( PORT ),
-                new ReverseProtocolHandler() );
+                new ReverseProtocolHandler(), cfg );
 
         System.out.println( "Listening on port " + PORT );
     }

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java?view=diff&rev=448088&r1=448087&r2=448088
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java
Tue Sep 19 23:22:42 2006
@@ -19,13 +19,9 @@
  */
 package org.apache.mina.example.reverser;
 
-import org.apache.mina.common.IoFilter;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.LoggingFilter;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
 
 /**
  * {@link IoHandler} implementation of reverser server protocol.
@@ -35,16 +31,6 @@
  */
 public class ReverseProtocolHandler extends IoHandlerAdapter
 {
-    private static IoFilter LOGGING_FILTER = new LoggingFilter();
-    private static IoFilter CODEC_FILTER =
-        new ProtocolCodecFilter( new TextLineCodecFactory() );
-
-    public void sessionCreated( IoSession session ) throws Exception
-    {
-        session.getFilterChain().addLast( "logger", LOGGING_FILTER );
-        session.getFilterChain().addLast( "codec", CODEC_FILTER );
-    }
-
     public void exceptionCaught( IoSession session, Throwable cause )
     {
         cause.printStackTrace();



Mime
View raw message