[jboss-cvs] JBoss Messaging SVN: r3821 - in trunk/src/main/org/jboss/messaging/core: asyncio and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 27 10:43:29 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-02-27 10:43:29 -0500 (Wed, 27 Feb 2008)
New Revision: 3821

Added:
   trunk/src/main/org/jboss/messaging/core/asyncio/
   trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java
   trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
   trunk/src/main/org/jboss/messaging/core/asyncio/impl/
   trunk/src/main/org/jboss/messaging/core/asyncio/impl/JlibAIO.java
Log:
A little Java.. just to remember the old times :-)

Added: trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java	2008-02-27 15:43:29 UTC (rev 3821)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.messaging.core.asyncio;
+
+/**
+ * 
+ * @author clebert.suconic at jboss.com
+ *
+ */
+public interface AIOCallback
+{
+    /** Leave this method as soon as possible, or you would be blocking the whole notification thread */
+    void done();
+
+    /** Observation: The whole file will be probably failing if this happens. Like, if you delete the file, you will start to get errors for these operations*/
+    void onError(int errorCode, String errorMessage);
+}


Property changes on: trunk/src/main/org/jboss/messaging/core/asyncio/AIOCallback.java
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java	2008-02-27 15:43:29 UTC (rev 3821)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.messaging.core.asyncio;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * 
+ * @author clebert.suconic at jboss.com
+ *
+ */
+public interface AsynchronousFile
+{
+   
+   void close();
+   
+   /**
+    * 
+    * Note: If you are using a native Linux implementation, maxIO can't be higher than what's defined on /proc/sys/fs/aio-max-nr, or you would get an error 
+    * @param fileName
+    * @param maxIO The number of max concurrent asynchrnous IO operations. It has to be balanced between the size of your writes and the capacity of your disk.
+    */
+   void open(String fileName, int maxIO);
+
+   /** 
+    * Warning: This function will perform a synchronous IO, probably translating to a fstat call
+    * */
+   long size();
+   
+   void write(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage);
+   
+   void read(long position, long size, ByteBuffer directByteBuffer,  AIOCallback aioPackage);
+   
+   void preAllocate(int blocks, long size);
+
+   ByteBuffer newBuffer(long size);
+   
+   void destroyBuffer(ByteBuffer buffer);
+
+}


Property changes on: trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"

Added: trunk/src/main/org/jboss/messaging/core/asyncio/impl/JlibAIO.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/impl/JlibAIO.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/impl/JlibAIO.java	2008-02-27 15:43:29 UTC (rev 3821)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.messaging.core.asyncio.impl;
+
+import java.nio.ByteBuffer;
+
+import org.jboss.messaging.core.asyncio.AIOCallback;
+import org.jboss.messaging.core.asyncio.AsynchronousFile;
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * 
+ * @author clebert.suconic at jboss.com
+ * Warning: Case you refactor the name or the package of this class
+ *          You need to make sure you also rename the C++ native calls
+ */
+public class JlibAIO implements AsynchronousFile
+{
+    private static Logger log = Logger.getLogger(JlibAIO.class);
+    private boolean opened = false;
+    private String fileName;
+    private Thread poller;
+    private static boolean loaded = true;
+    
+    /**
+     *  Warning: Beware of the C++ pointer! It will bite you! :-)
+     */ 
+    private long handler;
+    
+    static
+    {
+        try
+        {
+            log.info("JLibAIO being loaded");
+            System.loadLibrary("JBMLibAIO");
+        }
+        catch (Throwable e)
+        {
+            log.error(e.getLocalizedMessage(), e);
+            loaded = false;
+        }
+    }
+    
+    public static boolean isLoaded()
+    {
+       return loaded;
+    }
+    
+    
+
+    
+    public void open(String fileName, int maxIO)
+    {
+        opened = true;
+        this.fileName=fileName;
+        handler = init (fileName, AIOCallback.class, maxIO, log);
+        startPoller();
+    }
+    
+    class PollerThread extends Thread
+    {
+        PollerThread ()
+        {
+            super("NativePoller for " + fileName);
+        }
+        public void run()
+        {
+            pollEvents();
+        }
+    }
+    
+    private void startPoller()
+    {
+        checkOpened();
+        poller = new PollerThread(); 
+        poller.start();
+    }
+    
+    public void close()
+    {
+        checkOpened();
+        opened = false;
+        closeInternal(handler);
+        handler = 0;
+    }
+    
+    
+    public void write(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage)
+    {
+        checkOpened();
+        write (handler, position, size, directByteBuffer, aioPackage);
+        
+    }
+
+    public void read(long position, long size, ByteBuffer directByteBuffer, AIOCallback aioPackage)
+    {
+        checkOpened();
+        read (handler, position, size, directByteBuffer, aioPackage);
+        
+    }
+
+    public long size()
+    {
+        checkOpened();
+        // TODO: wire this method to ftell
+        return 0;
+    }
+
+    public void preAllocate(int blocks, long size)
+    {
+        checkOpened();
+        preAllocate(handler, blocks, size);
+    }
+
+    private void pollEvents()
+    {
+        checkOpened();
+        internalPollEvents(handler);
+    }
+    
+    private void checkOpened() 
+    {
+        if (!opened)
+        {
+            throw new RuntimeException("File is not opened");
+        }
+    }
+    
+    /** 
+     * I'm sending aioPackageClazz here, as you could have multiple classLoaders with the same class, and I don't want the hassle of doing classLoading in the Native layer
+     */
+    @SuppressWarnings("unchecked")
+    private static native long init(String fileName, Class aioPackageClazz, int maxIO, Logger logger);
+    
+    private static native void write(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
+
+    private static native void read(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
+    
+    private static native void preAllocate(long handle, int blocks, long size);
+
+    private static native void closeInternal(long handler);
+    
+    /** Poll asynchrounous events from internal queues */
+    private static native void internalPollEvents(long handler);
+
+    // Should we make this method static?
+    public native void destroyBuffer(ByteBuffer buffer);
+
+    // Should we make this method static?
+    public native ByteBuffer newBuffer(long size);
+   
+    
+}


Property changes on: trunk/src/main/org/jboss/messaging/core/asyncio/impl/JlibAIO.java
___________________________________________________________________
Name: svn:keywords
   + "Id LastChangedDate Author Revision"




More information about the jboss-cvs-commits mailing list