[jboss-cvs] JBoss Messaging SVN: r3818 - in trunk: native and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 27 09:37:11 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-02-27 09:37:11 -0500 (Wed, 27 Feb 2008)
New Revision: 3818

Added:
   trunk/native/
   trunk/native/AUTHORS
   trunk/native/COPYING
   trunk/native/ChangeLog
   trunk/native/INSTALL
   trunk/native/Makefile.am
   trunk/native/NEWS
   trunk/native/README
   trunk/native/acinclude.m4
   trunk/native/bootstrap
   trunk/native/build-aux/
   trunk/native/configure.ac
   trunk/native/perf-disk
   trunk/native/src/
   trunk/native/src/AIOController.cpp
   trunk/native/src/AIOController.h
   trunk/native/src/AIOException.h
   trunk/native/src/AsyncFile.cpp
   trunk/native/src/AsyncFile.h
   trunk/native/src/CallbackAdapter.h
   trunk/native/src/JAIODatatypes.h
   trunk/native/src/JNICallbackAdapter.cpp
   trunk/native/src/JNICallbackAdapter.h
   trunk/native/src/JavaUtilities.cpp
   trunk/native/src/JavaUtilities.h
   trunk/native/src/LibAIOController.cpp
   trunk/native/src/LockClass.h
   trunk/native/src/Makefile.am
   trunk/native/src/org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO.h
Log:
Adding native code (jLibAIO)

Added: trunk/native/AUTHORS
===================================================================

Added: trunk/native/COPYING
===================================================================

Added: trunk/native/ChangeLog
===================================================================

