commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r806274 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Mutex.java native/shared/mutex.c
Date Thu, 20 Aug 2009 17:46:22 GMT
Author: mturk
Date: Thu Aug 20 17:46:22 2009
New Revision: 806274

URL: http://svn.apache.org/viewvc?rev=806274&view=rev
Log:
Initial Mutex Java API

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
    commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java?rev=806274&r1=806273&r2=806274&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java Thu
Aug 20 17:46:22 2009
@@ -17,6 +17,8 @@
 
 import java.io.IOException;
 import org.apache.commons.runtime.io.File;
+import org.apache.commons.runtime.io.Status;
+import org.apache.commons.runtime.exception.ClosedDescriptorException;
 import org.apache.commons.runtime.exception.OperatingSystemException;
 import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
 
@@ -45,5 +47,128 @@
         this.mutex = mutex;
     }
 
+    private static native Mutex create0()
+        throws IOException, SecurityException, OutOfMemoryError;
+    /**
+     * Create and make accessable anonymous {@code Mutex} object.
+     * <p>
+     * A note about Anonymous vs. Named mutex objects:<br />
+     *         Not all plaforms support anonymous mutexess, but in
+     *         some cases it is prefered over other types of mutex
+     *         implementations. If such a system is not available,
+     *         {@code UnsupportedOperatingSystemException} is thrown.
+     * </p>
+     */
+    public static Mutex create()
+        throws IOException, SecurityException, OutOfMemoryError
+    {
+        return create0();
+    }
+
+    private static native Mutex create1(String name)
+        throws IOException, SecurityException, OutOfMemoryError;
+    /**
+     * Create and make accessable named {@code Mutex} object.
+     * <p>
+     * A note about Anonymous vs. Named mutex objects:<br />
+     *         Not all plaforms support anonymous mutexs, but in
+     *         some cases it is prefered over other types of mutex
+     *         implementations. If such a system is not available,
+     *         {@code UnsupportedOperatingSystemException} is thrown.
+     * </p>
+     * @param file The abstract file path to use for mutex on platforms
+     *             that require it.
+     */
+    public static Mutex create(File file)
+        throws IOException, SecurityException, OutOfMemoryError
+    {
+        return create1(file.getPath());
+    }
+
+    private static native Mutex create2(String name)
+        throws IOException, SecurityException, OutOfMemoryError;
+    /**
+     * Open a mutex that was created by another process.
+     * @param file The abstract file path that was used to create a
+     *             mutex.
+     */
+    public static Mutex open(File file)
+        throws IOException, SecurityException, OutOfMemoryError,
+               UnsupportedOperatingSystemException
+    {
+        Mutex mutex = create2(file.getPath());
+        if (mutex == null)
+            throw new UnsupportedOperatingSystemException();
+        return mutex;
+    }
+
+    private static native int close0(Descriptor sem)
+        throws IOException, SecurityException;
+    /**
+     * Close and remove the {@code this} Mutex object from the system.
+     */
+    public void close()
+        throws IOException, SecurityException, ClosedDescriptorException
+    {
+        if (mutex.valid()) {
+            close0(mutex);
+        }
+        else {
+            throw new ClosedDescriptorException();
+        }
+    }
+
+    public static native void lock0(Descriptor sem)
+        throws IOException, SecurityException;
+    /**
+     * Acquire the lock for {@code this} Mutex.
+     * If the Mutex is already locked,
+     * the current thread will be put to sleep until the lock becomes available.
+     */
+    public void lock()
+        throws IOException, SecurityException, ClosedDescriptorException
+    {
+        if (mutex.valid()) {
+            lock0(mutex);
+        }
+        else {
+            throw new ClosedDescriptorException();
+        }
+    }
+
+    public static native boolean lock1(Descriptor sem)
+        throws IOException, SecurityException;
+    /**
+     * Attempt to acquire the lock for {@code this} Mutex.
+     * If the mutex has already
+     * been acquired, the call returns immediately with {@code false}.
+     */
+    public boolean tryLock()
+        throws IOException, SecurityException, ClosedDescriptorException
+    {
+        if (mutex.valid()) {
+            return lock1(mutex);
+        }
+        else {
+            throw new ClosedDescriptorException();
+        }
+    }
+
+    public static native void release0(Descriptor sem)
+        throws IOException, SecurityException;
+    /**
+     * Release the lock for {@code this} Mutex.
+     */
+    public void release()
+        throws IOException, SecurityException, ClosedDescriptorException
+    {
+        if (mutex.valid()) {
+            release0(mutex);
+        }
+        else {
+            throw new ClosedDescriptorException();
+        }
+    }
+
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c?rev=806274&r1=806273&r2=806274&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/mutex.c Thu Aug 20 17:46:22 2009
@@ -24,8 +24,7 @@
 #include "acr_descriptor.h"
 #include "acr_procmutex.h"
 
-ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create0)(ACR_JNISTDARGS,
-                                                jint value)
+ACR_JNI_EXPORT_DECLARE(jobject, Mutex, create0)(ACR_JNISTDARGS)
 {
 
     jobject mtxo = NULL;



Mime
View raw message