Author: mheath
Date: Wed Jan 31 22:31:16 2007
New Revision: 502134

URL: http://svn.apache.org/viewvc?view=rev&rev=502134
Log:
Added stubs for JNI code.

Added:
    
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannel.java
    
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannel.java
    mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/
    
mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/TestPosixFileChannel.java
Modified:
    mina/sandbox/mheath/aioj/trunk/   (props changed)
    mina/sandbox/mheath/aioj/trunk/pom.xml
    mina/sandbox/mheath/aioj/trunk/src/main/c/Makefile
    mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp
    
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/concurrent/ConcurrentAsynchronousFileChannelProvider.java
    
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannelProvider.java
    
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannelProvider.java

Propchange: mina/sandbox/mheath/aioj/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Jan 31 22:31:16 2007
@@ -7,3 +7,5 @@
 target
 
 .clover
+
+null

Modified: mina/sandbox/mheath/aioj/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/pom.xml?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/pom.xml (original)
+++ mina/sandbox/mheath/aioj/trunk/pom.xml Wed Jan 31 22:31:16 2007
@@ -6,7 +6,7 @@
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.apache.aio</groupId>
        <artifactId>aio</artifactId>
-       <version>0.1</version>
+       <version>0.2-SNAPSHOT</version>
        <name>Asynchronous File I/O in Java</name>
        <description>
                Provides asynchronous file operations for Java applications.  
The current implementation calls methods in a

Modified: mina/sandbox/mheath/aioj/trunk/src/main/c/Makefile
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/c/Makefile?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/src/main/c/Makefile (original)
+++ mina/sandbox/mheath/aioj/trunk/src/main/c/Makefile Wed Jan 31 22:31:16 2007
@@ -25,9 +25,17 @@
 
 all: $(TARGET)
 
-$(TARGET): org_apache_aio.cpp $(WORKING_DIR)/org_apache_aio_test_Test.h
+$(TARGET): org_apache_aio.cpp $(WORKING_DIR)/org_apache_aio_test_Test.h 
$(WORKING_DIR)/org_apache_aio_posix_PosixAsynchronousFileChannel.h 
$(WORKING_DIR)/org_apache_aio_linux_LinuxAsynchronousFileChannel.h
        g++ -shared -lrt -lstdc++ $(INCLUDES) org_apache_aio.cpp -o $(TARGET)
 
 $(WORKING_DIR)/org_apache_aio_test_Test.h: 
$(TARGET_DIR)/classes/org/apache/aio/test/Test.class
        mkdir -p $(TARGET_DIR)/jni
        javah -force -classpath $(JAVAH_CLASSPATH) -d $(WORKING_DIR) 
org.apache.aio.test.Test
+
+$(WORKING_DIR)/org_apache_aio_posix_PosixAsynchronousFileChannel.h: 
$(TARGET_DIR)/classes/org/apache/aio/posix/PosixAsynchronousFileChannel.class
+       mkdir -p $(TARGET_DIR)/jni
+       javah -force -classpath $(JAVAH_CLASSPATH) -d $(WORKING_DIR) 
org.apache.aio.posix.PosixAsynchronousFileChannel
+
+$(WORKING_DIR)/org_apache_aio_linux_LinuxAsynchronousFileChannel.h: 
$(TARGET_DIR)/classes/org/apache/aio/linux/LinuxAsynchronousFileChannel.class
+       mkdir -p $(TARGET_DIR)/jni
+       javah -force -classpath $(JAVAH_CLASSPATH) -d $(WORKING_DIR) 
org.apache.aio.linux.LinuxAsynchronousFileChannel

Modified: mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp (original)
+++ mina/sandbox/mheath/aioj/trunk/src/main/c/org_apache_aio.cpp Wed Jan 31 
22:31:16 2007
@@ -5,6 +5,8 @@
 #include <string.h>
 
 #include "org_apache_aio_test_Test.h"
+#include "org_apache_aio_posix_PosixAsynchronousFileChannel.h"
+#include "org_apache_aio_linux_LinuxAsynchronousFileChannel.h"
 
 #define DEBUG
 
@@ -22,6 +24,7 @@
 static JavaVM *jvm;
 
 // --- Exception classes ---
+static jclass aioException;
 static jclass ioException;
 static jclass nullPointerException;
 
@@ -29,10 +32,14 @@
 {
        JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved);
        JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved);
-       void aio_read_write_completion_handler(sigval_t sigval);
 }
 
-// --- OnLoad and OnUnload Functions ----------------------------------------
+/**********************************************************************************************************************
+ * 
+ * JNI OnLoad and OnUnload functions
+ * 
+ 
*********************************************************************************************************************/
+
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
 {
 #ifdef DEBUG
@@ -49,6 +56,10 @@
        }
        
        jclass cls;
