KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > common > IoAcceptor


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.common;
21
22 import java.io.IOException JavaDoc;
23 import java.net.SocketAddress JavaDoc;
24
25 /**
26  * Accepts incoming connection, communicates with clients, and fires events to
27  * {@link IoHandler}s.
28  * <p>
29  * Please refer to
30  * <a HREF="../../../../../xref-examples/org/apache/mina/examples/echoserver/Main.html">EchoServer</a>
31  * example.
32  * <p>
33  * You should bind to the desired socket address to accept incoming
34  * connections, and then events for incoming connections will be sent to
35  * the specified default {@link IoHandler}.
36  * <p>
37  * Threads accept incoming connections start automatically when
38  * {@link #bind(SocketAddress, IoHandler)} is invoked, and stop when all
39  * addresses are unbound.
40  *
41  * @author The Apache Directory Project (mina-dev@directory.apache.org)
42  * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $
43  */

44 public interface IoAcceptor extends IoService {
45     /**
46      * Binds to the specified <code>address</code> and handles incoming
47      * connections with the specified <code>handler</code>.
48      *
49      * @throws IOException if failed to bind
50      */

51     void bind(SocketAddress JavaDoc address, IoHandler handler) throws IOException JavaDoc;
52
53     /**
54      * Binds to the specified <code>address</code> and handles incoming
55      * connections with the specified <code>handler</code>.
56      *
57      * @param config the configuration
58      * @throws IOException if failed to bind
59      */

60     void bind(SocketAddress JavaDoc address, IoHandler handler, IoServiceConfig config)
61             throws IOException JavaDoc;
62
63     /**
64      * Unbinds from the specified <code>address</code> and disconnects all clients
65      * connected there.
66      */

67     void unbind(SocketAddress JavaDoc address);
68
69     /**
70      * Unbinds all addresses which were bound by this acceptor.
71      */

72     void unbindAll();
73
74     /**
75      * (Optional) Returns an {@link IoSession} that is bound to the specified
76      * <tt>localAddress</tt> and <tt>remoteAddress</tt> which reuses
77      * the <tt>localAddress</tt> that is already bound by {@link IoAcceptor}
78      * via {@link #bind(SocketAddress, IoHandler)}.
79      * <p>
80      * This operation is optional. Please throw {@link UnsupportedOperationException}
81      * if the transport type doesn't support this operation. This operation is
82      * usually implemented for connectionless transport types.
83      *
84      * @throws UnsupportedOperationException if this operation is not supported
85      * @throws IllegalArgumentException if the specified <tt>localAddress</tt> is
86      * not bound yet. (see {@link #bind(SocketAddress, IoHandler)})
87      */

88     IoSession newSession(SocketAddress JavaDoc remoteAddress, SocketAddress JavaDoc localAddress);
89 }
Popular Tags