You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/13 14:25:01 UTC

svn commit: r1091759 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/ native/os/unix/ test/org/apache/commons/runtime/

Author: mturk
Date: Wed Apr 13 12:25:00 2011
New Revision: 1091759

URL: http://svn.apache.org/viewvc?rev=1091759&view=rev
Log:
Add skeleton for Semaphores

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImplFactory.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c   (with props)
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSemaphore.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,35 @@
+/* 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;
+
+import java.io.IOException;
+
+/**
+ * PosixSemaphore class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class PosixSemaphore extends Semaphore
+{
+
+    private PosixSemaphore()
+    {
+        // No Instance
+    }
+
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,36 @@
+/* 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;
+
+import java.io.IOException;
+
+/**
+ * SemaphoreImpl class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class PosixSemaphoreImpl extends SemaphoreImpl
+{
+
+    public PosixSemaphoreImpl()
+    {
+        // No Instance
+    }
+
+}
+

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImplFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImplFactory.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImplFactory.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImplFactory.java Wed Apr 13 12:25:00 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;
+
+import java.io.IOException;
+
+/**
+ * PosixSemaphoreImplFactory class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class PosixSemaphoreImplFactory extends SemaphoreImplFactory
+{
+
+    private PosixSemaphoreImplFactory()
+    {
+        // No Instance
+    }
+
+    public SemaphoreImpl createSemaphoreImpl()
+    {
+        return new PosixSemaphoreImpl();
+    }
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,47 @@
+/* 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;
+
+import java.io.IOException;
+
+/**
+ * Semaphore class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public abstract class Semaphore
+{
+
+    protected Semaphore()
+    {
+        // No Instance
+    }
+
+    private static final  SemaphoreImpl impl;
+    private static native SemaphoreImplFactory getImplFactory()
+        throws OutOfMemoryError;
+
+    static {
+        impl = getImplFactory().createSemaphoreImpl();
+    }
+
+    public static final SemaphoreImpl getImpl()
+    {
+        return impl;
+    }
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,36 @@
+/* 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;
+
+import java.io.IOException;
+
+/**
+ * SemaphoreImpl class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public abstract class SemaphoreImpl
+{
+
+    protected SemaphoreImpl()
+    {
+        // No Instance
+    }
+
+}
+

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImplFactory.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,36 @@
+/* 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;
+
+import java.io.IOException;
+
+/**
+ * SemaphoreImplFactory interface.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+abstract class SemaphoreImplFactory {
+    /**
+     * Creates a new <code>SemaphoreImpl</code> instance.
+     *
+     * @return  a new instance of <code>SemaphoreImpl</code>.
+     * @see     SemaphoreImpl
+     */
+    public abstract SemaphoreImpl createSemaphoreImpl();
+}
+

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

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1091759&r1=1091758&r2=1091759&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Wed Apr 13 12:25:00 2011
@@ -63,6 +63,7 @@ UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/dso.c \
 	$(TOPDIR)/os/unix/init.c \
 	$(TOPDIR)/os/unix/platform.c \
+	$(TOPDIR)/os/unix/semaphore.c \
 	$(TOPDIR)/os/unix/time.c \
 	$(TOPDIR)/os/unix/util.c
 

Added: 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=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c Wed Apr 13 12:25:00 2011
@@ -0,0 +1,68 @@
+/* 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.
+ */
+
+#include "acr/string.h"
+#include "acr/clazz.h"
+#include "acr/port.h"
+#include "arch_defs.h"
+
+#if HAVE_SEMAPHORE_H
+# include <semaphore.h>
+
+# if !defined(SEM_FAILED)
+#  define SEM_FAILED    (-1)
+# endif
+# if !defined(NAME_MAX)
+#  define NAME_MAX      64
+# endif
+#else
+# error Cannot find semaphore.h
+#endif
+
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_OFFSET,
+    0,
+    0,
+    0,
+    ACR_CLASS_PATH "PosixSemaphoreImplFactory"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "<init>",
+    "()V"
+};
+
+static int _init_factory(JNI_STDENV)
+{
+    int rv;
+
+    if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
+        return rv;
+    J_LOAD_METHOD(0000);
+    _clazzn.u = 1;
+    return 0;
+}
+
+ACR_JNI_EXPORT(jobject, Semaphore, getImplFactory)(JNI_STDARGS)
+{
+    if (_init_factory(env) != 0) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "PosixSemaphoreImplFactory not initialized");
+        return 0;
+    }
+    return (*env)->NewObject(env, _clazzn.i, J4MID(0000));
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/semaphore.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSemaphore.java?rev=1091759&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSemaphore.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSemaphore.java Wed Apr 13 12:25:00 2011
@@ -0,0 +1,34 @@
+/* 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;
+
+import java.io.IOException;
+import java.io.File;
+import org.testng.annotations.*;
+import org.testng.Assert;
+
+public class TestSemaphore
+{
+
+    @Test(groups = { "utils" })
+    public void factory()
+    {
+        SemaphoreImpl si = Semaphore.getImpl();
+        Assert.assertNotNull(si);
+    }
+
+}

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