+       
+       cls = env->FindClass("org/apache/aio/AioException");
+       aioException = (jclass)env->NewWeakGlobalRef(cls);
+
        cls = env->FindClass("java/io/IOException");
        ioException = (jclass)env->NewWeakGlobalRef(cls);
        
@@ -65,8 +76,121 @@
                return;
        }
        
+       env->DeleteWeakGlobalRef(aioException);
        env->DeleteWeakGlobalRef(ioException);
        env->DeleteWeakGlobalRef(nullPointerException);
+}
+
+/**********************************************************************************************************************
+ * 
+ * org.apache.aio.posix.PosixAsynchronousFileChannel methods
+ * 
+ 
*********************************************************************************************************************/
+
+/*
+ * Class:     org_apache_aio_posix_PosixAsynchronousFileChannel
+ * Method:    read
+ * Signature: 
(Ljava/nio/ByteBuffer;J)Lorg/apache/aio/AioFuture/ByteBufferFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_posix_PosixAsynchronousFileChannel_read__Ljava_nio_ByteBuffer_2J
+  (JNIEnv *env, jobject self, jobject buffer, jlong position)
+{
+       LOG_DEBUG("In read function");
+}
+
+/*
+ * Class:     org_apache_aio_posix_PosixAsynchronousFileChannel
+ * Method:    read
+ * Signature: 
([Lorg/apache/aio/ByteBufferPosition;II)Lorg/apache/aio/AioFuture/BatchFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_posix_PosixAsynchronousFileChannel_read___3Lorg_apache_aio_ByteBufferPosition_2II
+  (JNIEnv *env, jobject self, jobjectArray byteBufferPositions, jint offset, 
jint length)
+{
+       LOG_DEBUG("In batch read function");
+}
+
+/*
+ * Class:     org_apache_aio_posix_PosixAsynchronousFileChannel
+ * Method:    sync
+ * Signature: (Z)Lorg/apache/aio/AioFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_posix_PosixAsynchronousFileChannel_sync
+  (JNIEnv *env, jobject self, jboolean metaData)
+{
+       LOG_DEBUG("In sync function");
+}
+
+/*
+ * Class:     org_apache_aio_posix_PosixAsynchronousFileChannel
+ * Method:    write
+ * Signature: 
(Ljava/nio/ByteBuffer;J)Lorg/apache/aio/AioFuture/ByteBufferFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_posix_PosixAsynchronousFileChannel_write__Ljava_nio_ByteBuffer_2J
+  (JNIEnv *env, jobject self, jobject buffer, jlong position)
+{
+       LOG_DEBUG("In write function");
+}
+
+/*
+ * Class:     org_apache_aio_posix_PosixAsynchronousFileChannel
+ * Method:    write
+ * Signature: 
([Lorg/apache/aio/ByteBufferPosition;II)Lorg/apache/aio/AioFuture/BatchFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_posix_PosixAsynchronousFileChannel_write___3Lorg_apache_aio_ByteBufferPosition_2II
+  (JNIEnv *env, jobject self, jobjectArray byteBufferPositions, jint offset, 
jint position)
+{
+       LOG_DEBUG("In batch write function");
+       
+}
+
+/**********************************************************************************************************************
+ * 
+ * org.apache.aio.linux.LinuxAsynchronousFileChannel methods
+ * 
+ 
*********************************************************************************************************************/
+
+/*
+ * Class:     org_apache_aio_linux_LinuxAsynchronousFileChannel
+ * Method:    read
+ * Signature: 
(Ljava/nio/ByteBuffer;J)Lorg/apache/aio/AioFuture/ByteBufferFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_linux_LinuxAsynchronousFileChannel_read__Ljava_nio_ByteBuffer_2J
+  (JNIEnv *env, jobject self, jobject buffer, jlong position)
+{
+       env->ThrowNew(aioException, "Not yet implemented");
+}
+
+/*
+ * Class:     org_apache_aio_linux_LinuxAsynchronousFileChannel
+ * Method:    read
+ * Signature: 
([Lorg/apache/aio/ByteBufferPosition;II)Lorg/apache/aio/AioFuture/BatchFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_linux_LinuxAsynchronousFileChannel_read___3Lorg_apache_aio_ByteBufferPosition_2II
+  (JNIEnv *env, jobject self, jobjectArray byteBufferPositions, jint offset, 
jint length)
+{
+       env->ThrowNew(aioException, "Not yet implemented");
+}
+
+/*
+ * Class:     org_apache_aio_linux_LinuxAsynchronousFileChannel
+ * Method:    write
+ * Signature: 
(Ljava/nio/ByteBuffer;J)Lorg/apache/aio/AioFuture/ByteBufferFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_linux_LinuxAsynchronousFileChannel_write__Ljava_nio_ByteBuffer_2J
+  (JNIEnv *env, jobject self, jobject buffer, jlong position)
+{
+       env->ThrowNew(aioException, "Not yet implemented");
+}
+
+/*
+ * Class:     org_apache_aio_linux_LinuxAsynchronousFileChannel
+ * Method:    write
+ * Signature: 
([Lorg/apache/aio/ByteBufferPosition;II)Lorg/apache/aio/AioFuture/BatchFuture;
+ */
+JNIEXPORT jobject JNICALL 
Java_org_apache_aio_linux_LinuxAsynchronousFileChannel_write___3Lorg_apache_aio_ByteBufferPosition_2II
+  (JNIEnv *env, jobject self, jobjectArray byteBufferPositions, jint offset, 
jint length)
+{
+       env->ThrowNew(aioException, "Not yet implemented");
 }
 
 
