KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > example > reverser > Main


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.mina.example.reverser;
21
22 import java.net.InetSocketAddress JavaDoc;
23 import java.nio.charset.Charset JavaDoc;
24
25 import org.apache.mina.common.IoAcceptor;
26 import org.apache.mina.filter.LoggingFilter;
27 import org.apache.mina.filter.codec.ProtocolCodecFilter;
28 import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
29 import org.apache.mina.transport.socket.nio.SocketAcceptor;
30 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
31
32 /**
33  * (<b>Entry point</b>) Reverser server which reverses all text lines from
34  * clients.
35  *
36  * @author The Apache Directory Project (mina-dev@directory.apache.org)
37  * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $,
38  */

39 public class Main {
40     private static final int PORT = 8080;
41
42     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
43         IoAcceptor acceptor = new SocketAcceptor();
44
45         // Prepare the configuration
46
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
47         cfg.setReuseAddress(true);
48         cfg.getFilterChain().addLast("logger", new LoggingFilter());
49         cfg.getFilterChain().addLast(
50                 "codec",
51                 new ProtocolCodecFilter(new TextLineCodecFactory(Charset
52                         .forName("UTF-8"))));
53
54         // Bind
55
acceptor.bind(new InetSocketAddress JavaDoc(PORT),
56                 new ReverseProtocolHandler(), cfg);
57
58         System.out.println("Listening on port " + PORT);
59     }
60 }
61
Popular Tags