commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1091827 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java native/include/acr/error.h native/os/unix/semaphore.c native/shared/error.c
Date Wed, 13 Apr 2011 15:40:08 GMT
Author: mturk
Date: Wed Apr 13 15:40:08 2011
New Revision: 1091827

URL: http://svn.apache.org/viewvc?rev=1091827&view=rev
Log:
Implement native part of posix semaphore

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java?rev=1091827&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java
Wed Apr 13 15:40:08 2011
@@ -0,0 +1,39 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.exception;
+
+/**
+ * ObjectAlreadyExistsException thrown when an attempt is made to
+ * invoke an operation on already existing operating system {@code object}.
+ * This class mimics the os {@code EEXIST} error.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ObjectAlreadyExistsException extends RuntimeException
+{
+
+    public ObjectAlreadyExistsException()
+    {
+        super();
+    }
+
+    public ObjectAlreadyExistsException(String msg)
+    {
+        super(msg);
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ObjectAlreadyExistsException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1091827&r1=1091826&r2=1091827&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Wed Apr 13 15:40:08
2011
@@ -40,6 +40,7 @@ enum {
     ACR_EX_ERUNTIME,        /* java/lang/RuntimeException */
     ACR_EX_ENOMEM,          /* java/lang/OutOfMemoryError */
     ACR_EX_ENULL,           /* java/lang/NullPointerException */
+    ACR_EX_EACCES,          /* java/lang/IllegalAccessException */
     ACR_EX_EINVAL,          /* java/lang/IllegalArgumentException */
     ACR_EX_EISTATE,         /* java/lang/IllegalStateException */
     ACR_EX_EINDEX,          /* java/lang/IndexOutOfBoundsException */