/**********************************************************************************************************************

Modified: 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/concurrent/ConcurrentAsynchronousFileChannelProvider.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/concurrent/ConcurrentAsynchronousFileChannelProvider.java?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/concurrent/ConcurrentAsynchronousFileChannelProvider.java
 (original)
+++ 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/concurrent/ConcurrentAsynchronousFileChannelProvider.java
 Wed Jan 31 22:31:16 2007
@@ -62,7 +62,7 @@
         Future<AsynchronousFileChannel> future = service.submit(new 
Callable<AsynchronousFileChannel>() {
             public AsynchronousFileChannel call() throws Exception {
                 final FileChannel channel = new RandomAccessFile(file, 
mode.getModeString()).getChannel();
-                AsynchronousFileChannel afc = new 
ConcurrentAsynchronousFileChannel(channel, mode, service);
+                AsynchronousFileChannel afc = 
createAsynchronouseFileChannel(channel, mode, service);
                 
                 // Call completion handlers
                 service.submit(new Runnable() {
@@ -73,10 +73,15 @@
                 
                 return afc;
             }
+
         });
         aioFuture.setFuture(future);
         
         return aioFuture;
+    }
+
+    protected AsynchronousFileChannel createAsynchronouseFileChannel(final 
FileChannel channel, final Modes mode, final ExecutorService service) {
+        return new ConcurrentAsynchronousFileChannel(channel, mode, service);
     }
 
     private static synchronized ExecutorService getExecutorService() {

Added: 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannel.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannel.java?view=auto&rev=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannel.java
 (added)
+++ 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannel.java
 Wed Jan 31 22:31:16 2007
@@ -0,0 +1,32 @@
+package org.apache.aio.linux;
+
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.concurrent.ExecutorService;
+
+import org.apache.aio.AioException;
+import org.apache.aio.ByteBufferPosition;
+import org.apache.aio.Modes;
+import org.apache.aio.AioFuture.BatchFuture;
+import org.apache.aio.AioFuture.ByteBufferFuture;
+import org.apache.aio.concurrent.ConcurrentAsynchronousFileChannel;
+
+public class LinuxAsynchronousFileChannel extends 
ConcurrentAsynchronousFileChannel {
+
+    public LinuxAsynchronousFileChannel(FileChannel channel, Modes mode, 
ExecutorService executorService) {
+        super(channel, mode, executorService);
+    }
+
+    @Override
+    public native ByteBufferFuture read(ByteBuffer buffer, long position) 
throws AioException;
+    
+    @Override
+    public native BatchFuture read(ByteBufferPosition[] byteBufferPositions, 
int offset, int length) throws AioException;
+    
+    @Override
+    public native ByteBufferFuture write(ByteBuffer buffer, long position);
+    
+    @Override
+    public native BatchFuture write(ByteBufferPosition[] byteBufferPositions, 
int offset, int length);
+    
+}

Modified: 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannelProvider.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannelProvider.java?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannelProvider.java
 (original)
+++ 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/linux/LinuxAsynchronousFileChannelProvider.java
 Wed Jan 31 22:31:16 2007
@@ -19,14 +19,12 @@
  */
 package org.apache.aio.linux;
 
-import java.io.File;
-import java.util.Properties;
+import java.nio.channels.FileChannel;
 import java.util.concurrent.ExecutorService;
 
-import org.apache.aio.AioFuture;
 import org.apache.aio.AsynchronousFileChannel;
-import org.apache.aio.AsynchronousFileChannelProvider;
 import org.apache.aio.Modes;
+import org.apache.aio.concurrent.ConcurrentAsynchronousFileChannelProvider;
 
 /**
  * Creates an AsynchronousFileChannel that uses the Linux io_submit(2) system 
call.  This method should be faster than
@@ -34,9 +32,9 @@
  * 
  * @author mheath
  */
