Parent Directory
|
Revision Log
|
Patch
--- directory/network/trunk/src/java/org/apache/mina/common/IoFuture.java 2005/11/13 22:27:55 343989
+++ directory/network/trunk/src/java/org/apache/mina/common/IoFuture.java 2005/11/13 22:29:44 343990
@@ -28,15 +28,32 @@
public class IoFuture
{
private Object result;
+ private Callback callback;
private boolean ready;
/**
+ * Something interested in being notified when the result
+ * of an {@link IoFuture} becomes available.
+ */
+ public interface Callback
+ {
+ /**
+ * Invoked when the operation associated with the {@link IoFuture}
+ * has been completed.
+ *
+ * @param future The source {@link IoFuture} which called this
+ * callback.
+ */
+ public void operationComplete( IoFuture future );
+ }
+
+ /**
* Creates a new instance.
*/
protected IoFuture()
{
}
-
+
/**
* Wait for the asynchronous operation to end.
*/
@@ -112,6 +129,11 @@
result = newValue;
ready = true;
notifyAll();
+
+ if( callback != null )
+ {
+ invokeCallback();
+ }
}
/**
@@ -121,4 +143,36 @@
{
return result;
}
+
+ /**
+ * Returns a {@link Callback} which is associated with this future.
+ */
+ public synchronized Callback getCallback()
+ {
+ return callback;
+ }
+
+ /**
+ * Sets a {@link Callback} to be notified when a result
+ * becomes available. If tth result has already become obtained,
+ * the specified callback is notified immediately
+ */
+ public synchronized void setCallback( Callback callback )
+ {
+ if( callback == null )
+ {
+ throw new NullPointerException( "callback" );
+ }
+
+ this.callback = callback;
+ if( ready )
+ {
+ invokeCallback();
+ }
+ }
+
+ private void invokeCallback()
+ {
+ callback.operationComplete( this );
+ }
}
| apache@apache.org | ViewVC Help |
| Powered by ViewVC 1.1.2 |