commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r790467 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/include/ main/native/os/unix/ main/native/os/win32/ main/native/shared/ test/org/apache/commons/runtime/
Date Thu, 02 Jul 2009 06:10:41 GMT
Author: mturk
Date: Thu Jul  2 06:10:40 2009
New Revision: 790467

URL: http://svn.apache.org/viewvc?rev=790467&view=rev
Log:
Add Descriptor.flush() and rename isClosed to valid

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
Thu Jul  2 06:10:40 2009
@@ -17,6 +17,7 @@
 package org.apache.commons.runtime;
 
 import java.io.Closeable;
+import java.io.Flushable;
 import java.io.IOException;
 import java.io.SyncFailedException;
 
@@ -32,7 +33,7 @@
  * </p>
  * @since Runtime 1.0
  */
-public abstract class Descriptor implements Closeable {
+public abstract class Descriptor implements Closeable, Flushable {
 
     /* Last error operation.
      * Set by the native on error condition, but never cleared.
@@ -83,13 +84,15 @@
     }
 
     private native void close0()
-        throws IOException, InstantiationException;
+        throws IOException;
 
     private native void close1()
         throws Throwable;
 
     private native void sync0()
-        throws SyncFailedException, IOException, InstantiationException;
+        throws SyncFailedException, IOException;
+    private native void flush0()
+        throws SyncFailedException, IOException;
 
     private static native Descriptor nulld0();
 
@@ -124,32 +127,62 @@
      * </p>
      * @see java.io.Closeable#close()
      * @throws IOException if an I/O error occurs.
-     * @throws InstantiationException if native class loader was not initialized.
      */
+    @Override
     public final void close()
         throws IOException
     {
-        try {
-            close0();
-        } catch (InstantiationException ex) {
-            // Class is alreay uninitialized.
-            // TODO: We could rethrow IOException here.
-        }
+        close0();
     }
 
     /**
-     * Force the underlying object to synchonize any buffered data.
-     * @throws SyncFailedException when the object cannot be flushed.
+     * Force the underlying object to synchonize it's state with the storage
+     * device.
+     * <p>
+     * Sync does not necessarily syncronize it's meta data unless that metadata
+     * is needed in order to allow a subsequent data retrieval to be
+     * correctly handled. For example, changes to time of last  access and
+     * time of last modification do not not require flushing
+     * because they are not necessary for a subsequent data read to be
+     * handled correctly.  On the other hand, a change to the file size
+     * would require a metadata flush.
+     * </p>
+     * <p>
+     * The aim of {@code sync} is to reduce disk activity for applications
+     * that do not require all metadata to be synchronised with the disk.
+     * </p>
+     *
+     * @throws SyncFailedException when the object cannot be synced.
      * @throws IOException if an I/O error occurs.
-     * @throws InstantiationException if native class loader was not initialized.
      */
     public final void sync()
-        throws SyncFailedException, IOException, InstantiationException
+        throws SyncFailedException, IOException
     {
         sync0();
     }
 
     /**
+     * Flushed the underlying object by writing any buffered data.
+     * <p>
+     * {@code fsync()} transfers  all  modified in-core data of the object
+     * referred to by {@code this} Descriptor to the disk device
+     * (or other permanent storage device)  where  that  object resides.
+     * The call blocks until the device reports that the transfer has
+     * completed.  It also flushes  metadata information associated with
+     * {@code this} Descriptor.
+     * </p>
+     *
+     * @throws SyncFailedException when the object cannot be flushed.
+     * @throws IOException if an I/O error occurs.
+     */
+    @Override
+    public final void flush()
+        throws SyncFailedException, IOException
+    {
+        flush0();
+    }
+
+    /**
      * Error number of the last operation performed on this descriptor.
      *
      * @return {@code int} representation of error number.
@@ -209,10 +242,11 @@
     }
 
     /**
-     * Check if the underlying Operating system descriptor is closed.
-     * @return {@code true} if descriptor is closed {@code false} otherwise.
+     * Check if the underlying Operating system descriptor is valid.
+     * @return {@code true} if descriptor is valid and not closed
+     *         {@code false} otherwise.
      */
-    public abstract boolean isClosed();
+    public abstract boolean valid();
 
     /**
      * Get underlying Operating system descriptor.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
Thu Jul  2 06:10:40 2009
@@ -48,13 +48,13 @@
         return IHANDLE;
     }
 
-    public boolean isClosed()
+    public boolean valid()
     {
-        // true if both int is negative and pointer is NULL
+        // false if both int is negative and pointer is NULL
         if (IHANDLE < 0 && PHANDLE == 0)
-            return true;
-        else
             return false;
+        else
+            return true;
     }
 
     public boolean equals(Object other)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
Thu Jul  2 06:10:40 2009
@@ -48,13 +48,13 @@
         return IHANDLE;
     }
 
-    public boolean isClosed()
+    public boolean valid()
     {
         // true if both int is negative and pointer is NULL
         if (IHANDLE < 0 && PHANDLE == 0L)
-            return true;
-        else
             return false;
+        else
+            return true;
     }
 
     public boolean equals(Object other)

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_descriptor.h Thu Jul  2 06:10:40
2009
@@ -43,7 +43,8 @@
 
 typedef enum {
     ACR_DESC_CLOSE,
-    ACR_DESC_SYNC
+    ACR_DESC_SYNC,
+    ACR_DESC_FLUSH    
 } acr_descriptor_cb_type_e;
 
 typedef struct acr_descriptor_cb_t {
@@ -51,6 +52,7 @@
     void    *dp;    /* Pointer descriptor */
     void   **ctxp;  /* Context data pointer */
     jobject  data;  /* handler provided Java object */
+    jobject  thiz;  /* Pointer to 'this' Java object */
 } acr_descriptor_cb_t;
 
 /**

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c Thu Jul  2 06:10:40 2009
@@ -109,9 +109,6 @@
     acr_ioh_tab  = (acr_ioh *)calloc(sizeof(acr_ioh), __ioh_size);
     if (acr_ioh_tab) {
         acr_ioh_tab[acr_ioh_mask].h = INVALID_HANDLE_VALUE;
-        /* Allocate slots 0 ... 7 for system use.
-         */
-        __bitmap[0] = 0xFF;
     }
     else
         return errno;