Added: trunk/native/INSTALL
===================================================================
--- trunk/native/INSTALL	                        (rev 0)
+++ trunk/native/INSTALL	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,234 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
+2006 Free Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+Briefly, the shell commands `./configure; make; make install' should
+configure, build, and install this package.  The following
+more-detailed instructions are generic; see the `README' file for
+instructions specific to this package.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You need `configure.ac' if
+you want to change it or regenerate `configure' using a newer version
+of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.
+
+     Running `configure' might take a while.  While running, it prints
+     some messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c99 CFLAGS=-g LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you can use GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   With a non-GNU `make', it is safer to compile the package for one
+architecture at a time in the source code directory.  After you have
+installed the package for one architecture, use `make distclean' before
+reconfiguring for another architecture.
+
+Installation Names
+==================
+
+By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc.  You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
+an Autoconf bug.  Until the bug is fixed you can use this workaround:
+
+     CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+

Added: trunk/native/Makefile.am
===================================================================
--- trunk/native/Makefile.am	                        (rev 0)
+++ trunk/native/Makefile.am	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1 @@
+SUBDIRS = src tests

Added: trunk/native/NEWS
===================================================================

Added: trunk/native/README
===================================================================
--- trunk/native/README	                        (rev 0)
+++ trunk/native/README	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,72 @@
+How to build jLibAIO:
+
+You will need to make sure you these following dependencies:
+
+ - G++
+ - Gcc
+ - autotools-dev (including libtool, automake, autoconf)
+ - Make
+ - libaio (0.3.106)
+ - libaio-dev
+ - JDK (full JDK)
+
+
+To build the native part:
+ Make sure you have JAVA_HOME defined, and pointing to the root of your JDK:
+ Example:
+ 
+ $> export JAVA_HOME=/usr/share/jdk1.5.0_13
+ 
+ 
+ Go to ./native and call bootstrap. Bootstrap will call all the initial scripts you need
+ $>  ./bootstrap
+ 
+ if you are missing any dependencies, autoconf would tell you what you're missing.
+ 
+ After bootstrap is called for the first time, you can aways build it by just calling make
+ 
+
+To run the java part:
+ Add <pathToYourProject>/native/src/.lib to LD_LIBRARY_PATH
+ Example:
+ 
+ $> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/myWorkspace/native/src/.lib
+ 
+ $> cd ./java
+ 
+ $> ant tests
+ 
+ 
+ 
+
+
+Todo on the implementation:
+   - if queue is full, it needs to retry until it can find a slot (ok)
+
+Todo on the API:
+  - initialize with number of slots (ok)
+  - newAlignedBuffer (ok)
+  - destroyAlignedBuffer (ok)
+  - write (position, ByteBuffer, Callback) (ok)
+  - read (position, ByteBuffer, Callback) (ok)
+  - Logging (callback in Java); (ok
+  - Add more logging on the native layer
+  - Organize error codes
+  
+
+
+
+Future versions:
+  - MemoryPaging
+  
+  
+ Documenting:
+    - Man page libaio 
+      - requirements - O_BINARY
+      - requirements - Pre Allocation
+      - typos on the documentation (include libio?)
+      - Update example
+      - Max events ( /proc/sys/fs/aio-max-nr )
+      - is io_submit should be thread safe if you sumit on different io_cbs
+
+ 

Added: trunk/native/acinclude.m4
===================================================================
--- trunk/native/acinclude.m4	                        (rev 0)
+++ trunk/native/acinclude.m4	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,58 @@
+# serial 3
+# Find valid warning flags for the C Compiler.           -*-Autoconf-*-
+dnl Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl Written by Jesse Thilo.
+
+AC_DEFUN([gl_COMPILER_FLAGS],
+  [AC_MSG_CHECKING(whether compiler accepts $1)
+   AC_SUBST(COMPILER_FLAGS)
+   ac_save_CFLAGS="$CFLAGS"
+   CFLAGS="$CFLAGS $1"
+   ac_save_CXXFLAGS="$CXXFLAGS"
+   CXXFLAGS="$CXXFLAGS $1"
+   AC_TRY_COMPILE(,
+    [int x;],
+    COMPILER_FLAGS="$COMPILER_FLAGS $1"
+    AC_MSG_RESULT(yes),
+    AC_MSG_RESULT(no))
+  CFLAGS="$ac_save_CFLAGS"
+  CXXFLAGS="$ac_save_CXXFLAGS"
+ ])
+
+
+AC_DEFUN([AC_JNI_INCLUDE_DIR],
+[
+   JNI_INCLUDE_DIRS=""
+
+test -f $JAVA_HOME/include/jni.h || \
+     AC_MSG_ERROR([JAVA_HOME=$JAVA_HOME does not appear to be a valid java home.])
+
+
+JNI_INCLUDE_DIRS="$JAVA_HOME/include"
+case "$OSTYPE" in
+bsdi*)                  _JNI_INC_SUBDIRS="dos";;
+linux*)                 _JNI_INC_SUBDIRS="linux";;
+mingw32*|cygwin*)       _JNI_INC_SUBDIRS="win32";;
+osf*)                   _JNI_INC_SUBDIRS="alpha";;
+solaris*)               _JNI_INC_SUBDIRS="solaris";;
+*)                      _JNI_INC_SUBDIRS="genunix";;
+esac
+
+# add any subdirectories that are present
+for JINCSUBDIR in $_JNI_INC_SUBDIRS
+do
+       echo tttt $JINCSUBDIR
+        if test -d "$JAVA_HOME/include/$JINCSUBDIR"; then
+                JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $JAVA_HOME/include/$JINCSUBDIR"
+        fi
+done
+
+# add it to the CPPFLAGS, for convenience
+for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
+do
+        CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR"
+done
+])

Added: trunk/native/bootstrap
===================================================================
--- trunk/native/bootstrap	                        (rev 0)
+++ trunk/native/bootstrap	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,3 @@
+autoreconf --install
+./configure
+make


Property changes on: trunk/native/bootstrap
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/native/configure.ac
===================================================================
--- trunk/native/configure.ac	                        (rev 0)
+++ trunk/native/configure.ac	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,66 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.61)
+AC_INIT([jboss-profiler-jvmti], [1.0.Alpha],[clebert.suconic at jboss.org])
+AC_CONFIG_AUX_DIR([build-aux])
+
+AM_INIT_AUTOMAKE([dist-bzip2])
+
+# Minimum Autoconf version required.
+AC_PREREQ(2.59)
+
+AC_JNI_INCLUDE_DIR
+AC_CONFIG_HEADERS([config.h:config.in])
+AC_CONFIG_SRCDIR([src/LibAIOController.cpp])
+
+# Check for libaio and libaio-devel
+libaio_fail=0
+AC_CHECK_LIB([aio], [io_setup], ,[libaio_fail=1])
+AC_CHECK_HEADER([libaio.h], ,[libaio_fail=1])
+test $libaio_fail == 1 && \
+  AC_MSG_ERROR([libaio-devel package missing. Please ensure both libaio and libaio-devel are installed. (hint: yum install libaio-devel should do it...)])
+	
+
+gl_COMPILER_FLAGS(-Werror)
+gl_COMPILER_FLAGS(-g)
+gl_COMPILER_FLAGS(-pedantic)
+gl_COMPILER_FLAGS(-Wall)
+gl_COMPILER_FLAGS(-Wextra)
+gl_COMPILER_FLAGS(-Wno-shadow)
+gl_COMPILER_FLAGS(-Wpointer-arith)
+gl_COMPILER_FLAGS(-Wcast-qual)
+gl_COMPILER_FLAGS(-Wcast-align)
+gl_COMPILER_FLAGS(-Wno-long-long)
+gl_COMPILER_FLAGS(-Wvolatile-register-var)
+gl_COMPILER_FLAGS(-Winvalid-pch)
+gl_COMPILER_FLAGS(-Wno-system-headers)
+
+CPPFLAGS="$CPPFLAGS $COMPILER_FLAGS"
+
+# Checks for programs.
+AC_PROG_CXX
+AC_PROG_CC
+AC_PROG_CPP
+
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([stdlib.h string.h sys/time.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_C_INLINE
+AC_HEADER_TIME
+AC_HEADER_STDBOOL
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([gettimeofday memset strstr])
+
+AC_CONFIG_FILES([Makefile ./src/Makefile ./tests/Makefile])
+AC_OUTPUT

Added: trunk/native/perf-disk
===================================================================
--- trunk/native/perf-disk	                        (rev 0)
+++ trunk/native/perf-disk	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,3 @@
+#validates the performance in your disk
+dd if=/dev/zero of=/tmp/foo.dat bs=1M count=100 oflag=direct
+rm /tmp/foo.dat


Property changes on: trunk/native/perf-disk
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/native/src/AIOController.cpp
===================================================================
--- trunk/native/src/AIOController.cpp	                        (rev 0)
+++ trunk/native/src/AIOController.cpp	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,62 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+
+#include <string>
+#include "AIOController.h"
+#include "JavaUtilities.h"
+#include "JAIODatatypes.h"
+
+AIOController::AIOController(std::string fileName, int maxIO) : logger(0), fileOutput(fileName, this, maxIO) 
+{
+}
+
+void AIOController::log(THREAD_CONTEXT threadContext, short level, char * message)
+{
+	jmethodID methodID = 0;
+	
+	switch (level)
+	{
+	case 0: methodID = loggerError; break;
+	case 1: methodID = loggerWarn; break;
+	case 2: methodID = loggerInfo; break;
+	case 3: methodID = loggerDebug; break;
+	default: methodID = loggerDebug; break;
+	}
+
+#ifdef DEBUG
+	fprintf (stderr,"Callig log methodID=%ld, message=%s, logger=%ld, threadContext = %ld\n", (long) methodID, message, (long) logger, (long) threadContext); fflush(stderr);
+#endif
+	threadContext->CallVoidMethod(logger,methodID,threadContext->NewStringUTF(message));
+}
+
+
+void AIOController::destroy(THREAD_CONTEXT context)
+{
+	context->DeleteGlobalRef(logger);
+}
+
+/*
+ * level = 0-error, 1-warn, 2-info, 3-debug
+ */
+
+
+AIOController::~AIOController()
+{
+}


Property changes on: trunk/native/src/AIOController.cpp
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/native/src/AIOController.h
===================================================================
--- trunk/native/src/AIOController.h	                        (rev 0)
+++ trunk/native/src/AIOController.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,54 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+
+#ifndef AIOCONTROLLER_H_
+#define AIOCONTROLLER_H_
+#include <jni.h>
+#include <string>
+#include "JAIODatatypes.h"
+#include "AsyncFile.h"
+
+class AIOController
+{
+public:
+	jmethodID done;
+	jmethodID error;
+
+	jobject logger;
+	
+	jmethodID loggerError;
+	jmethodID loggerWarn;
+	jmethodID loggerDebug;
+	jmethodID loggerInfo;
+
+	/*
+	 * level = 0-error, 1-warn, 2-info, 3-debug
+	 */
+	void log(THREAD_CONTEXT threadContext, short level, char * message);
+	
+	int fileHandle;
+	AsyncFile fileOutput;
+	
+	void destroy(THREAD_CONTEXT context);
+	
+	AIOController(std::string fileName, int maxIO);
+	virtual ~AIOController();
+};
+#endif /*AIOCONTROLLER_H_*/

Added: trunk/native/src/AIOException.h
===================================================================
--- trunk/native/src/AIOException.h	                        (rev 0)
+++ trunk/native/src/AIOException.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+
+
+#ifndef AIOEXCEPTION_H_
+#define AIOEXCEPTION_H_
+
+#include <exception>
+#include <string>
+
+class AIOException : public std::exception
+{
+private:
+	int errorCode;
+	std::string message;
+public:
+	AIOException(int _errorCode, std::string  _message) throw() : errorCode(_errorCode), message(_message)
+	{
+		errorCode = _errorCode;
+		message = _message;
+	}
+	
+	AIOException(int _errorCode, const char * _message) throw ()
+	{
+		message = std::string(_message);
+		errorCode = _errorCode;
+	}
+	
+	virtual ~AIOException() throw()
+	{
+		
+	}
+	
+	int inline getErrorCode()
+	{
+		return errorCode;
+	}
+	
+    const char* what() const throw()
+    {
+    	return message.data();
+    }
+	
+};
+
+#endif /*AIOEXCEPTION_H_*/

Added: trunk/native/src/AsyncFile.cpp
===================================================================
--- trunk/native/src/AsyncFile.cpp	                        (rev 0)
+++ trunk/native/src/AsyncFile.cpp	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,292 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+
+#include <stdlib.h>
+#include <list>
+#include <iostream>
+#include <sstream>
+#include <memory.h>
+#include <errno.h>
+#include <libaio.h>
+#include <fcntl.h>
+#include "AsyncFile.h"
+#include "AIOController.h"
+#include "AIOException.h"
+#include "pthread.h"
+#include "LockClass.h"
+#include "CallbackAdapter.h"
+#include "LockClass.h"
+
+//#define DEBUG
+
+#define WAIT_FOR_SPOT 10000
+#define TRIES_BEFORE_WARN 0
+#define TRIES_BEFORE_ERROR 500
+
+
+std::string io_error(int rc)
+{
+	std::stringstream buffer;
+	
+	if (rc == -ENOSYS)
+		buffer << "AIO not in this kernel";
+	else 
+		buffer << "Error:= " << strerror(-rc);
+	
+	return buffer.str();
+}
+
+
+AsyncFile::AsyncFile(std::string & _fileName, AIOController * _controller, int _maxIO) : aioContext(0), events(0), fileHandle(0), controller(_controller), pollerRunning(0)
+{
+	::pthread_mutex_init(&fileMutex,0);
+	::pthread_mutex_init(&pollerMutex,0);
+	
+	maxIO = _maxIO;
+	fileName = _fileName;
+	if (io_queue_init(maxIO, &aioContext))
+	{
+		throw AIOException(1, "Can't initialize aio"); 
+	}
+
+	fileHandle = ::open(fileName.data(),  O_RDWR | O_CREAT | O_DIRECT, 0666);
+	if (fileHandle < 0)
+	{
+		throw AIOException(1, "Can't open file"); 
+	}
+	
+#ifdef DEBUG
+	fprintf (stderr,"File Handle %d", fileHandle);
+#endif
+
+	events = (struct io_event *)malloc (maxIO * sizeof (struct io_event));
+
+}
+
+AsyncFile::~AsyncFile()
+{
+	::pthread_mutex_destroy(&fileMutex);
+	::pthread_mutex_destroy(&pollerMutex);
+	free(events);
+	if (io_queue_release(aioContext))
+	{
+		throw AIOException(2,"Can't release aio");
+	}
+	if (::close(fileHandle))
+	{
+		throw AIOException(2,"Can't close file");
+	}
+}
+
+void AsyncFile::pollEvents(THREAD_CONTEXT threadContext)
+{
+	
+	LockClass lock(&pollerMutex);
+	pollerRunning=1;
+	
+	// TODO: Maybe we don't need to wait for one second.... we just keep waiting forever, and use something to interrupt it
+	// maybe an invalid write to interrupt it.
+	struct timespec oneSecond;
+	oneSecond.tv_sec = 1;
+	oneSecond.tv_nsec = 0;
+	
+	
+	while (pollerRunning)
+	{
+		int result = io_getevents(this->aioContext, 1, maxIO, events, &oneSecond);
+		
+#ifdef DEBUG
+		fprintf (stderr, "poll, pollerRunning=%d\n", pollerRunning); fflush(stderr);
+#endif
+		
+		if (result > 0)
+		{
+			
+#ifdef DEBUG
+			fprintf (stdout, "Received %d events\n", result);
+			fflush(stdout);
+#endif
+		}
+
+		for (int i=0; i<result; i++)
+		{
+			
+			struct iocb * iocbp = events[i].obj;
+	
+			CallbackAdapter * adapter = (CallbackAdapter *) iocbp->data;
+			
+			long result = events[i].res;
+			if (result < 0)
+			{
+				std::string strerror = io_error(result);
+				adapter->onError(threadContext, result, strerror);
+			}
+			else
+			{
+				adapter->completeBlock(threadContext);
+				adapter->deleteRef(threadContext);
+			}
+			
+			delete iocbp;
+		}
+	}
+	
+	controller->log(threadContext, 2, "Poller finished execution");
+	
+}
+
+
+void AsyncFile::preAllocate(THREAD_CONTEXT threadContext, int blocks, size_t size)
+{
+	size_t currentSize = lseek (fileHandle, 0, SEEK_END);
+	
+	if (currentSize >= blocks * size)
+	{
+		controller->log(threadContext,2,"File being reused");
+		return;
+	}
+	
+	if (size % ALIGNMENT != 0)
+	{
+		throw AIOException (101, "You can only pre allocate files in multiples of 512");
+	}
+	
+	void * preAllocBuffer = 0;
+	if (posix_memalign(&preAllocBuffer, 512, size))
+	{
+		throw AIOException(10, "Error on posix_memalign");
+	}
+	
+	memset(preAllocBuffer, 0, size);
+	
+	
+	if (::lseek (fileHandle, 0, SEEK_SET) < 0) throw AIOException (11, "Error positioning the file");
+	
+	for (int i=0; i<blocks; i++)
+	{
+		if (::write(fileHandle, preAllocBuffer, size)<0)
+		{
+			throw AIOException (12, "Error pre allocating the file");
+		}
+	}
+	
+	if (::lseek (fileHandle, 0, SEEK_SET) < 0) throw AIOException (11, "Error positioning the file");
+	
+	free (preAllocBuffer);
+}
+
+void AsyncFile::write(THREAD_CONTEXT threadContext, long position, size_t size, void *& buffer, CallbackAdapter *& adapter)
+{
+
+	struct iocb * iocb = new struct iocb();
+	::io_prep_pwrite(iocb, fileHandle, buffer, size, position);
+	iocb->data = (void *) adapter;
+
+	int tries = 0;
+	int result = 0;
+	
+	while ((result = ::io_submit(aioContext, 1, &iocb)) == (-EAGAIN))
+	{
+#ifdef DEBUG
+		fprintf (stderr, "Retrying block as iocb was full (retry=%d)\n", tries);
+#endif
+		tries ++;
+		if (tries > TRIES_BEFORE_WARN)
+		{
+#ifdef DEBUG
+		    fprintf (stderr, "Warning level on retries, informing logger (retry=%d)\n", tries);
+#endif
+			controller->log(threadContext, 1, "You should consider expanding AIOLimit if this message appears too many times");
+		}
+		
+		if (tries > TRIES_BEFORE_ERROR)
+		{
+#ifdef DEBUG
+		    fprintf (stderr, "Error level on retries, throwing exception (retry=%d)\n", tries);
+#endif
+			throw AIOException(500, "Too many retries (500) waiting for a valid iocb block, please increase MAX_IO limit");
+		}
+		::usleep(WAIT_FOR_SPOT);
+	}
+	
+	if (result<0)
+	{
+		std::stringstream str;
+		str<< "Problem on submit block, errorCode=" << result;
+		throw AIOException (6, str.str());
+	}
+}
+
+void AsyncFile::read(THREAD_CONTEXT threadContext, long position, size_t size, void *& buffer, CallbackAdapter *& adapter)
+{
+
+	struct iocb * iocb = new struct iocb();
+	::io_prep_pread(iocb, fileHandle, buffer, size, position);
+	iocb->data = (void *) adapter;
+
+	int tries = 0;
+	int result = 0;
+	
+	// I will hold the lock until I'm done here
+	//LockClass lock(&fileMutex);
+	while ((result = ::io_submit(aioContext, 1, &iocb)) == (-EAGAIN))
+	{
+#ifdef DEBUG
+		fprintf (stderr, "Retrying block as iocb was full (retry=%d)\n", tries);
+#endif
+		tries ++;
+		if (tries > TRIES_BEFORE_WARN)
+		{
+#ifdef DEBUG
+		    fprintf (stderr, "Warning level on retries, informing logger (retry=%d)\n", tries);
+#endif
+			controller->log(threadContext, 1, "You should consider expanding AIOLimit if this message appears too many times");
+		}
+		
+		if (tries > TRIES_BEFORE_ERROR)
+		{
+#ifdef DEBUG
+		    fprintf (stderr, "Error level on retries, throwing exception (retry=%d)\n", tries);
+#endif
+			throw AIOException(500, "Too many retries (500) waiting for a valid iocb block, please increase MAX_IO limit");
+		}
+		::usleep(WAIT_FOR_SPOT);
+	}
+	
+	if (result<0)
+	{
+		std::stringstream str;
+		str<< "Problem on submit block, errorCode=" << result;
+		throw AIOException (6, str.str());
+	}
+}
+
+void AsyncFile::stopPoller(THREAD_CONTEXT threadContext)
+{
+	pollerRunning = 0;
+	controller->log(threadContext, 2,"Setting poller to stop");
+	// It will wait the Poller to gives up its lock
+	LockClass lock(&pollerMutex);
+}
+


Property changes on: trunk/native/src/AsyncFile.cpp
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/native/src/AsyncFile.h
===================================================================
--- trunk/native/src/AsyncFile.h	                        (rev 0)
+++ trunk/native/src/AsyncFile.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,89 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef FILEOUTPUT_H_
+#define FILEOUTPUT_H_
+
+#include <string>
+#include <libaio.h>
+#include <pthread.h>
+#include "JAIODatatypes.h"
+#include "AIOException.h"
+
+class AIOController;
+
+class CallbackAdapter;
+
+class AsyncFile
+{
+private:
+	io_context_t aioContext;
+	struct io_event *events; 
+	int fileHandle;
+	std::string fileName;
+	
+	pthread_mutex_t fileMutex;
+	pthread_mutex_t pollerMutex;
+	
+	AIOController * controller;
+	
+	bool pollerRunning;
+	
+	int maxIO;
+	
+public:
+	AsyncFile(std::string & _fileName, AIOController * controller, int maxIO);
+	virtual ~AsyncFile();
+	
+	void write(THREAD_CONTEXT threadContext, long position, size_t size, void *& buffer, CallbackAdapter *& adapter);
+	
+	void read(THREAD_CONTEXT threadContext, long position, size_t size, void *& buffer, CallbackAdapter *& adapter);
+	
+	int getHandle()
+	{
+		return fileHandle;
+	}
+
+	inline void * newBuffer(int size)
+	{
+		void * buffer = 0;
+		if (::posix_memalign(&buffer, 512, size))
+		{
+			throw AIOException(10, "Error on posix_memalign");
+		}
+		return buffer;
+		
+	}
+
+	inline void destroyBuffer(void * buffer)
+	{
+		::free(buffer);
+	}
+
+	
+	// Finishes the polling thread (if any) and return
+	void stopPoller(THREAD_CONTEXT threadContext);
+	
+	void preAllocate(THREAD_CONTEXT threadContext, int numberOfBlocks, size_t size);
+	
+	void pollEvents(THREAD_CONTEXT threadContext);
+	
+};
+
+#endif /*FILEOUTPUT_H_*/

Added: trunk/native/src/CallbackAdapter.h
===================================================================
--- trunk/native/src/CallbackAdapter.h	                        (rev 0)
+++ trunk/native/src/CallbackAdapter.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,69 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef BUFFERADAPTER_H_
+#define BUFFERADAPTER_H_
+
+#include <iostream>
+
+#include "JAIODatatypes.h"
+
+class CallbackAdapter
+{
+private:
+    // The number of pages that are expected to be used by this Buffer
+    int blocks;
+
+    virtual void destroy(THREAD_CONTEXT threadContext) = 0;
+public:
+	CallbackAdapter() : blocks(1)
+	{
+		
+	}
+	virtual ~CallbackAdapter()
+	{
+		
+	}
+	
+	void setBlocks(int _blocks)
+	{
+		blocks = _blocks;
+	}
+	
+	void addBlock()
+	{
+		// TODO: Do I need to mutex here?
+		blocks++;
+	}
+	
+	void completeBlock(THREAD_CONTEXT threadContext)
+	{
+		// TODO: Do I need to mutex here?
+		if (--blocks <= 0)
+		{
+			done(threadContext);
+		}
+	}
+	
+	virtual void addref(THREAD_CONTEXT threadContext) = 0;
+	virtual void deleteRef(THREAD_CONTEXT threadContext) = 0;
+	virtual void done(THREAD_CONTEXT threadContext) = 0;
+	virtual void onError(THREAD_CONTEXT threadContext, long error, std::string error)=0;
+};
+#endif /*BUFFERADAPTER_H_*/

Added: trunk/native/src/JAIODatatypes.h
===================================================================
--- trunk/native/src/JAIODatatypes.h	                        (rev 0)
+++ trunk/native/src/JAIODatatypes.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,30 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef JAIODATATYPES_H_
+#define JAIODATATYPES_H_
+
+#include <jni.h>
+
+#define THREAD_CONTEXT JNIEnv *&
+#define JNI_ENV(pointer) pointer 
+#define ALIGNMENT 512
+
+
+#endif /*JAIODATATYPES_H_*/

Added: trunk/native/src/JNICallbackAdapter.cpp
===================================================================
--- trunk/native/src/JNICallbackAdapter.cpp	                        (rev 0)
+++ trunk/native/src/JNICallbackAdapter.cpp	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,51 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#include <jni.h>
+#include "JNICallbackAdapter.h"
+#include <iostream>
+#include "JavaUtilities.h"
+
+JNICallbackAdapter::JNICallbackAdapter(AIOController * _controller, jobject _obj) : CallbackAdapter(), refs(1)
+{
+	controller = _controller;
+	obj = _obj;
+}
+
+JNICallbackAdapter::~JNICallbackAdapter()
+{
+}
+
+void JNICallbackAdapter::done(THREAD_CONTEXT threadContext)
+{
+	JNI_ENV(threadContext)->CallVoidMethod(obj,controller->done); 
+	return;
+}
+
+void JNICallbackAdapter::onError(THREAD_CONTEXT threadContext, long errorCode, std::string error)
+{
+	controller->log(threadContext, 0, "Libaio event generated errors, callback object was informed about it");
+	jstring strError = JNI_ENV(threadContext)->NewStringUTF(error.data());
+	JNI_ENV(threadContext)->CallVoidMethod(obj, controller->error, (jint)errorCode, strError);
+}
+
+void JNICallbackAdapter::destroy(THREAD_CONTEXT threadContext)
+{
+	JNI_ENV(threadContext)->DeleteGlobalRef(obj);
+}


Property changes on: trunk/native/src/JNICallbackAdapter.cpp
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/native/src/JNICallbackAdapter.h
===================================================================
--- trunk/native/src/JNICallbackAdapter.h	                        (rev 0)
+++ trunk/native/src/JNICallbackAdapter.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef JNIBUFFERADAPTER_H_
+#define JNIBUFFERADAPTER_H_
+
+#include <iostream>
+
+#include "CallbackAdapter.h"
+#include "AIOController.h"
+#include "JAIODatatypes.h"
+
+
+class JNICallbackAdapter : public CallbackAdapter
+{
+private:
+	AIOController * controller;
+	jobject obj;
+	int refs;
+    void destroy(THREAD_CONTEXT threadContext);
+	
+public:
+	// _ob must be a global Reference (use createGloblReferente before calling the constructor)
+	JNICallbackAdapter(AIOController * _controller, jobject _ob);
+	virtual ~JNICallbackAdapter();
+	void done(THREAD_CONTEXT threadContext);
+	void onError(THREAD_CONTEXT threadContext, long error, std::string error);
+	
+	void addref(THREAD_CONTEXT )
+	{
+		// As long as there is only one thread polling events, we are safe with this
+		refs++;
+	}
+	
+	void deleteRef(THREAD_CONTEXT threadContext)
+	{
+		// As long as there is only one thread polling events, we are safe with this
+		if (--refs <= 0)
+		{
+			destroy(threadContext);
+			delete this;
+		}
+	}
+	
+	
+};
+#endif /*JNIBUFFERADAPTER_H_*/

Added: trunk/native/src/JavaUtilities.cpp
===================================================================
--- trunk/native/src/JavaUtilities.cpp	                        (rev 0)
+++ trunk/native/src/JavaUtilities.cpp	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#include <stdio.h>
+#include <iostream>
+#include <string>
+#include "JavaUtilities.h"
+
+void throwException(JNIEnv * env,const char * clazz, const char * message)
+{
+  jclass exceptionClass = env->FindClass(clazz);
+  if (exceptionClass==NULL) 
+  {
+     exceptionClass = env->FindClass("java/lang/RuntimeException");
+     if (exceptionClass==NULL) 
+     {
+    	std::cerr << "Couldn't throw exception " << clazz << " message:= " << message << "\n";
+        return;
+     }
+  }
+  
+  env->ThrowNew(exceptionClass,message);
+  
+}
+
+std::string convertJavaString(JNIEnv * env, jstring& jstr)
+{
+	const char * valueStr = env->GetStringUTFChars(jstr, NULL);
+	std::string data(valueStr);
+	//data+=valueStr;
+	env->ReleaseStringUTFChars(jstr, valueStr);
+	return data;
+}
+


Property changes on: trunk/native/src/JavaUtilities.cpp
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/native/src/JavaUtilities.h
===================================================================
--- trunk/native/src/JavaUtilities.h	                        (rev 0)
+++ trunk/native/src/JavaUtilities.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,28 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#ifndef JAVAUTILITIES_H_
+#define JAVAUTILITIES_H_
+#include <string>
+#include <jni.h>
+
+void throwException(JNIEnv * env,const char * clazz, const char * message);
+std::string convertJavaString(JNIEnv * env, jstring& jstr);
+
+#endif /*JAVAUTILITIES_H_*/

Added: trunk/native/src/LibAIOController.cpp
===================================================================
--- trunk/native/src/LibAIOController.cpp	                        (rev 0)
+++ trunk/native/src/LibAIOController.cpp	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,187 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+    
+    Software written by Clebert Suconic (csuconic at redhat dot com)
+*/
+
+#include <jni.h>
+#include <stdlib.h>
+#include <iostream>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string>
+
+
+#include "org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO.h"
+
+
+#include "JavaUtilities.h"
+#include "AIOController.h"
+#include "JNICallbackAdapter.h"
+#include "AIOException.h"
+
+/*
+ * Class:     org_jboss_jaio_libaioimpl_LibAIOController
+ * Method:    init
+ * Signature: (Ljava/lang/String;Ljava/lang/Class;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_init
+  (JNIEnv * env, jclass, jstring jstrFileName, jclass callbackClass, jint maxIO, jobject logger)
+{
+	try
+	{
+		std::string fileName = convertJavaString(env, jstrFileName);
+		
+		AIOController * controller = new AIOController(fileName, (int) maxIO);
+		controller->done = env->GetMethodID(callbackClass,"done","()V");
+		if (!controller->done) return 0;
+		
+		controller->error = env->GetMethodID(callbackClass, "onError", "(ILjava/lang/String;)V");
+        if (!controller->error) return 0;
+        
+        jclass loggerClass = env->GetObjectClass(logger);
+        
+        if (!(controller->loggerDebug = env->GetMethodID(loggerClass, "debug", "(Ljava/lang/Object;)V"))) return 0;
+        if (!(controller->loggerWarn = env->GetMethodID(loggerClass, "warn", "(Ljava/lang/Object;)V"))) return 0;
+        if (!(controller->loggerInfo = env->GetMethodID(loggerClass, "info", "(Ljava/lang/Object;)V"))) return 0;
+        if (!(controller->loggerError = env->GetMethodID(loggerClass, "error", "(Ljava/lang/Object;)V"))) return 0;
+        
+        controller->logger = env->NewGlobalRef(logger);
+        
+        controller->log(env,4, "Controller initialized");
+		
+	    return (jlong)controller;
+	}
+	catch (AIOException& e){
+		throwException(env, "java/lang/RuntimeException", e.what());
+		return 0;
+	}
+}
+
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_read
+  (JNIEnv *env, jclass, jlong controllerAddress, jlong position, jlong size, jobject jbuffer, jobject callback)
+{
+	try 
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		void * buffer = env->GetDirectBufferAddress(jbuffer);
+		CallbackAdapter * adapter = new JNICallbackAdapter(controller, env->NewGlobalRef(callback));
+		
+		controller->fileOutput.read(env, position, (size_t)size, buffer, adapter);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}
+
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_write
+  (JNIEnv *env, jclass, jlong controllerAddress, jlong position, jlong size, jobject jbuffer, jobject callback)
+{
+	try 
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		void * buffer = env->GetDirectBufferAddress(jbuffer);
+		CallbackAdapter * adapter = new JNICallbackAdapter(controller, env->NewGlobalRef(callback));
+		
+		controller->fileOutput.write(env, position, (size_t)size, buffer, adapter);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}
+
+
+
+JNIEXPORT void Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_internalPollEvents
+  (JNIEnv *env, jclass, jlong controllerAddress)
+{
+	try
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		controller->fileOutput.pollEvents(env);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}
+
+JNIEXPORT jobject JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_newBuffer
+  (JNIEnv * env, jobject, jlong size)
+{
+	try
+	{
+		
+		if (size % ALIGNMENT)
+		{
+			throwException(env, "java/lang/RuntimeException", "Buffer size needs to be aligned to 512");
+			return 0;
+		}
+		
+		void * buffer = 0;
+		if (::posix_memalign(&buffer, 512, size))
+		{
+			throw AIOException(10, "Error on posix_memalign");
+		}
+		return env->NewDirectByteBuffer(buffer, size);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+		return 0;
+	}
+}
+
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_destroyBuffer
+  (JNIEnv * env, jobject, jobject jbuffer)
+{
+	void *  buffer = env->GetDirectBufferAddress(jbuffer);
+	free(buffer);
+}
+
+
+
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_closeInternal
+  (JNIEnv *env, jclass, jlong controllerAddress)
+{
+	try
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		controller->fileOutput.stopPoller(env);
+		controller->destroy(env);
+		delete controller;
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}
+
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_preAllocate
+  (JNIEnv * env, jclass, jlong controllerAddress, jint blocks, jlong size)
+{
+	try
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		controller->fileOutput.preAllocate(env, blocks, size);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}


Property changes on: trunk/native/src/LibAIOController.cpp
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/native/src/LockClass.h
===================================================================
--- trunk/native/src/LockClass.h	                        (rev 0)
+++ trunk/native/src/LockClass.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2008 Red Hat Software - JBoss Middleware Division
+
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+    The GNU Lesser General Public License is available in the file COPYING.
+
+*/
+
+#ifndef LOCKCLASS_H_
+#define LOCKCLASS_H_
+
+#include <pthread.h>
+
+class LockClass
+{
+protected:
+    pthread_mutex_t* _m;
+public:
+    inline LockClass(pthread_mutex_t* m) : _m(m)
+    {
+        ::pthread_mutex_lock(_m);
+    }
+    inline ~LockClass()
+    {
+        ::pthread_mutex_unlock(_m);
+    }
+};
+
+
+#endif /*LOCKCLASS_H_*/

Added: trunk/native/src/Makefile.am
===================================================================
--- trunk/native/src/Makefile.am	                        (rev 0)
+++ trunk/native/src/Makefile.am	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,7 @@
+#AM_CXXFLAGS = $(JVM_CXXFLAGS)
+lib_LTLIBRARIES = libJLibAIO.la
+
+libJLibAIO_la_SOURCES = AIOController.cpp AIOController.h AIOException.h AsyncFile.cpp \
+                     AsyncFile.h CallbackAdapter.h JAIODatatypes.h JavaUtilities.cpp \
+                     JavaUtilities.h JNICallbackAdapter.cpp JNICallbackAdapter.h LibAIOController.cpp \
+                     LockClass.h org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO

Added: trunk/native/src/org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO.h
===================================================================
--- trunk/native/src/org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO.h	                        (rev 0)
+++ trunk/native/src/org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO.h	2008-02-27 14:37:11 UTC (rev 3818)
@@ -0,0 +1,79 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO */
+
+#ifndef _Included_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+#define _Included_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Inaccessible static: log */
+/* Inaccessible static: loaded */
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    init
+ * Signature: (Ljava/lang/String;Ljava/lang/Class;ILorg/jboss/messaging/core/logging/Logger;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_init
+  (JNIEnv *, jclass, jstring, jclass, jint, jobject);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    write
+ * Signature: (JJJLjava/nio/ByteBuffer;Lorg/jboss/messaging/core/persistence/impl/libaio/jni/api/AIOCallback;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_write
+  (JNIEnv *, jclass, jlong, jlong, jlong, jobject, jobject);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    read
+ * Signature: (JJJLjava/nio/ByteBuffer;Lorg/jboss/messaging/core/persistence/impl/libaio/jni/api/AIOCallback;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_read
+  (JNIEnv *, jclass, jlong, jlong, jlong, jobject, jobject);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    preAllocate
+ * Signature: (JIJ)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_preAllocate
+  (JNIEnv *, jclass, jlong, jint, jlong);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    closeInternal
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_closeInternal
+  (JNIEnv *, jclass, jlong);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    internalPollEvents
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_internalPollEvents
+  (JNIEnv *, jclass, jlong);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    destroyBuffer
+ * Signature: (Ljava/nio/ByteBuffer;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_destroyBuffer
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO
+ * Method:    newBuffer
+ * Signature: (J)Ljava/nio/ByteBuffer;
+ */
+JNIEXPORT jobject JNICALL Java_org_jboss_messaging_core_persistence_impl_libaio_jni_impl_JlibAIO_newBuffer
+  (JNIEnv *, jobject, jlong);
+
+#ifdef __cplusplus
+}
+#endif
+#endif




More information about the jboss-cvs-commits mailing list