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 /** 23 * An {@link IoFuture} for {@link IoSession#read() asynchronous read requests}. 24 * 25 * <h3>Example</h3> 26 * <pre> 27 * IoSession session = ...; 28 * // useReadOperation must be enabled to use read operation. 29 * session.getConfig().setUseReadOperation(true); 30 * 31 * ReadFuture future = session.read(); 32 * // Wait until a message is received. 33 * future.await(); 34 * try { 35 * Object message = future.getMessage(); 36 * } catch (Exception e) { 37 * ... 38 * } 39 * </pre> 40 * 41 * @author The Apache MINA Project (dev@mina.apache.org) 42 * @version $Rev: 594477 $, $Date: 2007-11-13 03:42:03 -0700 (Tue, 13 Nov 2007) $ 43 */ 44 public interface ReadFuture extends IoFuture { 45 46 /** 47 * Returns the received message. It returns <tt>null</tt> if this 48 * future is not ready or the associated {@link IoSession} has been closed. 49 * 50 * @throws RuntimeException if read or any relevant operation has failed. 51 */ 52 Object getMessage(); 53 54 /** 55 * Returns <tt>true</tt> if a message was received successfully. 56 */ 57 boolean isRead(); 58 59 /** 60 * Returns <tt>true</tt> if the {@link IoSession} associated with this 61 * future has been closed. 62 */ 63 boolean isClosed(); 64 65 /** 66 * Returns the cause of the read failure if and only if the read 67 * operation has failed due to an {@link Exception}. Otherwise, 68 * <tt>null</tt> is returned. 69 */ 70 Throwable getException(); 71 72 /** 73 * Sets the message is written, and notifies all threads waiting for 74 * this future. This method is invoked by MINA internally. Please do 75 * not call this method directly. 76 */ 77 void setRead(Object message); 78 79 /** 80 * Sets the associated {@link IoSession} is closed. This method is invoked 81 * by MINA internally. Please do not call this method directly. 82 */ 83 void setClosed(); 84 85 /** 86 * Sets the cause of the read failure, and notifies all threads waiting 87 * for this future. This method is invoked by MINA internally. Please 88 * do not call this method directly. 89 */ 90 void setException(Throwable cause); 91 92 ReadFuture await() throws InterruptedException; 93 94 ReadFuture awaitUninterruptibly(); 95 96 ReadFuture addListener(IoFutureListener<?> listener); 97 98 ReadFuture removeListener(IoFutureListener<?> listener); 99 }