@@ -56,6 +57,7 @@ enum {
     ACR_EX_ESYNC,           /* java/io/SyncFailedException */
     ACR_EX_ESOCK,           /* java/net/SocketException */
     ACR_EX_ENOENT,          /* exception/NoSuchObjectException */
+    ACR_EX_EEXIST,          /* exception/ObjectAlreadyExistsException */
     ACR_EX_OSERR,           /* exception/OperatingSystemException */
     ACR_EX_ETIMEOUT,        /* exception/TimeoutException */
     ACR_EX_UNSUPPORTED,     /* exception/UnsupportedOperatingSystemException */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c?rev=1091827&r1=1091826&r2=1091827&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c Wed Apr 13 15:40:08
2011
@@ -47,10 +47,12 @@ J_DECLARE_M_ID(0000) = {
     "()V"
 };
 
-static int _init_factory(JNI_STDENV)
+static int _load_factory(JNI_STDENV)
 {
     int rv;
 
+    if (_clazzn.u == 1)
+        return 0;
     if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
         return rv;
     J_LOAD_METHOD(0000);
@@ -60,9 +62,125 @@ static int _init_factory(JNI_STDENV)
 
 ACR_JNI_EXPORT(jobject, Semaphore, getImplFactory)(JNI_STDARGS)
 {
-    if (_init_factory(env) != 0) {
+    if (_load_factory(env) != 0) {
         ACR_THROW_MSG(ACR_EX_EINSTANCE, "PosixSemaphoreImplFactory not initialized");
         return 0;
     }
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
 }
+
+ACR_JNI_EXPORT(void, PosixSemaphore, unlink0)(JNI_STDARGS, jstring name)
+{
+    WITH_CSTR(name) {
+        sem_unlink(J2S(name));        
+    } DONE_WITH_STR(name);    
+}
+
+ACR_JNI_EXPORT(jlong, PosixSemaphore, create0)(JNI_STDARGS,
+                                               jstring name, jint value)
+{
+    sem_t *sp = 0;
+
+    WITH_CSTR(name) {
+        sp = sem_open(J2S(name), O_CREAT | O_EXCL, 0660, value);       
+        if (sp == SEM_FAILED) {
+            if (errno == ENAMETOOLONG) {
+                ACR_THROW(ACR_EX_EINVAL, 0);
+            }
+            else if (errno == EEXIST) {
+                ACR_THROW(ACR_EX_EEXIST, 0);
+            }
+            else if (errno == EACCES) {
+                ACR_THROW(ACR_EX_EACCES, 0);
+            }
+            else {
+                ACR_THROW_OS_ERROR(ACR_EX_EIO);                
+            }
+        }
+    } DONE_WITH_STR(name);    
+    
+    return P2J(sp);
+}
+
+ACR_JNI_EXPORT(jlong, PosixSemaphore, open0)(JNI_STDARGS,
+                                             jstring name)
+{
+    sem_t *sp = 0;
+
+    WITH_CSTR(name) {
+        sp = sem_open(J2S(name), O_RDWR, 0, 0);       
+        if (sp == SEM_FAILED) {
+            if (errno == ENAMETOOLONG) {
+                ACR_THROW(ACR_EX_EINVAL, 0);
+            }
+            else if (errno == ENOENT) {
+                ACR_THROW(ACR_EX_ENOENT, 0);
+            }
+            else if (errno == EACCES) {
+                ACR_THROW(ACR_EX_EACCES, 0);
+            }
+            else {
+                ACR_THROW_OS_ERROR(ACR_EX_EIO);                
+            }
+            ACR_THROW_OS_ERROR(ACR_EX_EIO);                
+        }
+    } DONE_WITH_STR(name);    
+    
+    return P2J(sp);
+}
+
+ACR_JNI_EXPORT(void, PosixSemaphore, close0)(JNI_STDARGS, jlong sem)
+{
+    sem_t *sp = J2P(sem, sem_t *);
+
+    if (sp != SEM_FAILED) {
+        if (sem_close(sp)) {
+            ACR_THROW_OS_ERROR(ACR_EX_OSERR);
+        }
+    }
+}
+
+ACR_JNI_EXPORT(jint, PosixSemaphore, wait0)(JNI_STDARGS, jlong sem)
+{
+    int    rc;
+    sem_t *sp = J2P(sem, sem_t *);
+
+    do {
+        rc = sem_wait(sp);
+    } while (rc < 0 && errno == EINTR);
+    if (rc < 0)
+        return ACR_GET_OS_ERROR();
+    else
+        return 0;
+}
+
+ACR_JNI_EXPORT(jint, PosixSemaphore, try0)(JNI_STDARGS, jlong sem)
+{
+    int    rc;
+    sem_t *sp = J2P(sem, sem_t *);
+
+    do {
+        rc = sem_trywait(sp);
+    } while (rc < 0 && errno == EINTR);
+    if (rc < 0) {
+        if (errno == EAGAIN)
+            return ACR_EBUSY;
+        else
+            return ACR_GET_OS_ERROR();
+    }
+    return 0;
+}
+
+ACR_JNI_EXPORT(jint, PosixSemaphore, release0)(JNI_STDARGS, jlong sem)
+{
+    int    rc;
+    sem_t *sp = J2P(sem, sem_t *);
+
+    do {
+        rc = sem_post(sp);
+    } while (rc < 0 && errno == EINTR);
+    if (rc < 0)
+        return ACR_GET_OS_ERROR();
+    else
+        return 0;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1091827&r1=1091826&r2=1091827&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Wed Apr 13 15:40:08 2011
@@ -34,6 +34,7 @@ static struct {
     { 0, "java/lang/RuntimeException"                           },
     { 0, "java/lang/OutOfMemoryError"                           },
     { 0, "java/lang/NullPointerException"                       },
+    { 0, "java/lang/IllegalAccessException"                     },
     { 0, "java/lang/IllegalArgumentException"                   },
     { 0, "java/lang/IllegalStateException"                      },
     { 0, "java/lang/IndexOutOfBoundsException"                  },
@@ -50,6 +51,7 @@ static struct {
     { 0, "java/io/SyncFailedException"                          },
     { 0, "java/net/SocketException"                             },
     { 0, ACR_EXCEPTION_CP "NoSuchObjectException"               },
+    { 0, ACR_EXCEPTION_CP "ObjectAlreadyExistsException"        },    
     { 0, ACR_EXCEPTION_CP "OperatingSystemException"            },
     { 0, ACR_EXCEPTION_CP "TimeoutException"                    },
     { 0, ACR_EXCEPTION_CP "UnsupportedOperatingSystemException" },



Mime
View raw message