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.net.SocketAddress;
23
24 /**
25 * Connects to endpoint, communicates with the server, and fires events to
26 * {@link IoHandler}s.
27 * <p>
28 * Please refer to
29 * <a href="../../../../../xref-examples/org/apache/mina/examples/netcat/Main.html">NetCat</a>
30 * example.
31 * <p>
32 * You should connect to the desired socket address to start communication,
33 * and then events for incoming connections will be sent to the specified
34 * default {@link IoHandler}.
35 * <p>
36 * Threads connect to endpoint start automatically when
37 * {@link #connect(SocketAddress, IoHandler)} is invoked, and stop when all
38 * connection attempts are finished.
39 *
40 * @author The Apache Directory Project (mina-dev@directory.apache.org)
41 * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
42 */
43 public interface IoConnector extends IoService {
44 /**
45 * Connects to the specified <code>address</code>. If communication starts
46 * successfully, events are fired to the specified
47 * <code>handler</code>.
48 *
49 * @return {@link ConnectFuture} that will tell the result of the connection attempt
50 */
51 ConnectFuture connect(SocketAddress address, IoHandler handler);
52
53 /**
54 * Connects to the specified <code>address</code>. If communication starts
55 * successfully, events are fired to the specified
56 * <code>handler</code>.
57 *
58 * @param config the configuration
59 * @return {@link ConnectFuture} that will tell the result of the connection attempt
60 */
61 ConnectFuture connect(SocketAddress address, IoHandler handler,
62 IoServiceConfig config);
63
64 /**
65 * Connects to the specified <code>address</code>. If communication starts
66 * successfully, events are fired to the specified
67 * <code>handler</code>.
68 *
69 * @param localAddress the local address the channel is bound to
70 * @return {@link ConnectFuture} that will tell the result of the connection attempt
71 */
72 ConnectFuture connect(SocketAddress address, SocketAddress localAddress,
73 IoHandler handler);
74
75 /**
76 * Connects to the specified <code>address</code>. If communication starts
77 * successfully, events are fired to the specified
78 * <code>handler</code>.
79 *
80 * @param config the configuration
81 * @return {@link ConnectFuture} that will tell the result of the connection attempt
82 */
83 ConnectFuture connect(SocketAddress address, SocketAddress localAddress,
84 IoHandler handler, IoServiceConfig config);
85 }