1 19 package org.apache.mina.example.haiku; 20 21 import java.net.InetSocketAddress ; 22 import java.nio.charset.Charset ; 23 import java.util.concurrent.ExecutorService ; 24 import java.util.concurrent.Executors ; 25 26 import org.apache.mina.filter.codec.ProtocolCodecFilter; 27 import org.apache.mina.filter.codec.textline.TextLineCodecFactory; 28 import org.apache.mina.filter.executor.ExecutorFilter; 29 import org.apache.mina.transport.socket.nio.SocketAcceptor; 30 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; 31 32 36 37 public class HaikuValidationServer { 38 public static void main(String ... args) throws Exception { 39 ExecutorService executor = Executors.newCachedThreadPool(); 40 SocketAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime() 41 .availableProcessors(), executor); 42 43 SocketAcceptorConfig config = new SocketAcceptorConfig(); 44 45 config.getFilterChain().addLast("executor", 46 new ExecutorFilter(executor)); 47 config.getFilterChain().addLast( 48 "to-string", 49 new ProtocolCodecFilter(new TextLineCodecFactory(Charset 50 .forName("US-ASCII")))); 51 config.getFilterChain().addLast("to-haiki", new ToHaikuIoFilter()); 52 53 acceptor.bind(new InetSocketAddress (42458), 54 new HaikuValidatorIoHandler(), config); 55 } 56 } 57 | Popular Tags |