commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1091885 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime: PosixSemaphore.java PosixSemaphoreImpl.java Semaphore.java SemaphoreImpl.java WindowsSemaphore.java WindowsSemaphoreImpl.java
Date Wed, 13 Apr 2011 18:49:38 GMT
Author: mturk
Date: Wed Apr 13 18:49:38 2011
New Revision: 1091885

URL: http://svn.apache.org/viewvc?rev=1091885&view=rev
Log:
Fill in Semaphore api

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java

Modified: 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=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphore.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,6 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
 import org.apache.commons.runtime.exception.AlreadyExistsException;
 import org.apache.commons.runtime.exception.NoSuchObjectException;
 import org.apache.commons.runtime.exception.ClosedDescriptorException;
@@ -55,8 +54,6 @@ final class PosixSemaphore extends Semap
 
     // OS semaphore handle (sem_t)
     private long    sd;
-    private String  name;
-    private boolean owner;
 
     public PosixSemaphore(final String name, int value)
         throws IllegalAccessException,
@@ -175,11 +172,6 @@ final class PosixSemaphore extends Semap
         sd = 0L;
     }
     
-    public String getCanonicalName()
-    {
-        return name;
-    }
-
     /**
      * Called by the garbage collector when the object is destroyed.
      * The class will free internal resources allocated by the Operating system.

Modified: 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=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/PosixSemaphoreImpl.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,9 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
+import org.apache.commons.runtime.exception.AlreadyExistsException;
+import org.apache.commons.runtime.exception.NoSuchObjectException;
+import org.apache.commons.runtime.exception.SystemException;
 
 /**
  * SemaphoreImpl class.
@@ -32,5 +34,23 @@ final class PosixSemaphoreImpl extends S
         // No Instance
     }
 
+    public Semaphore create(String name, int value)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               AlreadyExistsException,
+               SystemException
+    {
+        return new PosixSemaphore(name, value);
+    }
+
+    public Semaphore open(String name)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               NoSuchObjectException,
+               SystemException
+    {
+        return new PosixSemaphore(name);
+    }
+
 }
 

Modified: 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=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,7 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
+import org.apache.commons.runtime.exception.SystemException;
 
 /**
  * Semaphore class.
@@ -40,8 +40,65 @@ public abstract class Semaphore
         impl = getImplFactory().createSemaphoreImpl();
     }
 
+    protected String  name;
+    protected boolean owner;
+
     public static final SemaphoreImpl getImpl()
     {
         return impl;
     }
+
+    /**
+     * Acquires a permit from this semaphore, blocking until
+     * one is available.
+     * 
+     */
+    public abstract void acquire()
+        throws SystemException;
+
+    /**
+     * Acquires a permit from this semaphore, only if one is available
+     * at the time of invocation.
+     * 
+     */
+    public abstract boolean tryAcquire()
+        throws SystemException;
+
+    /**
+     * Releases a permit.
+     * 
+     */
+    public abstract void release()
+        throws SystemException;
+
+    /**
+     * Clears the Semaphore.
+     * 
+     */
+    public abstract void clear()
+        throws SystemException;
+
+    /**
+     * Closes the semaphore.
+     * 
+     */
+    public abstract void close()
+        throws SystemException;
+
+    /**
+     * Get Semaphore name.
+     */
+    public String getCanonicalName()
+    {
+        return name;
+    }
+
+    /**
+     * Check if this is Semaphore owner.
+     */
+    public boolean isOwner()
+    {
+        return owner;
+    }
+
 }

Modified: 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=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SemaphoreImpl.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,9 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
+import org.apache.commons.runtime.exception.AlreadyExistsException;
+import org.apache.commons.runtime.exception.NoSuchObjectException;
+import org.apache.commons.runtime.exception.SystemException;
 
 /**
  * SemaphoreImpl class.
@@ -32,5 +34,17 @@ public abstract class SemaphoreImpl
         // No Instance
     }
 
+    public abstract Semaphore create(String name, int value)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               AlreadyExistsException,
+               SystemException;
+
+    public abstract Semaphore open(String name)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               NoSuchObjectException,
+               SystemException;
+
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java?rev=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphore.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,10 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
+import org.apache.commons.runtime.exception.AlreadyExistsException;
+import org.apache.commons.runtime.exception.NoSuchObjectException;
+import org.apache.commons.runtime.exception.ClosedDescriptorException;
+import org.apache.commons.runtime.exception.SystemException;
 
 /**
  * WindowsSemaphore class.
@@ -32,4 +35,80 @@ final class WindowsSemaphore extends Sem
         // No Instance
     }
 
+    // OS semaphore handle
+    private long    sd;
+    
+    public WindowsSemaphore(final String name, int value)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               AlreadyExistsException,
+               SystemException
+    {
+        if (name == null)
+            throw new NullPointerException();
+        this.name = "\\\\Global\\" + name.replace('\\', '_');
+
+        owner = true;
+    }
+
+    public WindowsSemaphore(final String name)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               NoSuchObjectException,
+               SystemException
+    {
+        if (name == null)
+            throw new NullPointerException();
+        this.name = "\\\\Global\\" + name.replace('\\', '_');
+
+        owner = false;
+    }
+
+    public void acquire()
+        throws SystemException
+    {
+        if (sd == 0L)
+            throw new ClosedDescriptorException();
+    }
+
+    public boolean tryAcquire()
+        throws SystemException
+    {
+        if (sd == 0L)
+            throw new ClosedDescriptorException();
+        return false;
+    }
+
+    public void release()
+        throws SystemException
+    {
+        if (sd == 0L)
+            throw new ClosedDescriptorException();
+    }
+
+    public void clear()
+        throws SystemException
+    {
+    }
+
+    public void close()
+        throws SystemException
+    {
+        if (sd == 0L)
+            throw new ClosedDescriptorException();
+        sd = 0L;
+    }
+    
+    /**
+     * Called by the garbage collector when the object is destroyed.
+     * The class will free internal resources allocated by the Operating system.
+     * @see Object#finalize()
+     * @throws Throwable the {@code Exception} raised by this method.
+     */
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java?rev=1091885&r1=1091884&r2=1091885&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/WindowsSemaphoreImpl.java
Wed Apr 13 18:49:38 2011
@@ -15,7 +15,9 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.IOException;
+import org.apache.commons.runtime.exception.AlreadyExistsException;
+import org.apache.commons.runtime.exception.NoSuchObjectException;
+import org.apache.commons.runtime.exception.SystemException;
 
 /**
  * WindowsSemaphoreImpl class.
@@ -32,5 +34,22 @@ final class WindowsSemaphoreImpl extends
         // No Instance
     }
 
-}
+    public Semaphore create(String name, int value)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               AlreadyExistsException,
+               SystemException
+    {
+        return new WindowsSemaphore(name, value);
+    }
 
+    public Semaphore open(String name)
+        throws IllegalAccessException,
+               IllegalArgumentException,
+               NoSuchObjectException,
+               SystemException
+    {
+        return new WindowsSemaphore(name);
+    }
+
+}



Mime
View raw message