[jboss-cvs] JBoss Messaging SVN: r3732 - in projects/jaio/trunk/jaio/java: lib and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 18 10:21:32 EST 2008
Author: clebert.suconic at jboss.com
Date: 2008-02-18 10:21:32 -0500 (Mon, 18 Feb 2008)
New Revision: 3732
Added:
projects/jaio/trunk/jaio/java/lib/
projects/jaio/trunk/jaio/java/lib/junit.jar
Modified:
projects/jaio/trunk/jaio/java/build.xml
projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOPackage.java
projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java
projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java
Log:
Event handling
Modified: projects/jaio/trunk/jaio/java/build.xml
===================================================================
--- projects/jaio/trunk/jaio/java/build.xml 2008-02-18 15:20:49 UTC (rev 3731)
+++ projects/jaio/trunk/jaio/java/build.xml 2008-02-18 15:21:32 UTC (rev 3732)
@@ -5,17 +5,33 @@
<property name="cppoutput" value="../native/src" >
</property>
+ <path id="thirdparty.classpath">
+ <fileset dir="./lib" includes="**/*.jar"/>
+ </path>
+
<path id="build.classpath">
<pathelement location="./output/classes"/>
+ <path refid="thirdparty.classpath"/>
</path>
+ <path id="test.classpath">
+ <pathelement location="./output/classes"/>
+ <pathelement location="./output/testclasses"/>
+ <path refid="thirdparty.classpath"/>
+ </path>
+
<target name="init">
<mkdir dir="./output/jni"/>
<mkdir dir="./output/classes"/>
+ <mkdir dir="./output/testclasses"/>
+ <mkdir dir="./output/tests"/>
+ <mkdir dir="./output/testresult"/>
</target>
<target name="compile" depends="init">
<javac srcdir="./src" destdir="output/classes" classpathref="build.classpath" />
+ <javac srcdir="./tests" destdir="output/testclasses" classpathref="test.classpath" />
+
<javah class="org.jboss.jaio.libaioimpl.LibAIOController" classpathref="build.classpath" destdir="./output/jni">
</javah>
<copy todir="${cppoutput}">
@@ -23,6 +39,21 @@
</copy>
</target>
+ <target name="tests" depends="compile" description="run tests">
+
+ <junit printsummary="yes" haltonfailure="yes" haltonerror="yes">
+ <classpath refid="test.classpath"/>
+ <formatter type="xml"/>
+ <batchtest todir="./output/testresult">
+ <formatter type="plain" usefile="${junit.formatter.usefile}"/>
+ <fileset dir="./output/testclasses">
+ <include name="**/TestController.class"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+
<target name="core" depends="compile">
</target>
Added: projects/jaio/trunk/jaio/java/lib/junit.jar
===================================================================
(Binary files differ)
Property changes on: projects/jaio/trunk/jaio/java/lib/junit.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOPackage.java
===================================================================
--- projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOPackage.java 2008-02-18 15:20:49 UTC (rev 3731)
+++ projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOPackage.java 2008-02-18 15:21:32 UTC (rev 3732)
@@ -18,6 +18,9 @@
void decode(int length, ByteBuffer buffer);
void done();
+
+ /** Observation: The whole journal 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);
}
Modified: projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java
===================================================================
--- projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java 2008-02-18 15:20:49 UTC (rev 3731)
+++ projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java 2008-02-18 15:21:32 UTC (rev 3732)
@@ -1,6 +1,6 @@
package org.jboss.jaio.libaioimpl;
-import java.nio.ByteBuffer;
+import java.util.LinkedList;
import org.jboss.jaio.api.AIOController;
import org.jboss.jaio.api.AIOPackage;
@@ -13,12 +13,15 @@
*/
public class LibAIOController implements AIOController
{
-
+ private boolean opened = false;
+ private Thread poller;
/**
* Warning: Beware of the C++ pointer! It will bite you! :-)
*/
private long handler;
+ Object lock = new Object();
+
static
{
try
@@ -36,16 +39,56 @@
public void open(String fileName)
{
+ opened = true;
handler = init (fileName, AIOPackage.class);
}
- public void open(String fileName, int pageSize)
+ static class PollerThread extends Thread
{
+ PollerThread (LibAIOController lib)
+ {
+ this.lib = lib;
+ }
+ LibAIOController lib;
+ public void run()
+ {
+ while (lib.opened)
+ {
+ try
+ {
+ System.out.println("poll");
+ Thread.sleep(500);
+ lib.pollEvents();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void startPoller()
+ {
+ if (handler == 0)
+ throw new RuntimeException("not opened");
+ poller = new PollerThread(this);
+ poller.start();
+ }
+
+ public void open(String fileName, int pageSize)
+ {
+ opened = true;
handler = init (fileName, pageSize, AIOPackage.class);
}
public void close()
{
+ if (poller!=null)
+ {
+ opened = false;
+ try {poller.join();} catch (Exception ignored){}
+ }
closeInternal(handler);
handler = 0;
}
@@ -53,8 +96,12 @@
public void append(AIOPackage aioPackage)
{
- append(handler, aioPackage);
+ synchronized (lock)
+ {
+ append(handler, aioPackage);
+ }
+
}
public void read(long position, AIOPackage aioPackage)
@@ -83,7 +130,10 @@
public void pollEvents()
{
- pollEvents(handler);
+ synchronized (lock)
+ {
+ internalPollEvents(handler);
+ }
}
public void validateLowRate()
@@ -102,8 +152,8 @@
private static native void closeInternal(long handler);
/** Poll asynchrounous events from internal queues */
- private static native void pollEvents(long handler);
-
+ private static native void internalPollEvents(long handler);
+
/** Poll asynchrounous events from internal queues */
private static native void validateLowRate(long handler);
}
Modified: projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java
===================================================================
--- projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java 2008-02-18 15:20:49 UTC (rev 3731)
+++ projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java 2008-02-18 15:21:32 UTC (rev 3732)
@@ -8,6 +8,8 @@
import org.jboss.jaio.api.AIOPackage;
import org.jboss.jaio.libaioimpl.LibAIOController;
+import sun.rmi.transport.LiveRef;
+
import junit.framework.TestCase;
public class TestController extends TestCase
@@ -26,14 +28,14 @@
file.delete();
}
- public void testOpen()throws Exception
+ public void aatestOpen()throws Exception
{
LibAIOController controller = new LibAIOController();
controller.open("/tmp/libaio.log");
controller.close();
}
- public void testAddData() throws Exception
+ public void aatestAddData() throws Exception
{
LibAIOController controller = new LibAIOController();
controller.open("/tmp/libaio.log", 1024*1024);
@@ -55,8 +57,8 @@
public void testDirectDataNoPage() throws Exception
{
- final int NUMBER_LINES = 2500;
- final int SIZE = 100*512;
+ final int NUMBER_LINES = 200;
+ final int SIZE = 512;
commonBuffer = new byte[SIZE];
for (int i=0; i< commonBuffer.length-1; i++)
@@ -66,7 +68,7 @@
commonBuffer[commonBuffer.length -1] = '\n';
CountDownLatch latchDone = new CountDownLatch(NUMBER_LINES);
- LibAIOController controller = new LibAIOController();
+ final LibAIOController controller = new LibAIOController();
controller.open("/tmp/libaio.log");
ArrayList<LocalAIO> list = new ArrayList<LocalAIO>();
@@ -78,13 +80,30 @@
long valueInitial = System.currentTimeMillis();
int counterFile=0;
+
+ System.out.println("Adding data");
+
for (LocalAIO tmp: list)
{
controller.append(tmp);
}
+
+ System.out.println("Data added " + (System.currentTimeMillis() - valueInitial));
+
+
+ new Thread()
+ {
+ public void run()
+ {
+ controller.pollEvents();
+ }
+ }.start();
+
+ //controller.pollEvents();
+ //controller.startPoller();
System.out.println("Finished append " + (System.currentTimeMillis() - valueInitial) + " received = " + LocalAIO.staticDone);
System.out.println("Flush now");
- controller.pollEvents();
+ System.out.println("Received " + LocalAIO.staticDone);
latchDone.await();
long timeTotal = System.currentTimeMillis() - valueInitial;
@@ -103,7 +122,7 @@
}
- public void testPage() throws Exception
+ public void aatestPage() throws Exception
{
LibAIOController controller = new LibAIOController();
controller.open("/tmp/libaio.log", 8);
@@ -153,10 +172,11 @@
public void done()
{
- if (latch != null)
+ System.out.println("done - " + staticDone);
+ /*if (latch != null)
{
latch.countDown();
- }
+ }*/
doneCalled = true;
timesDoneCalled++;
staticDone++;
@@ -185,6 +205,12 @@
encodeSizeCalled = true;
return size;
}
+
+ public void onError(int errorCode, String errorMessage)
+ {
+ System.out.println("Error - " + errorCode + " message=" + errorMessage);
+
+ }
}
}
More information about the jboss-cvs-commits
mailing list