You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by mh...@apache.org on 2007/01/31 05:48:45 UTC

svn commit: r501725 - in /mina/sandbox/mheath/aioj/trunk/src/site/xdoc: ./ usage.xml

Author: mheath
Date: Tue Jan 30 20:48:44 2007
New Revision: 501725

URL: http://svn.apache.org/viewvc?view=rev&rev=501725
Log:
Added files for site creation.

Added:
    mina/sandbox/mheath/aioj/trunk/src/site/xdoc/
    mina/sandbox/mheath/aioj/trunk/src/site/xdoc/usage.xml

Added: mina/sandbox/mheath/aioj/trunk/src/site/xdoc/usage.xml
URL: http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/site/xdoc/usage.xml?view=auto&rev=501725
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/src/site/xdoc/usage.xml (added)
+++ mina/sandbox/mheath/aioj/trunk/src/site/xdoc/usage.xml Tue Jan 30 20:48:44 2007
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<document>
+	<properties>
+		<author>Mike Heath</author>
+		<title>Asynchronous File I/O in Java Usage</title>
+	</properties>
+	<body>
+		<section name="Open a file">
+		<p>All file operations are done asynchronously, including file opens.  The following code is an example of how
+		to open a file:</p>
+		<source><![CDATA[
+        File testFile = new File("fileName");
+        AioFuture<AsynchronousFileChannel> future = AsynchronousFileChannelFactory.open(testFile, Modes.READ_ONLY);
+        AsynchronousFileChannel channel = future.get();
+		]]></source>
+		<p>The AsynchronousFileChannel class is very similar to java.nio.FileChannel.  All the operations available to
+		java.nio.FileChannel can be done with AsynchronousFileChannel.  The difference is that all the methods in
+		AsynchronousFileChannel do not block and return an AioFuture handle the represents the pending I/O operation.
+		AioFuture implements java.util.concurrent.Future.  Additionally, AioFuture provides support for regestering
+		callbacks.  A callback is an implementation of the AioCompletionHandler interface.  When the operation
+		represented by an AioFuture completes, all the callbacks registered with the AioFutre are invoked.</p>
+		</section>
+		<section name="Reading data from a file">
+		To read data from a file, use the following example.
+		<source><![CDATA[
+        AioFuture<Integer> readFuture = channel.read(buffer, 0);
+        readFuture.addCompletionHandler(new AioCompletionHandler<Integer>() {
+            public void onCompletion(AioFuture<Integer> future) {
+                ByteBufferFuture byteBufferFuture = (ByteBufferFuture)future;
+                ByteBuffer buffer = byteBufferFuture.getByteBuffer();
+                
+                // Do something with the ByteBuffer
+            }
+        });
+		]]></source>
+		</section>
+	</body>
+</document>
\ No newline at end of file