package org.jboss.netty.channel; import java.util.EventListener; /** * Listens to the result of a {@link ChannelFuture}. The result of the * asynchronous {@link Channel} I/O operation is notified once this listener * is added by calling {@link ChannelFuture#addListener(ChannelFutureListener)}. * * <h3>Return the control to the caller quickly</h3> * * {@link #operationComplete(ChannelFuture)} is directly called by an I/O * thread. Therefore, performing a time consuming task or a blocking operation * in the handler method can cause an unexpected pause during I/O. If you need * to perform a blocking operation on I/O completion, try to execute the * operation in a different thread using a thread pool. */ public interface ChannelFutureListener extends EventListener { /** * A {@link ChannelFutureListener} that closes the {@link Channel} which is * associated with the specified {@link ChannelFuture}. */ ChannelFutureListener CLOSE = new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { future.getChannel().close(); } }; /** * A {@link ChannelFutureListener} that closes the {@link Channel} when the * operation ended up with a failure or cancellation rather than a success. */ ChannelFutureListener CLOSE_ON_FAILURE = new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (!future.isSuccess()) { future.getChannel().close(); } } }; /** * Invoked when the I/O operation associated with the {@link ChannelFuture} * has been completed. * * @param future the source {@link ChannelFuture} which called this * callback */ void operationComplete(ChannelFuture future) throws Exception; }