-public class LinuxAsynchronousFileChannelProvider implements 
AsynchronousFileChannelProvider {
-
-    public AioFuture<AsynchronousFileChannel> open(File fileName, Modes mode, 
ExecutorService executorService, Properties properties) {
-        return null;
+public class LinuxAsynchronousFileChannelProvider extends 
ConcurrentAsynchronousFileChannelProvider {
+    @Override
+    protected AsynchronousFileChannel 
createAsynchronouseFileChannel(FileChannel channel, Modes mode, ExecutorService 
service) {
+        return new LinuxAsynchronousFileChannel(channel, mode, service);
     }
 }

Added: 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannel.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannel.java?view=auto&rev=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannel.java
 (added)
+++ 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannel.java
 Wed Jan 31 22:31:16 2007
@@ -0,0 +1,36 @@
+package org.apache.aio.posix;
+
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.concurrent.ExecutorService;
+
+import org.apache.aio.AioException;
+import org.apache.aio.AioFuture;
+import org.apache.aio.ByteBufferPosition;
+import org.apache.aio.Modes;
+import org.apache.aio.AioFuture.BatchFuture;
+import org.apache.aio.AioFuture.ByteBufferFuture;
+import org.apache.aio.concurrent.ConcurrentAsynchronousFileChannel;
+
+public class PosixAsynchronousFileChannel extends 
ConcurrentAsynchronousFileChannel {
+
+    public PosixAsynchronousFileChannel(FileChannel channel, Modes mode, 
ExecutorService executorService) {
+        super(channel, mode, executorService);
+    }
+
+    @Override
+    public native ByteBufferFuture read(ByteBuffer buffer, long position) 
throws AioException;
+
+    @Override
+    public native BatchFuture read(ByteBufferPosition[] byteBufferPositions, 
int offset, int length) throws AioException;
+    
+    @Override
+    public native AioFuture<Void> sync(boolean metaData) throws AioException;
+    
+    @Override
+    public native ByteBufferFuture write(ByteBuffer buffer, long position);
+    
+    @Override
+    public native BatchFuture write(ByteBufferPosition[] byteBufferPositions, 
int offset, int length);
+    
+}

Modified: 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannelProvider.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannelProvider.java?view=diff&rev=502134&r1=502133&r2=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannelProvider.java
 (original)
+++ 
mina/sandbox/mheath/aioj/trunk/src/main/java/org/apache/aio/posix/PosixAsynchronousFileChannelProvider.java
 Wed Jan 31 22:31:16 2007
@@ -19,20 +19,18 @@
  */
 package org.apache.aio.posix;
 
-import java.io.File;
-import java.util.Properties;
+import java.nio.channels.FileChannel;
 import java.util.concurrent.ExecutorService;
 
-import org.apache.aio.AioFuture;
 import org.apache.aio.AsynchronousFileChannel;
-import org.apache.aio.AsynchronousFileChannelProvider;
 import org.apache.aio.Modes;
+import org.apache.aio.concurrent.ConcurrentAsynchronousFileChannelProvider;
 
-public class PosixAsynchronousFileChannelProvider implements 
AsynchronousFileChannelProvider {
+public class PosixAsynchronousFileChannelProvider extends 
ConcurrentAsynchronousFileChannelProvider {
 
-    public AioFuture<AsynchronousFileChannel> open(File fileName, Modes mode, 
ExecutorService executorService, Properties properties) {
-        // TODO Auto-generated method stub
-        return null;
+    @Override
+    protected AsynchronousFileChannel 
createAsynchronouseFileChannel(FileChannel channel, Modes mode, ExecutorService 
service) {
+        return new PosixAsynchronousFileChannel(channel, mode, service);
     }
 
 }

Added: 
mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/TestPosixFileChannel.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/TestPosixFileChannel.java?view=auto&rev=502134
==============================================================================
--- 
mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/TestPosixFileChannel.java
 (added)
+++ 
mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/posix/TestPosixFileChannel.java
 Wed Jan 31 22:31:16 2007
@@ -0,0 +1,20 @@
+package org.apache.aio.posix;
+
+import org.apache.aio.linux.LinuxAsynchronousFileChannel;
+
+public class TestPosixFileChannel {
+
+    static {
+        System.loadLibrary("aioj");
+    }
+    
+    public static void main(String[] args) {
+        PosixAsynchronousFileChannel channel = new 
PosixAsynchronousFileChannel(null, null, null);
+        channel.read(null, 0L);
+        
+        LinuxAsynchronousFileChannel linuxChannel = new 
LinuxAsynchronousFileChannel(null, null, null);
+        linuxChannel.read(null, 0L);
+        
+    }
+
+}


Reply via email to