[jboss-cvs] JBoss Messaging SVN: r3774 - in projects/jaio/trunk/jaio/native: src and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 22 20:12:39 EST 2008
Author: clebert.suconic at jboss.com
Date: 2008-02-22 20:12:38 -0500 (Fri, 22 Feb 2008)
New Revision: 3774
Added:
projects/jaio/trunk/jaio/native/src/AsyncFile.cpp
projects/jaio/trunk/jaio/native/src/AsyncFile.h
projects/jaio/trunk/jaio/native/src/CallbackAdapter.h
projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.cpp
projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.h
projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_JLibAIO.h
Removed:
projects/jaio/trunk/jaio/native/src/BufferAdapter.h
projects/jaio/trunk/jaio/native/src/DataManager.cpp
projects/jaio/trunk/jaio/native/src/DataManager.h
projects/jaio/trunk/jaio/native/src/FileOutput.cpp
projects/jaio/trunk/jaio/native/src/FileOutput.h
projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.cpp
projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.h
projects/jaio/trunk/jaio/native/src/PageManager.cpp
projects/jaio/trunk/jaio/native/src/PageManager.h
projects/jaio/trunk/jaio/native/src/PageObserver.h
projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_LibAIOController.h
Modified:
projects/jaio/trunk/jaio/native/README
projects/jaio/trunk/jaio/native/configure.ac
projects/jaio/trunk/jaio/native/src/AIOController.cpp
projects/jaio/trunk/jaio/native/src/AIOController.h
projects/jaio/trunk/jaio/native/src/JAIODatatypes.h
projects/jaio/trunk/jaio/native/src/LibAIOController.cpp
projects/jaio/trunk/jaio/native/src/Makefile.am
Log:
Tidy up on the API
Modified: projects/jaio/trunk/jaio/native/README
===================================================================
--- projects/jaio/trunk/jaio/native/README 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/README 2008-02-23 01:12:38 UTC (rev 3774)
@@ -2,22 +2,15 @@
- if queue is full, it needs to retry until it can find a slot
Todo on the API:
- - initialize with number of slots
- - newAlignedBuffer
- - destroyAlignedBuffer
+ - initialize with number of slots (ok)
+ - newAlignedBuffer (ok)
+ - destroyAlignedBuffer (ok)
- write (position, ByteBuffer, Callback)
- read (position, ByteBuffer, Callback)
- - setPosition (position); // This will have to block until everything is solved
- - Logging (callback in Java);
- maybe:
- - appendOnPosition(ByteBuffer, Callback);
- - readOnPosition(ByteBuffer, Callback);
- - configureAIO (numberOfSlots);
+ - Logging (callback in Java); (ok
-
-
Future versions:
- MemoryPaging
@@ -29,3 +22,4 @@
- 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
Modified: projects/jaio/trunk/jaio/native/configure.ac
===================================================================
--- projects/jaio/trunk/jaio/native/configure.ac 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/configure.ac 2008-02-23 01:12:38 UTC (rev 3774)
@@ -23,6 +23,7 @@
gl_COMPILER_FLAGS(-Werror)
+gl_COMPILER_FLAGS(-g)
gl_COMPILER_FLAGS(-pedantic)
gl_COMPILER_FLAGS(-Wall)
gl_COMPILER_FLAGS(-Wextra)
Modified: projects/jaio/trunk/jaio/native/src/AIOController.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/AIOController.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/AIOController.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -20,15 +20,11 @@
#include <string>
#include "AIOController.h"
-#include "FileOutput.h"
-#include "PageManager.h"
#include "JavaUtilities.h"
#include "JAIODatatypes.h"
AIOController::AIOController(std::string fileName, int maxIO) : logger(0), fileOutput(fileName, this, maxIO)
{
- manager = (DataManager *)&fileOutput;
- usingPaging = false;
}
void AIOController::log(THREAD_CONTEXT threadContext, short level, char * message)
Modified: projects/jaio/trunk/jaio/native/src/AIOController.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/AIOController.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/AIOController.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -23,17 +23,14 @@
#include <jni.h>
#include <string>
#include "JAIODatatypes.h"
-#include "FileOutput.h"
-#include "DataManager.h"
+#include "AsyncFile.h"
class AIOController
{
public:
- jmethodID encodeSize;
- jmethodID encode;
- jmethodID decode;
jmethodID done;
jmethodID error;
+
jobject logger;
jmethodID loggerError;
@@ -47,16 +44,10 @@
void log(THREAD_CONTEXT threadContext, short level, char * message);
int fileHandle;
- FileOutput fileOutput;
+ AsyncFile fileOutput;
- // It could be Paging or Direct File output
- DataManager * manager;
-
void destroy(THREAD_CONTEXT context);
-
- bool usingPaging;
-
AIOController(std::string fileName, int maxIO);
virtual ~AIOController();
};
Added: projects/jaio/trunk/jaio/native/src/AsyncFile.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/AsyncFile.cpp (rev 0)
+++ projects/jaio/trunk/jaio/native/src/AsyncFile.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -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;
+
+ 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;
+
+ // 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::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: projects/jaio/trunk/jaio/native/src/AsyncFile.cpp
___________________________________________________________________
Name: svn:keywords
+ "Id LastChangedDate Author Revision"
Added: projects/jaio/trunk/jaio/native/src/AsyncFile.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/AsyncFile.h (rev 0)
+++ projects/jaio/trunk/jaio/native/src/AsyncFile.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -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_*/
Deleted: projects/jaio/trunk/jaio/native/src/BufferAdapter.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/BufferAdapter.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/BufferAdapter.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,71 +0,0 @@
-/*
- 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 BufferAdapter
-{
-private:
- // The number of pages that are expected to be used by this Buffer
- int blocks;
-
- virtual void destroy(THREAD_CONTEXT threadContext) = 0;
-public:
- BufferAdapter() : blocks(1)
- {
-
- }
- virtual ~BufferAdapter()
- {
-
- }
-
- 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 encode(THREAD_CONTEXT threadContext, const int& size, void *) = 0;
- virtual void done(THREAD_CONTEXT threadContext) = 0;
- virtual int blockSize(THREAD_CONTEXT threadContext) = 0;
- virtual void onError(THREAD_CONTEXT threadContext, long error, std::string error)=0;
-};
-#endif /*BUFFERADAPTER_H_*/
Added: projects/jaio/trunk/jaio/native/src/CallbackAdapter.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/CallbackAdapter.h (rev 0)
+++ projects/jaio/trunk/jaio/native/src/CallbackAdapter.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -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_*/
Deleted: projects/jaio/trunk/jaio/native/src/DataManager.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/DataManager.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/DataManager.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,28 +0,0 @@
-/*
- 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 "DataManager.h"
-
-DataManager::DataManager()
-{
-}
-
-DataManager::~DataManager()
-{
-}
Deleted: projects/jaio/trunk/jaio/native/src/DataManager.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/DataManager.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/DataManager.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,35 +0,0 @@
-/*
- 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 DATAMANAGER_H_
-#define DATAMANAGER_H_
-
-#include "BufferAdapter.h"
-#include "JAIODatatypes.h"
-
-class DataManager
-{
-public:
- DataManager();
- virtual ~DataManager();
- virtual void addData(THREAD_CONTEXT threadContext, BufferAdapter * adapter) = 0;
- virtual void pollEvents(THREAD_CONTEXT threadContext) = 0;
-};
-
-#endif /*DATAMANAGER_H_*/
Deleted: projects/jaio/trunk/jaio/native/src/FileOutput.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/FileOutput.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/FileOutput.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,277 +0,0 @@
-/*
- 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 "FileOutput.h"
-#include "AIOController.h"
-#include "AIOException.h"
-#include "pthread.h"
-#include "LockClass.h"
-
-
-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();
-}
-
-
-FileOutput::FileOutput(std::string & _fileName, AIOController * _controller, int _maxIO) : aioContext(0), filePointer(0), events(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_WRONLY | O_CREAT | O_DIRECT, 0666);
- events = (struct io_event *)malloc (maxIO * sizeof (struct io_event));
-
- if (fileHandle < 0)
- {
- throw AIOException(1, "Can't open file");
- }
-
-}
-
-FileOutput::~FileOutput()
-{
- ::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 FileOutput::completePage(THREAD_CONTEXT threadContext, long size, void * page, std::list<BufferAdapter *> * adapters)
-{
- ::write(fileHandle, page, size);
- for (std::list<BufferAdapter *>::iterator iter = adapters->begin(); iter != adapters->end(); iter++)
- {
- (*iter)->completeBlock(threadContext);
- (*iter)->deleteRef(threadContext);
- }
-
- free (page);
- delete adapters;
-}
-
-void FileOutput::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);
-}
-
-
-void FileOutput::pollEvents(THREAD_CONTEXT threadContext)
-{
-
- LockClass lock(&pollerMutex);
- pollerRunning=1;
-
- 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;
-
- std::list<BufferAdapter *> * list = (std::list<BufferAdapter *> *)(iocbp->data);
-
- long result = events[i].res;
- if (result < 0)
- {
- std::string strerror = io_error(result);
- for (std::list<BufferAdapter *>::iterator iter = list->begin(); iter != list->end(); iter ++)
- {
- (*iter)->onError(threadContext, result, strerror);
- }
- }
- else
- {
- for (std::list<BufferAdapter *>::iterator iter = list->begin(); iter != list->end(); iter ++)
- {
- (*iter)->completeBlock(threadContext);
- (*iter)->deleteRef(threadContext);
- }
- }
-
- free(iocbp->u.c.buf);
- delete list;
- free(iocbp);
- }
- }
-
- controller->log(threadContext, 2, "Poller finished execution");
-
-}
-
-
-void FileOutput::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");
- filePointer=0;
- return;
- }
-
- if (size % 512 != 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);
-
- filePointer = 0;
-}
-
-// Used only when Paging is disabled (as the user have this option to opt out for Paging)
-void FileOutput::addData(THREAD_CONTEXT threadContext, BufferAdapter * adapter)
-{
-#ifdef TRACE
- fprintf (stderr,"Getting size\n"); fflush(stderr);
- fprintf (stderr,"ThreadContext:- %ld\n", (long)threadContext);
-#endif
-
- int size = adapter->blockSize(threadContext);
-#ifdef TRACE
- fprintf (stderr,"Got size\n"); fflush(stderr);
- fprintf (stderr,"Getting lock\n"); fflush(stderr);
-#endif
-
- LockClass * lock = new LockClass(&fileMutex);
-
-#ifdef TRACE
- fprintf (stderr,"Got lock\n"); fflush(stderr);
-#endif
-
- filePointer+=size;
-
-#ifdef TRACE
- fprintf (stderr,"Added Size\n"); fflush(stderr);
-#endif
-
- delete lock;
- lock = 0;
-
-#ifdef TRACE
- fprintf (stderr,"Deleted Lock\n"); fflush(stderr);
-#endif
-
- void * buffer = 0;
- //void * buffer = malloc(size + sizeof (BufferAdapter *));
- if (posix_memalign(&buffer, 512, size))
- {
- throw AIOException(10, "Error on posix_memalign");
- }
-
- std::list<BufferAdapter *> * list = new std::list<BufferAdapter *>();
- list->push_back(adapter);
-
- // call encode on JNI
- adapter->encode(threadContext, size, buffer);
-
- struct iocb * iocb = new struct iocb();
- ::io_prep_pwrite(iocb, fileHandle, buffer, size, filePointer);
- iocb->data = (void *) list;
-
- int result = ::io_submit(aioContext, 1, &iocb);
-
- if (result<0)
- {
- std::stringstream str;
- str<< "Problem on submit block, errorCode=" << result;
- throw AIOException (6, str.str());
- }
-}
-
Deleted: projects/jaio/trunk/jaio/native/src/FileOutput.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/FileOutput.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/FileOutput.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,71 +0,0 @@
-/*
- 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 "PageObserver.h"
-#include "DataManager.h"
-#include "JAIODatatypes.h"
-
-class AIOController;
-
-class FileOutput : public PageObserver, DataManager
-{
-private:
- io_context_t aioContext;
- off_t filePointer;
- struct io_event *events;
- int fileHandle;
- std::string fileName;
-
- pthread_mutex_t fileMutex;
- pthread_mutex_t pollerMutex;
-
- AIOController * controller;
-
- bool pollerRunning;
-
- int maxIO;
-
-public:
- FileOutput(std::string & _fileName, AIOController * controller, int maxIO);
- virtual ~FileOutput();
- void completePage(THREAD_CONTEXT threadContext, long size, void *, std::list<BufferAdapter *> *);
- void addData(THREAD_CONTEXT threadContext, BufferAdapter * adapter);
-
- int getHandle()
- {
- return fileHandle;
- }
-
-
- // 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_*/
Modified: projects/jaio/trunk/jaio/native/src/JAIODatatypes.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/JAIODatatypes.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/JAIODatatypes.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -24,6 +24,7 @@
#define THREAD_CONTEXT JNIEnv *&
#define JNI_ENV(pointer) pointer
+#define ALIGNMENT 512
#endif /*JAIODATATYPES_H_*/
Deleted: projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,63 +0,0 @@
-/*
- 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 "JNIBufferAdapter.h"
-#include <iostream>
-#include "JavaUtilities.h"
-
-JNIBufferAdapter::JNIBufferAdapter(AIOController * _controller, jobject _obj) : BufferAdapter(), refs(1)
-{
- controller = _controller;
- obj = _obj;
- //obj = _obj; // delete me
-}
-
-JNIBufferAdapter::~JNIBufferAdapter()
-{
-}
-
-void JNIBufferAdapter::encode(THREAD_CONTEXT threadContext, const int& size, void * bufferAddress)
-{
- jobject buffer = JNI_ENV(threadContext)->NewDirectByteBuffer(bufferAddress, size);
- JNI_ENV(threadContext)->CallVoidMethod(obj, controller->encode, buffer);
-}
-
-void JNIBufferAdapter::done(THREAD_CONTEXT threadContext)
-{
- JNI_ENV(threadContext)->CallVoidMethod(obj,controller->done);
- return;
-}
-
-int JNIBufferAdapter::blockSize(THREAD_CONTEXT threadContext)
-{
- return JNI_ENV(threadContext)->CallIntMethod(obj,controller->encodeSize);
-}
-
-void JNIBufferAdapter::onError(THREAD_CONTEXT threadContext, long errorCode, std::string error)
-{
- std::cout<< "Calling onError with errorCode " << errorCode << "\n";
- jstring strError = JNI_ENV(threadContext)->NewStringUTF(error.data());
- JNI_ENV(threadContext)->CallVoidMethod(obj, controller->error, (jint)errorCode, strError);
-}
-
-void JNIBufferAdapter::destroy(THREAD_CONTEXT threadContext)
-{
- JNI_ENV(threadContext)->DeleteGlobalRef(obj);
-}
Deleted: projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/JNIBufferAdapter.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,62 +0,0 @@
-/*
- 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 "BufferAdapter.h"
-#include "AIOController.h"
-#include "JAIODatatypes.h"
-
-
-class JNIBufferAdapter : public BufferAdapter
-{
-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)
- JNIBufferAdapter(AIOController * _controller, jobject _ob);
- virtual ~JNIBufferAdapter();
- void encode(THREAD_CONTEXT threadContext, const int& size, void *);
- void done(THREAD_CONTEXT threadContext);
- int blockSize(THREAD_CONTEXT threadContext);
- void onError(THREAD_CONTEXT threadContext, long error, std::string error);
- void addref(THREAD_CONTEXT )
- {
- refs++;
- }
-
- void deleteRef(THREAD_CONTEXT threadContext)
- {
- if (--refs <= 0)
- {
- destroy(threadContext);
- delete this;
- }
- }
-
-
-};
-#endif /*JNIBUFFERADAPTER_H_*/
Added: projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.cpp (rev 0)
+++ projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -0,0 +1,52 @@
+/*
+ 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;
+ //obj = _obj; // delete me
+}
+
+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: projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.cpp
___________________________________________________________________
Name: svn:keywords
+ "Id LastChangedDate Author Revision"
Added: projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.h (rev 0)
+++ projects/jaio/trunk/jaio/native/src/JNICallbackAdapter.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -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_*/
Modified: projects/jaio/trunk/jaio/native/src/LibAIOController.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/LibAIOController.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/LibAIOController.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -18,18 +18,19 @@
*/
#include <jni.h>
+#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <fcntl.h>
#include <string>
-#include "org_jboss_jaio_libaioimpl_LibAIOController.h"
+#include "org_jboss_jaio_libaioimpl_JLibAIO.h"
#include "JavaUtilities.h"
#include "AIOController.h"
-#include "JNIBufferAdapter.h"
+#include "JNICallbackAdapter.h"
#include "AIOException.h"
/*
@@ -37,7 +38,7 @@
* Method: init
* Signature: (Ljava/lang/String;Ljava/lang/Class;)J
*/
-JNIEXPORT jlong JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_init
+JNIEXPORT jlong JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_init
(JNIEnv * env, jclass, jstring jstrFileName, jclass callbackClass, jint maxIO, jobject logger)
{
try
@@ -48,15 +49,6 @@
controller->done = env->GetMethodID(callbackClass,"done","()V");
if (!controller->done) return 0;
- controller->encode = env->GetMethodID(callbackClass,"encode","(Ljava/nio/ByteBuffer;)V");
- if (!controller->encode) return 0;
-
- controller->decode = env->GetMethodID(callbackClass,"decode","(ILjava/nio/ByteBuffer;)V");
- if (!controller->decode) return 0;
-
- controller->encodeSize = env->GetMethodID(callbackClass,"encodeSize","()I");
- if (!controller->encodeSize) return 0;
-
controller->error = env->GetMethodID(callbackClass, "onError", "(ILjava/lang/String;)V");
if (!controller->error) return 0;
@@ -79,14 +71,16 @@
}
}
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_append
- (JNIEnv *env, jclass, jlong controllerAddress, jobject obj)
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_read
+ (JNIEnv *env, jclass, jlong controllerAddress, jlong position, jlong size, jobject jbuffer, jobject callback)
{
try
{
AIOController * controller = (AIOController *) controllerAddress;
- JNIBufferAdapter * adapter = new JNIBufferAdapter(controller, env->NewGlobalRef(obj));
- controller->manager->addData(env, adapter);
+ 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)
{
@@ -94,15 +88,32 @@
}
}
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_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_jaio_libaioimpl_LibAIOController_internalPollEvents
+
+JNIEXPORT void Java_org_jboss_jaio_libaioimpl_JLibAIO_internalPollEvents
(JNIEnv *env, jclass, jlong controllerAddress)
{
try
{
AIOController * controller = (AIOController *) controllerAddress;
- controller->manager->pollEvents(env);
+ controller->fileOutput.pollEvents(env);
}
catch (AIOException& e)
{
@@ -110,9 +121,42 @@
}
}
+JNIEXPORT jobject JNICALL Java_org_jboss_jaio_libaioimpl_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_jaio_libaioimpl_JLibAIO_destroyBuffer
+ (JNIEnv * env, jobject, jobject jbuffer)
+{
+ void * buffer = env->GetDirectBufferAddress(jbuffer);
+ free(buffer);
+}
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_closeInternal
+
+
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_closeInternal
(JNIEnv *env, jclass, jlong controllerAddress)
{
try
@@ -128,7 +172,7 @@
}
}
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_preAllocate
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_preAllocate
(JNIEnv * env, jclass, jlong controllerAddress, jint blocks, jlong size)
{
try
Modified: projects/jaio/trunk/jaio/native/src/Makefile.am
===================================================================
--- projects/jaio/trunk/jaio/native/src/Makefile.am 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/Makefile.am 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,11 +1,10 @@
#AM_CXXFLAGS = $(JVM_CXXFLAGS)
-lib_LTLIBRARIES = libJaio.la
+lib_LTLIBRARIES = libJLibAIO.la
-libJaio_la_SOURCES = LibAIOController.cpp AIOController.cpp JavaUtilities.h PageManager.cpp AIOController.h \
- JNIBufferAdapter.cpp PageManager.h BufferAdapter.h JNIBufferAdapter.h \
- JavaUtilities.cpp org_jboss_jaio_libaioimpl_LibAIOController.h \
- PageObserver.h FileOutput.h FileOutput.cpp \
- DataManager.cpp DataManager.h AIOException.h JAIODatatypes.h
-#libJaio_la_SOURCES = LibAIOController.cpp AIOController.cpp
+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_jaio_libaioimpl_JLibAIO.h
+
Deleted: projects/jaio/trunk/jaio/native/src/PageManager.cpp
===================================================================
--- projects/jaio/trunk/jaio/native/src/PageManager.cpp 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/PageManager.cpp 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,120 +0,0 @@
-/*
- 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 <sstream>
-
-#include "BufferAdapter.h"
-#include "PageManager.h"
-#include "pthread.h"
-#include "LockClass.h"
-
-#include "AIOException.h"
-
-PageManager::PageManager(int _pageSize, PageObserver * _observer)
-{
- pageSize = _pageSize;
- observer = _observer;
- initMemory();
- ::pthread_mutex_init(&pageMutex,0);
-}
-
-PageManager::~PageManager()
-{
- ::pthread_mutex_destroy(&pageMutex);
- free(memoryArea);
-}
-
-void PageManager::destroy(THREAD_CONTEXT threadContext)
-{
- for (std::list<BufferAdapter *>::iterator iter = list->begin(); iter != list->end(); iter ++)
- {
- (*iter)->deleteRef(threadContext);
- }
- delete list;
-}
-
-
-void PageManager::addData(THREAD_CONTEXT threadContext, BufferAdapter * adapter)
-{
-
- long size = adapter->blockSize(threadContext);
-
- LockClass lock(&pageMutex);
-
- if (pagePosition + size > pageSize)
- {
- int bytesToPage = pageSize - pagePosition;
-
- char * mem = (char *)malloc(size);
- memset(mem, 0, size);
- adapter->encode(threadContext, size, mem);
- long local = 0;
-
- adapter->setBlocks(((size - bytesToPage) / pageSize) + 1);
-
- while (size - local > 0)
- {
- adapter->addref(threadContext);
- long toBeCompleted = pageSize - pagePosition;
- long minValue = size-local > toBeCompleted ? toBeCompleted : size-local;
- memcpy(memoryArea + pagePosition, mem + local, minValue);
- pagePosition += toBeCompleted;
- list->push_back(adapter);
- if (pagePosition >= pageSize)
- {
- flushMemory(threadContext);
- local+=toBeCompleted;
- }
- }
-
-
- adapter->deleteRef(threadContext);
-
- free(mem);
- }
- else
- {
- list->push_back(adapter);
-
- adapter->encode (threadContext, size, memoryArea + pagePosition);
-
- pagePosition += size;
- }
-}
-
-void PageManager::initMemory()
-{
- memoryArea = (char *)malloc(pageSize);
- memset(memoryArea, 0, pageSize);
- list = new std::list<BufferAdapter *>();
- pagePosition = 0;
-}
-
-void PageManager::flushMemory(THREAD_CONTEXT threadContext)
-{
- observer->completePage(threadContext, pagePosition, memoryArea, list);
- initMemory();
-}
-
-void PageManager::pollEvents(THREAD_CONTEXT)
-{
- //observer->completePage(pagePosition, memoryArea, list);
- //initMemory();
- throw AIOException (100, "Not implemented");
-}
Deleted: projects/jaio/trunk/jaio/native/src/PageManager.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/PageManager.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/PageManager.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,65 +0,0 @@
-/*
- 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 PAGEMANAGER_H_
-#define PAGEMANAGER_H_
-
-#include "pthread.h"
-
-#include "BufferAdapter.h"
-#include "PageObserver.h"
-#include "DataManager.h"
-#include "JAIODatatypes.h"
-
-#include <list>
-
-
-class PageManager : public DataManager
-{
-private:
- int pageSize;
- int pagePosition;
- std::list<BufferAdapter *> * list;
- char * memoryArea;
-
- PageObserver * observer;
-
- pthread_mutex_t pageMutex;
-
- void initMemory();
-
-public:
- PageManager(int pageSize, PageObserver * observer);
- virtual ~PageManager();
- void addData(THREAD_CONTEXT threadContext, BufferAdapter* adapter);
-
- void pollEvents(THREAD_CONTEXT threadContext);
-
- void destroy(THREAD_CONTEXT threadContext);
-
- void validateLowRate(THREAD_CONTEXT)
- {
- }
-
- void flushMemory(THREAD_CONTEXT context);
-
-
-};
-
-#endif /*PAGEMANAGER_H_*/
Deleted: projects/jaio/trunk/jaio/native/src/PageObserver.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/PageObserver.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/PageObserver.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,46 +0,0 @@
-/*
- 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 PAGEOBSERVER_H_
-#define PAGEOBSERVER_H_
-
-#include <list>
-#include "BufferAdapter.h"
-#include "JAIODatatypes.h"
-
-/**
- * This is probably going to be the file itself
- */
-class PageObserver
-{
-public:
- PageObserver()
- {
-
- }
-
- virtual ~PageObserver()
- {
- }
-
- // Implementations of PageObserver should also delete the list, and delete each element of BufferAdapter calling BufferAdapter::killYourslef()
- virtual void completePage(THREAD_CONTEXT threadContext, long size, void *, std::list<BufferAdapter *> *)=0;
-};
-
-#endif /*PAGEOBSERVER_H_*/
Added: projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_JLibAIO.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_JLibAIO.h (rev 0)
+++ projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_JLibAIO.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -0,0 +1,78 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_jboss_jaio_libaioimpl_JLibAIO */
+
+#ifndef _Included_org_jboss_jaio_libaioimpl_JLibAIO
+#define _Included_org_jboss_jaio_libaioimpl_JLibAIO
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Inaccessible static: log */
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: init
+ * Signature: (Ljava/lang/String;Ljava/lang/Class;ILorg/jboss/jaio/api/logging/Logger;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_init
+ (JNIEnv *, jclass, jstring, jclass, jint, jobject);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: write
+ * Signature: (JJJLjava/nio/ByteBuffer;Lorg/jboss/jaio/api/AIOCallback;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_write
+ (JNIEnv *, jclass, jlong, jlong, jlong, jobject, jobject);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: read
+ * Signature: (JJJLjava/nio/ByteBuffer;Lorg/jboss/jaio/api/AIOCallback;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_read
+ (JNIEnv *, jclass, jlong, jlong, jlong, jobject, jobject);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: preAllocate
+ * Signature: (JIJ)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_preAllocate
+ (JNIEnv *, jclass, jlong, jint, jlong);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: closeInternal
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_closeInternal
+ (JNIEnv *, jclass, jlong);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: internalPollEvents
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_internalPollEvents
+ (JNIEnv *, jclass, jlong);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: destroyBuffer
+ * Signature: (Ljava/nio/ByteBuffer;)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_destroyBuffer
+ (JNIEnv *, jobject, jobject);
+
+/*
+ * Class: org_jboss_jaio_libaioimpl_JLibAIO
+ * Method: newBuffer
+ * Signature: (J)Ljava/nio/ByteBuffer;
+ */
+JNIEXPORT jobject JNICALL Java_org_jboss_jaio_libaioimpl_JLibAIO_newBuffer
+ (JNIEnv *, jobject, jlong);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
Deleted: projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_LibAIOController.h
===================================================================
--- projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_LibAIOController.h 2008-02-22 17:56:42 UTC (rev 3773)
+++ projects/jaio/trunk/jaio/native/src/org_jboss_jaio_libaioimpl_LibAIOController.h 2008-02-23 01:12:38 UTC (rev 3774)
@@ -1,54 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class org_jboss_jaio_libaioimpl_LibAIOController */
-
-#ifndef _Included_org_jboss_jaio_libaioimpl_LibAIOController
-#define _Included_org_jboss_jaio_libaioimpl_LibAIOController
-#ifdef __cplusplus
-extern "C" {
-#endif
-/* Inaccessible static: log */
-/*
- * Class: org_jboss_jaio_libaioimpl_LibAIOController
- * Method: init
- * Signature: (Ljava/lang/String;Ljava/lang/Class;ILorg/jboss/jaio/api/logging/Logger;)J
- */
-JNIEXPORT jlong JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_init
- (JNIEnv *, jclass, jstring, jclass, jint, jobject);
-
-/*
- * Class: org_jboss_jaio_libaioimpl_LibAIOController
- * Method: append
- * Signature: (JLorg/jboss/jaio/api/AIOPackage;)V
- */
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_append
- (JNIEnv *, jclass, jlong, jobject);
-
-/*
- * Class: org_jboss_jaio_libaioimpl_LibAIOController
- * Method: preAllocate
- * Signature: (JIJ)V
- */
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_preAllocate
- (JNIEnv *, jclass, jlong, jint, jlong);
-
-/*
- * Class: org_jboss_jaio_libaioimpl_LibAIOController
- * Method: closeInternal
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_closeInternal
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_jboss_jaio_libaioimpl_LibAIOController
- * Method: internalPollEvents
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_org_jboss_jaio_libaioimpl_LibAIOController_internalPollEvents
- (JNIEnv *, jclass, jlong);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
More information about the jboss-cvs-commits
mailing list