@@ -122,6 +119,10 @@
         acr_ioh_tab = NULL;
         return rv;
     }
+    /* Allocate slots 0 ... 7 for system use.
+        */
+    __bitmap[0] = 0xFF;
+
     return 0;
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c Thu Jul  2 06:10:40 2009
@@ -85,9 +85,6 @@
     acr_ioh_tab  = (acr_ioh *)calloc(sizeof(acr_ioh), __ioh_size);
     if (acr_ioh_tab) {
         acr_ioh_tab[acr_ioh_mask].h = INVALID_HANDLE_VALUE;
-        /* Allocate slots 0 ... 7 for system use.
-         */
-        __bitmap[0] = 0xFF;
     }
     else
         return errno;
@@ -98,7 +95,11 @@
         acr_ioh_tab = NULL;
         return rv;
     }
+    /* Allocate slots 0 ... 7 for system use.
+        */
+    __bitmap[0] = 0xFF;
     InitializeCriticalSection(&ios_lock);
+
     return 0;
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Thu Jul  2 06:10:40
2009
@@ -150,6 +150,7 @@
     if (_clazzn.i && J4MID(0000)) {
         acr_descriptor_cb_t cb;
         acr_descriptor_handler_fn_t *handler;
+
         cb.di   = GET_IFIELD_I(0000, _O);
         cb.dp   = GET_IFIELD_V(0001, _O, void *);
         handler = GET_IFIELD_V(0002, _O, acr_descriptor_handler_fn_t *);
@@ -162,6 +163,8 @@
         }
         if (handler) {
             int rc;
+            cb.thiz = _O;
+            cb.data = GET_IFIELD_O(0005, _O);
             if ((rc = (*handler)(_E, _O, ACR_DESC_CLOSE, &cb))) {
                 /* Throw IOException with errno message */
                 ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
@@ -169,7 +172,7 @@
         }
     }
     else
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINSTANCE, 0);
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_EINIT);
 }
 
 ACR_JNI_EXPORT_DECLARE(void, Descriptor, close1)(ACR_JNISTDARGS)
@@ -177,6 +180,7 @@
     if (_clazzn.i && J4MID(0000)) {
         acr_descriptor_cb_t cb;
         acr_descriptor_handler_fn_t *handler;
+
         cb.di   = GET_IFIELD_I(0000, _O);
         cb.dp   = GET_IFIELD_V(0001, _O, void *);
         handler = GET_IFIELD_V(0002, _O, acr_descriptor_handler_fn_t *);
@@ -188,6 +192,8 @@
             SET_IFIELD_P(0001, _O, NULL);
         }
         if (handler) {
+            cb.thiz = _O;
+            cb.data = GET_IFIELD_O(0005, _O);
             (*handler)(_E, _O, ACR_DESC_CLOSE, &cb);
         }
     }
