activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r881737 - in /activemq/sandbox/activemq-apollo/activemq-syscall/src: main/java/org/apache/activemq/syscall/ main/java/org/apache/activemq/syscall/jni/ main/native-package/src/ test/java/org/apache/activemq/syscall/ test/java/org/apache/acti...
Date Wed, 18 Nov 2009 12:01:15 GMT
Author: chirino
Date: Wed Nov 18 12:01:14 2009
New Revision: 881737

URL: http://svn.apache.org/viewvc?rev=881737&view=rev
Log:
- reorganized packages syscall will now hold a high level (easier to use) java API to the
system calls exposed in the syscall.jni package.
- added pointer addition fuctions

Added:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/AIO.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/IO.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/Posix.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html
  (with props)
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html
  (with props)
    activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/
    activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/AIOTest.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/CLibraryTest.java
Removed:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/AIO.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/CLibrary.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/IO.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/Posix.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/AIOTest.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/CLibraryTest.java
Modified:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.syscall;
+
+import org.apache.activemq.syscall.jni.CLibrary;
+
+import static org.apache.activemq.syscall.jni.CLibrary.*;
+
+/**
+ * Wraps up a a native memory allocation in a a Java object
+ * so that it can get garbage collected collected and so we can 
+ * keep track of how big the allocation is.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public final class NativeAllocation {
+	
+    private long pointer;
+    private long length;
+
+    public NativeAllocation(long pointer, long length) {
+        if( pointer==NULL ) {
+            throw new OutOfMemoryError("jni failed to heap allocate: "+length);
+        }
+        this.pointer = pointer;
+        this.length = length;
+    }
+    
+    static public NativeAllocation allocate(String value) {
+        return allocate(value.getBytes());
+    }
+
+    private static NativeAllocation allocate(byte[] value) {
+        int size = value.length;
+        NativeAllocation rc = allocate(size);
+        memmove(rc.pointer(), value, size);
+        return rc;
+    }
+    
+    static public NativeAllocation allocate(long size) {
+        return new NativeAllocation(calloc(size,1), size);
+    }        
+    
+    synchronized public void free() {
+        if( pointer!=NULL ) {
+            CLibrary.free(pointer);
+            pointer = 0;
+        }
+    }
+    
+    @Override
+    protected void finalize() throws Throwable {
+        free();
+    }
+
+    public long pointer() {
+        return pointer;
+    }
+    
+    public long offset(long offset) {
+        return void_pointer_add(pointer, offset);
+    }
+
+    public long length() {
+        return length;
+    }
+
+}
\ No newline at end of file

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/AIO.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/AIO.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/AIO.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/AIO.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,183 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.syscall.jni;
+
+import org.fusesource.hawtjni.runtime.ClassFlag;
+import org.fusesource.hawtjni.runtime.FieldFlag;
+import org.fusesource.hawtjni.runtime.JniArg;
+import org.fusesource.hawtjni.runtime.JniClass;
+import org.fusesource.hawtjni.runtime.JniField;
+import org.fusesource.hawtjni.runtime.JniMethod;
+
+import static org.fusesource.hawtjni.runtime.ArgFlag.*;
+
+import static org.fusesource.hawtjni.runtime.MethodFlag.*;
+
+/**
+ * The aio facility provides system calls for asynchronous I/O
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@JniClass
+public class AIO {
+    static {
+        CLibrary.LIBRARY.load();
+        init();
+    }
+    
+    @JniMethod(flags={CONSTANT_INITIALIZER})
+    private static final native void init();
+    
+    @JniField(flags={FieldFlag.CONSTANT}, conditional="#ifdef HAVE_AIO_H", accessor="1")
+    public static boolean SUPPORTED;
+    
+    @JniField(flags={FieldFlag.CONSTANT}, conditional="#ifdef HAVE_AIO_H")
+    public static int EINPROGRESS;
+    
+//    @JniField(flags={FieldFlag.CONSTANT})
+//    public static int ECANCELLED;
+
+    @JniClass(flags={ClassFlag.STRUCT, ClassFlag.ZERO_OUT}, conditional="#ifdef HAVE_AIO_H")
+    static public class aiocb {
+        static {
+            CLibrary.LIBRARY.load();
+            init();
+        }
+        
+        @JniMethod(flags={CONSTANT_INITIALIZER})
+        private static final native void init();
+        
+        @JniField(flags={FieldFlag.CONSTANT}, accessor="sizeof(struct aiocb)", conditional="#ifdef
HAVE_AIO_H")
+        public static int SIZEOF;
+        
+        public int aio_fildes;
+        @JniField(cast="void *")
+        public long aio_buf;
+        @JniField(cast="size_t")
+        public long aio_nbytes;
+        @JniField(cast="off_t")
+        public long aio_offset;
+        // Don't need to access these right now:
+        // int aio_reqprio;
+        // struct sigevent aio_sigevent
+        // int aio_lio_opcode;
+        // int aio_flags;
+        
+        @JniMethod(conditional="#ifdef HAVE_AIO_H")
+        public static final native void memmove (
+                @JniArg(cast="void *", flags={NO_IN, CRITICAL}) aiocb dest, 
+                @JniArg(cast="const void *") long src, 
+                @JniArg(cast="size_t") long size);
+        
+        @JniMethod(conditional="#ifdef HAVE_AIO_H")
+        public static final native void memmove (
+                @JniArg(cast="void *") long dest, 
+                @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) aiocb src, 
+                @JniArg(cast="size_t") long size);
+    }
+    
+    @JniClass(flags={ClassFlag.STRUCT}, conditional="#ifdef HAVE_AIO_H")
+    static public class timespec {
+
+    	static {
+            CLibrary.LIBRARY.load();
+            init();
+        }
+
+        @JniMethod(flags={CONSTANT_INITIALIZER})
+        private static final native void init();
+
+        @JniField(flags={FieldFlag.CONSTANT}, accessor="sizeof(struct timespec)", conditional="#ifdef
HAVE_AIO_H")
+        public static int SIZEOF;
+        
+        @JniField(cast="time_t")
+        long tv_sec;  
+        @JniField(cast="long")
+        long tv_nsec;
+        
+        @JniMethod(conditional="#ifdef HAVE_AIO_H")
+        public static final native void memmove (
+                @JniArg(cast="void *", flags={NO_IN, CRITICAL}) timespec dest, 
+                @JniArg(cast="const void *") long src, 
+                @JniArg(cast="size_t") long size);
+        
+        @JniMethod(conditional="#ifdef HAVE_AIO_H")
+        public static final native void memmove (
+                @JniArg(cast="void *") long dest, 
+                @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) timespec src, 
+                @JniArg(cast="size_t") long size);
+        
+    }    
+    
+    /**
+     * <code><pre>
+     * int aio_read(struct aiocb *aiocbp);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native int aio_read(
+            @JniArg(cast="struct aiocb *")long aiocbp);
+
+    /**
+     * <code><pre>
+     * int aio_write(struct aiocb *aiocbp);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native int aio_write(
+            @JniArg(cast="struct aiocb *")long aiocbp);
+
+    /**
+     * <code><pre>
+     * int aio_cancel(int fd, struct aiocb *aiocbp);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native int aio_cancel(
+            int fd, 
+            @JniArg(cast="struct aiocb *")long aiocbp);
+    
+    /**
+     * <code><pre>
+     * int aio_error(const struct aiocb *aiocbp);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native int aio_error(
+            @JniArg(cast="const struct aiocb *")long aiocbp);
+    
+    /**
+     * <code><pre>
+     * ssize_t aio_return(struct aiocb *aiocbp);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native long aio_return(
+            @JniArg(cast="struct aiocb *")long aiocbp);
+
+    /**
+     * <code><pre>
+     * int aio_suspend(const struct aiocb *const list[], int nent, const struct timespec
*timeout);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_AIO_H")
+    public static final native int aio_suspend(
+            @JniArg(cast="const struct aiocb *const*")long[] list,
+            int nent,
+            @JniArg(cast="struct timespec *")long timeout);
+    
+}

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,316 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.syscall.jni;
+
+import org.fusesource.hawtjni.runtime.JniArg;
+import org.fusesource.hawtjni.runtime.JniClass;
+import org.fusesource.hawtjni.runtime.JniMethod;
+import org.fusesource.hawtjni.runtime.Library;
+import org.fusesource.hawtjni.runtime.MethodFlag;
+
+import static org.fusesource.hawtjni.runtime.ArgFlag.*;
+import static org.fusesource.hawtjni.runtime.Pointer.*;
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@JniClass
+public class CLibrary {
+
+    final public static Library LIBRARY = new Library("activemq-syscall", CLibrary.class);
+    static {
+        LIBRARY.load();
+    }
+    
+    final public static long NULL = 0;
+    
+    @JniMethod(flags={MethodFlag.CONSTANT})
+    public static final native int errno();
+
+    @JniMethod(cast="char *")
+    public static final native long strerror(int errnum);
+    
+    public static final native int strlen(
+            @JniArg(cast="char *")long s);
+    
+    public static String string(long ptr) {
+        if( ptr == NULL )
+            return null;
+        int length = strlen(ptr);
+        byte[] data = new byte[length];
+        memmove(data, ptr, length);
+        return new String(data);
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // Memory management related methods 
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    /**
+     * <code><pre>
+     * void * calloc(size_t count, size_t size);
+     * </pre></code>
+     */
+    @JniMethod(cast="void *")
+    public static final native long calloc(
+            @JniArg(cast="size_t") long count,
+            @JniArg(cast="size_t") long size);
+
+    /**
+     * <code><pre>
+     * void * malloc(size_t len);
+     * </pre></code>
+     */
+    @JniMethod(cast="void *")
+    public static final native long malloc(
+            @JniArg(cast="size_t") long size);
+    
+    /**
+     * <code><pre>
+     * void * memset(void *ptr, int c, size_t len);
+     * </pre></code>
+     */
+    @JniMethod(cast="void *")
+    public static final native long memset (
+            @JniArg(cast="void *") long buffer, 
+            int c, 
+            @JniArg(cast="size_t") long num);
+    
+    /**
+     * <code><pre>
+     * void free(void *ptr);
+     * </pre></code>
+     */
+    public static final native void free(
+            @JniArg(cast="void *") long ptr);
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // Generic void * helpers..
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="void *", accessor="add")
+    public static final native long void_pointer_add(
+            @JniArg(cast="void *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // byte helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jbyte *", accessor="add")
+    public static final native long jbyte_pointer_add(
+            @JniArg(cast="jbyte *") long ptr, 
+            long amount);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // char helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jchar *", accessor="add")
+    public static final native long jchar_pointer_add(
+            @JniArg(cast="jchar *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) char[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) char[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // short helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jshort *", accessor="add")
+    public static final native long jshort_pointer_add(
+            @JniArg(cast="jshort *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL})  short[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) short[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // int helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jint *", accessor="add")
+    public static final native long jint_pointer_add(
+            @JniArg(cast="jint *") long ptr, 
+            long amount);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL})  int[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) int[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // long helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+
+    @JniMethod(cast="jlong *", accessor="add")
+    public static final native long jlong_pointer_add(
+            @JniArg(cast="jlong *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}, pointer=FALSE) long[]
src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}, pointer=FALSE) long[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // float helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jfloat *", accessor="add")
+    public static final native long jfloat_pointer_add(
+            @JniArg(cast="jfloat *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) float[] src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) float[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // double helpers / converters.
+    //
+    ///////////////////////////////////////////////////////////////////
+    
+    @JniMethod(cast="jdouble *", accessor="add")
+    public static final native long jdouble_pointer_add(
+            @JniArg(cast="jdouble *") long ptr, 
+            long amount);
+
+    public static final native void memmove (
+            @JniArg(cast="void *") long dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) double[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) double[] dest, 
+            @JniArg(cast="const void *") long src, 
+            @JniArg(cast="size_t") long size);
+    
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // Common array type converters..
+    //
+    ///////////////////////////////////////////////////////////////////
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL})  char[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) char[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL})  byte[] src, 
+            @JniArg(cast="size_t") long size);
+
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) int[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) int[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) short[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) short[] src, 
+            @JniArg(cast="size_t") long size);
+
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) long[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src, 
+            @JniArg(cast="size_t") long size);
+    
+    public static final native void memmove (
+            @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest, 
+            @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) long[] src, 
+            @JniArg(cast="size_t") long size);
+    
+}

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/IO.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/IO.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/IO.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/IO.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,181 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.syscall.jni;
+
+import org.fusesource.hawtjni.runtime.JniClass;
+import org.fusesource.hawtjni.runtime.JniField;
+import org.fusesource.hawtjni.runtime.JniMethod;
+
+import static org.fusesource.hawtjni.runtime.MethodFlag.*;
+
+import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@JniClass
+public class IO {
+
+    @JniMethod(flags={CONSTANT_INITIALIZER})
+    private static final native void init();
+    static {
+        CLibrary.LIBRARY.load();
+        init();
+    }
+
+    @JniField(flags={CONSTANT})
+    public static int O_RDONLY;
+    @JniField(flags={CONSTANT})
+    public static int O_WRONLY;
+    @JniField(flags={CONSTANT})
+    public static int O_RDWR;
+    @JniField(flags={CONSTANT})
+    public static int O_APPEND;
+    @JniField(flags={CONSTANT})
+    public static int O_CREAT;
+    @JniField(flags={CONSTANT})
+    public static int O_TRUNC;
+    @JniField(flags={CONSTANT})
+    public static int O_EXCL;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_NONBLOCK")
+    public static int O_NONBLOCK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_ASYNC")
+    public static int O_ASYNC;
+    
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_SHLOCK")
+    public static int O_SHLOCK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_EXLOCK")
+    public static int O_EXLOCK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_NOFOLLOW")
+    public static int O_NOFOLLOW;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_SYMLINK")
+    public static int O_SYMLINK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef O_EVTONLY")
+    public static int O_EVTONLY;
+    
+    // Mode Constants
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IRWXU")
+    public static int S_IRWXU;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IRUSR")
+    public static int S_IRUSR;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IWUSR")
+    public static int S_IWUSR;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IXUSR")
+    public static int S_IXUSR;            
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IRWXG")
+    public static int S_IRWXG;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IRGRP")
+    public static int S_IRGRP;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IWGRP")
+    public static int S_IWGRP;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IXGRP")
+    public static int S_IXGRP;            
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IRWXO")
+    public static int S_IRWXO;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IROTH")
+    public static int S_IROTH;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IWOTH")
+    public static int S_IWOTH;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_IXOTH")
+    public static int S_IXOTH;            
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_ISUID")
+    public static int S_ISUID;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_ISGID")
+    public static int S_ISGID;
+    @JniField(flags={CONSTANT}, conditional="#ifdef S_ISVTX")
+    public static int S_ISVTX;
+    
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_DUPFD")
+    public static int F_DUPFD;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_GETFD")
+    public static int F_GETFD;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETFD")
+    public static int F_SETFD;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_GETFL")
+    public static int F_GETFL;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETFL")
+    public static int F_SETFL;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_GETOWN")
+    public static int F_GETOWN;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETOWN")
+    public static int F_SETOWN;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_GETLK")
+    public static int F_GETLK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETLK")
+    public static int F_SETLK;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETLKW")
+    public static int F_SETLKW;
+
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_GETPATH")
+    public static int F_GETPATH;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_PREALLOCATE")
+    public static int F_PREALLOCATE;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_SETSIZE")
+    public static int F_SETSIZE;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_RDADVISE")
+    public static int F_RDADVISE;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_RDAHEAD")
+    public static int F_RDAHEAD;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_READBOOTSTRAP")
+    public static int F_READBOOTSTRAP;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_WRITEBOOTSTRAP")
+    public static int F_WRITEBOOTSTRAP;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_NOCACHE")
+    public static int F_NOCACHE;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_LOG2PHYS")
+    public static int F_LOG2PHYS;
+    @JniField(flags={CONSTANT}, conditional="#ifdef F_FULLFSYNC")
+    public static int F_FULLFSYNC;
+    
+    ///////////////////////////////////////////////////////////////////
+    //
+    // IO related methods 
+    //
+    ///////////////////////////////////////////////////////////////////
+    /**
+     * <code><pre>
+     * int open(const char *path, int oflags, ...);
+     * </pre></code>
+     */
+    public static final native int open(String path, int oflags);
+    
+    /**
+     * <code><pre>
+     * int open(const char *path, int oflags, ...);
+     * </pre></code>
+     */
+    public static final native int open(String path, int oflags, int mode);
+
+    /**
+     * <code><pre>
+     * int close(int fd);
+     * </pre></code>
+     */
+    public static final native int close(int fd);
+
+    /**
+     * <code><pre>
+     * int fcntl(int fd, int cmd, ...);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_FCNTL_FUNCTION")
+    public static final native int fcntl(int fd, int cmd);
+        
+    
+
+}

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/Posix.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/Posix.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/Posix.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/Posix.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.syscall.jni;
+
+import org.fusesource.hawtjni.runtime.JniArg;
+import org.fusesource.hawtjni.runtime.JniClass;
+import org.fusesource.hawtjni.runtime.JniMethod;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@JniClass
+public class Posix extends CLibrary {
+
+    /**
+     * <code><pre>
+     * int posix_memalign(void **ptrRef, size_t alignment, size_t len);
+     * </pre></code>
+     */
+    @JniMethod(conditional="#ifdef HAVE_POSIX_MEMALIGN_FUNCTION")
+    public static final native int posix_memalign(
+            @JniArg(cast="void **") long ptrRef[], 
+            @JniArg(cast="size_t")  long alignment, 
+            @JniArg(cast="size_t")  long len);
+    
+}

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,26 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Provide low level access to OS level system calls.  These APIs do a little
+object wrapping as possible to provide good performance.
+
+</body>
+</html>

