directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Directory Wiki] Update of "MinaTutorial" by TrustinLee
Date Mon, 09 May 2005 15:24:44 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Directory Wiki" for change notification.

The following page has been changed by TrustinLee:
http://wiki.apache.org/directory/MinaTutorial

The comment on the change is:
Fixed all TODOs

------------------------------------------------------------------------------
  
  That's it, the Reverser protocol is fully implemented now.  Startup code is very similar
to that of echo server:
  
- TODO: startup code here
+ {{{
+ package org.apache.mina.examples.reverser;
+ 
+ import org.apache.mina.common.*;
+ import org.apache.mina.protocol.*;
+ import org.apache.mina.registry.*;
+ 
+ /**
+  * (<b>Entry point</b>) Reverser server which reverses all text lines from
+  * clients.
+  * 
+  * @author Trustin Lee (trustin@apache.org)
+  * @version $Rev: 165594 $, $Date: 2005-05-02 16:21:22 +0900 $,
+  */
+ public class Main
+ {
+     private static final int PORT = 8080;
+ 
+     public static void main( String[] args ) throws Exception
+     {
+         ServiceRegistry registry = new SimpleServiceRegistry();
+ 
+         // Bind
+         Service service = new Service( "reverse", TransportType.SOCKET, PORT );
+         registry.bind( service, new ReverseProtocolProvider() );
+ 
+         System.out.println( "Listening on port " + PORT );
+     }
+ }
+ }}}
  
  === Adding ProtocolFilters ===
  
@@ -288, +317 @@

  
  Adding IoLoggingFilter logs low-level I/O events which are appropriate for debugging purposes.
 We could use ProtocolLoggingFilter instead to log higher-level events:
  
- TODO: Code here
+ {{{
+     private static void addLogger( ServiceRegistry registry )
+     {
+         ProtocolAcceptor acceptor = registry.getProtocolAcceptor( TransportType.SOCKET );
+         acceptor.getFilterChain().addLast( "logger", new ProtocolLoggingFilter() );
+         System.out.println( "Logging ON" );
+     }
+ }}}
  
  == Advanced Topics ==
  
@@ -314, +350 @@

  
  The SimpleServiceRegistry adds IoThreadPoolFilter and ProtocolThreadPoolFilter which is
adequate for applications that require high-scalability by default.  If you want to use your
own threading model, please refer to the SimpleServiceRegistry source code and initialize
Acceptors by yourself.  It is, of course, a trivial task.
  
- TODO: Example code here
+ {{{
+ IoThreadPoolFilter threadPool = new IoThreadPoolFilter();
+ threadPool.start();
+ 
+ IoAcceptor acceptor = new SocketAcceptor();
+ acceptor.getFilterChain().addLast( "threadPool", threadPool );
+ 
+ ProtocolThreadPoolFilter threadPool2 = new ProtocolThreadPoolFilter();
+ threadPool2.start();
+ 
+ ProtocolAcceptor acceptor2 = new IoProtocolAcceptor( acceptor );
+ acceptor2.getFilterChain().addLast( "threadPool", threadPool2 );
+ 
+ ...
+ 
+ threadPool2.stop();
+ threadPool.stop();
+ }}}
+ 
  
  === More Complex Protocols ===
  

Mime
View raw message