@@ -198,12 +204,15 @@
     if (_clazzn.i && J4MID(0000)) {
         acr_descriptor_cb_t cb;
         acr_descriptor_handler_fn_t *handler;
+
         cb.di   = GET_IFIELD_I(0000, _O);
         cb.dp   = GET_IFIELD_V(0001, _O, void *);
         handler = GET_IFIELD_V(0002, _O, acr_descriptor_handler_fn_t *);
 
         if (handler) {
             int rc;
+            cb.thiz = _O;
+            cb.data = GET_IFIELD_O(0005, _O);
             if ((rc = (*handler)(_E, _O, ACR_DESC_SYNC, &cb))) {
                 if (rc == ACR_EINVAL)
                     ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESYNC, 0);
@@ -213,7 +222,34 @@
         }
     }
     else
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINSTANCE, 0);
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_EINIT);
+
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Descriptor, flush0)(ACR_JNISTDARGS)
+{
+    if (_clazzn.i && J4MID(0000)) {
+        acr_descriptor_cb_t cb;
+        acr_descriptor_handler_fn_t *handler;
+
+        cb.di   = GET_IFIELD_I(0000, _O);
+        cb.dp   = GET_IFIELD_V(0001, _O, void *);
+        handler = GET_IFIELD_V(0002, _O, acr_descriptor_handler_fn_t *);
+
+        if (handler) {
+            int rc;
+            cb.thiz = _O;
+            cb.data = GET_IFIELD_O(0005, _O);
+            if ((rc = (*handler)(_E, _O, ACR_DESC_FLUSH, &cb))) {
+                if (rc == ACR_EINVAL)
+                    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESYNC, 0);
+                else
+                    ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
+            }
+        }
+    }
+    else
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_EINIT);
 
 }
 
@@ -278,6 +314,8 @@
         (*_E)->MonitorExit(_E, _O);
 
         if (handler) {
+            cb.thiz = _O;
+            cb.data = GET_IFIELD_O(0005, _O);
             return (*handler)(_E, _O, ACR_DESC_CLOSE, &cb);
         }
         else {

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=790467&r1=790466&r2=790467&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Thu
Jul  2 06:10:40 2009
@@ -360,7 +360,7 @@
     {
         Descriptor d = Descriptor.NULL;
         assertNotNull("Descriptor", d);
-        assertTrue("Closed", d.isClosed());
+        assertFalse("Closed", d.valid());
     }
 
     public void testDescriptorNullErrno()
@@ -368,7 +368,7 @@
     {
         Descriptor d = Descriptor.NULL;
         assertNotNull("Descriptor", d);
-        assertTrue("Closed", d.isClosed());
+        assertFalse("Closed", d.valid());
         assertEquals("Errno", Status.EBADF, d.errno());
     }
 
@@ -377,7 +377,7 @@
     {
         Descriptor d = test021(2303, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         d.close();
         d = null;
         System.gc();
@@ -391,9 +391,9 @@
     {
         Descriptor d = test021(2303, 0);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         d.close();
-        assertTrue("Closed", d.isClosed());
+        assertFalse("Closed", d.valid());
         d = null;
         System.gc();
         // This should be enough for a gc
@@ -406,9 +406,9 @@
     {
         Descriptor d = test021(-1, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         d.close();
-        assertTrue("Closed", d.isClosed());
+        assertFalse("Closed", d.valid());
         d = null;
         System.gc();
         // This should be enough for a gc
@@ -421,7 +421,7 @@
     {
         Descriptor d = test021(2303, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         d = null;
         System.gc();
         // This should be enough for a first invocation
@@ -434,7 +434,7 @@
     {
         Descriptor d = test021(2303, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         int r = test022(d);
         assertEquals("Result ", 0, r);
         int c = test022(d);
@@ -454,7 +454,7 @@
     {
         Descriptor d = test021(-1, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         int r = test023(d);
         assertEquals("Result ", 1, r);
         d.close();
@@ -474,7 +474,7 @@
     {
         Descriptor d = test021(2303, 0);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         int r = test024(d);
         assertEquals("Result ", 2303, r);
         d.close();
@@ -494,7 +494,7 @@
     {
         Descriptor d = test021(-1, 0xcafebabe);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         int r = test023(d);
         assertEquals("Result ", 1, r);
         int s = test025(d, 0xdeadbeef);
@@ -518,7 +518,7 @@
     {
         Descriptor d = test021(2303, 0);
         assertNotNull("Descriptor", d);
-        assertFalse("Closed", d.isClosed());
+        assertTrue("Valid", d.valid());
         int r = test024(d);
         assertEquals("Result ", 2303, r);
         int s = test026(d, 1964);
@@ -544,7 +544,7 @@
         assertNotNull("Descriptor", d);
         assertEquals("Size ", 8, d.length);
         for (int i = 0; i < 8; i++) {
-            assertFalse("Closed", d[i].isClosed());
+            assertTrue("Valid", d[i].valid());
             int r = test024(d[i]);
             assertEquals("Result ", i, r);
         }
@@ -561,7 +561,7 @@
         Descriptor d1 = test021(2303, 0);
         Descriptor d2 = test021(2303, 0);
         assertNotNull("Descriptor", d1);
-        assertFalse("Closed", d1.isClosed());
+        assertTrue("Valid", d1.valid());
         assertTrue("Equals other", d1.equals(d2));
         assertTrue("Equals self", d1.equals(d1));
         d1.close();



Mime
View raw message