Author: mturk
Date: Mon Sep  7 15:55:01 2009
New Revision: 812211

URL: http://svn.apache.org/viewvc?rev=812211&view=rev
Log:
Implement Java API

Modified:
    
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SharedMemory.java
    
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSharedMemory.java

Modified: 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SharedMemory.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SharedMemory.java?rev=812211&r1=812210&r2=812211&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SharedMemory.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SharedMemory.java
 Mon Sep  7 15:55:01 2009
@@ -17,8 +17,10 @@
 
 import java.io.IOException;
 import java.util.Enumeration;
+import java.util.EnumSet;
 import java.util.Vector;
 import org.apache.commons.runtime.io.File;
+import org.apache.commons.runtime.io.FileProtection;
 import org.apache.commons.runtime.io.Status;
 import org.apache.commons.runtime.exception.ClosedDescriptorException;
 import org.apache.commons.runtime.exception.OperatingSystemException;
@@ -295,5 +297,20 @@
         }
     }
 
+    private static native boolean chown0(Descriptor shm, int prot,
+                                         Descriptor uid, Descriptor gid)
+        throws IOException, IndexOutOfBoundsException;
+    /**
+     * Set protection for the {...@code this} SharedMemory object.
+     * <p>
+     * </p>
+     * @param prot The {...@code EnumSet} determining the access permissions.
+     */
+    public boolean setProtection(EnumSet<FileProtection> prot)
+        throws IOException, SecurityException
+    {
+        return chown0(shm, FileProtection.bitmapOf(prot), null, null);
+    }
+
 }
 

Modified: 
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSharedMemory.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSharedMemory.java?rev=812211&r1=812210&r2=812211&view=diff
==============================================================================
--- 
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSharedMemory.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSharedMemory.java
 Mon Sep  7 15:55:01 2009
@@ -17,6 +17,7 @@
 package org.apache.commons.runtime;
 
 import java.lang.System;
+import java.util.EnumSet;
 import junit.framework.*;
 import org.apache.commons.runtime.io.*;
 import org.apache.commons.runtime.exception.*;
@@ -43,7 +44,7 @@
         throws Throwable
     {
         if (TestParams.getInstance().isChild()) {
-            // Ship the test
+            // Skip the test
             return;
         }
         try {
@@ -66,7 +67,7 @@
         throws Throwable
     {
         if (TestParams.getInstance().isChild()) {
-            // Ship the test
+            // Skip the test
             return;
         }
         SharedMemory shm;
@@ -84,5 +85,25 @@
         assertTrue("Shared memory not removed", rv);
     }
 
+    public void testSharedMemoryPermSet()
+        throws Throwable
+    {
+        if (TestParams.getInstance().isChild()) {
+            // Skip the test
+            return;
+        }
+        SharedMemory shm;
+
+        shm = SharedMemory.create(new File("ACRSharedMemory"), 1024);
+        try {
+        } catch (Throwable t) {
+            assertSame("Wrong Exception class",
+                ClosedDescriptorException.class, t.getClass());
+        }
+        boolean rv = shm.setProtection(EnumSet.of(FileProtection.UREAD, 
FileProtection.UWRITE));
+        assertTrue("Shared memory not protected", rv);
+        shm.close();
+    }
+
 }
 


Reply via email to