Propchange: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/package.html
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,25 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Provide easier to use access class to the system call JNI functions.
+
+</body>
+</html>

Propchange: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/package.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h?rev=881737&r1=881736&r2=881737&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
Wed Nov 18 12:01:14 2009
@@ -42,4 +42,7 @@
 #endif
 
 #include <fcntl.h>
+
+#define add(value1, value2) ((value1)+value2)
+
 #endif /* INCLUDED_ACTIVEMQ_SYSCALL_H */

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/AIOTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/AIOTest.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/AIOTest.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/AIOTest.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,133 @@
+package org.apache.activemq.syscall.jni;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.activemq.syscall.NativeAllocation;
+import org.apache.activemq.syscall.jni.AIO;
+import org.apache.activemq.syscall.jni.AIO.aiocb;
+import org.junit.Test;
+
+import static org.apache.activemq.syscall.jni.AIO.*;
+import static org.apache.activemq.syscall.jni.CLibrary.*;
+import static org.apache.activemq.syscall.jni.IO.*;
+
+import static org.apache.activemq.syscall.NativeAllocation.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.junit.Assume.*;
+
+public class AIOTest {
+    
+    @Test
+    public void write() throws IOException, InterruptedException {
+    	assumeThat(AIO.SUPPORTED, is(true));
+    	 
+        File file = new File("target/test-data/test.data");
+        file.getParentFile().mkdirs();
+
+        // Setup a buffer holds the data that we will be writing..
+        StringBuffer sb = new StringBuffer();
+        for( int i=0; i < 1024*4; i++ ) {
+            sb.append((char)('a'+(i%26)));
+        }
+                
+        String expected = sb.toString();
+        NativeAllocation writeBuffer = allocate(expected);
+
+        long aiocbp = malloc(aiocb.SIZEOF);
+        System.out.println("Allocated cb of size: "+aiocb.SIZEOF);
+
+        try {
+            // open the file...
+            int mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
+            int fd = open(file.getCanonicalPath(), O_NONBLOCK | O_CREAT | O_TRUNC| O_RDWR,
mode);
+            checkrc(fd);
+            
+            // Create a control block..
+            // The where:
+            aiocb cb = new aiocb();
+            cb.aio_fildes = fd;
+            cb.aio_offset = 0;
+            // The what:
+            cb.aio_buf = writeBuffer.pointer();        
+            cb.aio_nbytes = writeBuffer.length();
+            
+            // Move the struct into the c heap.
+            aiocb.memmove(aiocbp, cb, aiocb.SIZEOF);
+
+            // enqueue the async write..
+            checkrc(aio_write(aiocbp));
+            
+            long blocks[] = new long[]{aiocbp};
+            
+            // Wait for the IO to complete.
+            long timeout = NULL; // To suspend forever.
+            checkrc(aio_suspend(blocks, blocks.length, timeout));
+            
+            // Check to see if it completed.. it should 
+            // since we previously suspended.
+            int rc = aio_error(aiocbp);
+            checkrc(rc);
+            assertEquals(0, rc);
+
+            // The full buffer should have been written.
+            long count = aio_return(aiocbp);
+            assertEquals(count, writeBuffer.length());
+            
+            checkrc(close(fd));
+            
+        } finally {
+            // Lets free up allocated memory..
+            writeBuffer.free();
+            if( aiocbp!=NULL ) {
+                free(aiocbp);
+            }
+        }
+        
+        // Read the file in and verify the contents is what we expect 
+        String actual = loadContent(file);
+        assertEquals(expected, actual);
+    }
+
+    private String loadContent(File file) throws FileNotFoundException, IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        FileInputStream is = new FileInputStream(file);
+        try {
+            int c=0;
+            while( (c=is.read())>=0 ) {
+                baos.write(c);
+            }
+        } finally {
+            is.close();
+        }
+        String actual = new String(baos.toByteArray());
+        return actual;
+    }
+
+    private void storeContent(File file, String content) throws FileNotFoundException, IOException
{
+        FileOutputStream os = new FileOutputStream(file);
+        try {
+            os.write(content.getBytes());
+        } finally {
+            os.close();
+        }
+    }
+    
+    private void checkrc(int rc) throws IOException {
+        if( rc==-1 ) {
+            throw new IOException("IO failure: "+string(strerror(errno())));
+        }
+    }
+
+    @Test
+    public void testFree() {
+        long ptr = malloc(100);
+        free(ptr);
+    }
+    
+}

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/CLibraryTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/CLibraryTest.java?rev=881737&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/CLibraryTest.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/test/java/org/apache/activemq/syscall/jni/CLibraryTest.java
Wed Nov 18 12:01:14 2009
@@ -0,0 +1,24 @@
+package org.apache.activemq.syscall.jni;
+
+import org.apache.activemq.syscall.jni.CLibrary;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.activemq.syscall.jni.CLibrary.*;
+
+
+public class CLibraryTest {
+    
+    @Test
+    public void testMalloc() {
+        long ptr = CLibrary.malloc(100);
+        Assert.assertTrue(ptr!=0);
+    }
+    
+    @Test
+    public void testFree() {
+        long ptr = malloc(100);
+        free(ptr);
+    }
+    
+}



Mime
View raw message