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.core.future; 21 22 import org.apache.mina.core.session.IoSession; 23 24 /** 25 * An {@link IoFuture} for asynchronous connect requests. 26 * 27 * <h3>Example</h3> 28 * <pre> 29 * IoConnector connector = ...; 30 * ConnectFuture future = connector.connect(...); 31 * future.join(); // Wait until the connection attempt is finished. 32 * IoSession session = future.getSession(); 33 * session.write(...); 34 * </pre> 35 * 36 * @author The Apache MINA Project (dev@mina.apache.org) 37 * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $ 38 */ 39 public interface ConnectFuture extends IoFuture { 40 /** 41 * Returns {@link IoSession} which is the result of connect operation. 42 * 43 * @return <tt>null</tt> if the connect operation is not finished yet 44 * @throws RuntimeException if connection attempt failed by an exception 45 */ 46 IoSession getSession(); 47 48 /** 49 * Returns the cause of the connection failure. 50 * 51 * @return <tt>null</tt> if the connect operation is not finished yet, 52 * or if the connection attempt is successful. 53 */ 54 Throwable getException(); 55 56 /** 57 * Returns <tt>true</tt> if the connect operation is finished successfully. 58 */ 59 boolean isConnected(); 60 61 /** 62 * Returns {@code true} if the connect operation has been canceled by 63 * {@link #cancel()} method. 64 */ 65 boolean isCanceled(); 66 67 /** 68 * Sets the newly connected session and notifies all threads waiting for 69 * this future. This method is invoked by MINA internally. Please do not 70 * call this method directly. 71 */ 72 void setSession(IoSession session); 73 74 /** 75 * Sets the exception caught due to connection failure and notifies all 76 * threads waiting for this future. This method is invoked by MINA 77 * internally. Please do not call this method directly. 78 */ 79 void setException(Throwable exception); 80 81 /** 82 * Cancels the connection attempt and notifies all threads waiting for 83 * this future. 84 */ 85 void cancel(); 86 87 ConnectFuture await() throws InterruptedException; 88 89 ConnectFuture awaitUninterruptibly(); 90 91 ConnectFuture addListener(IoFutureListener<?> listener); 92 93 ConnectFuture removeListener(IoFutureListener<?> listener); 94 }