svn commit: r161025 [10/13] - in incubator/beehive/trunk: ./ external/beehive-antext/ netui/ant/ netui/external/xdoclet/ netui/src/bootstrap/ netui/src/compiler-core/ netui/src/compiler-core/org/apache/beehive/netui/compiler/ netui/src/compiler-core/org/apache/beehive/netui/compiler/genmodel/ netui/src/compiler-core/org/apache/beehive/netui/compiler/grammar/ netui/src/compiler-core/org/apache/beehive/netui/compiler/model/ netui/src/compiler-core/org/apache/beehive/netui/compiler/model/validation/ netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/ netui/src/compiler-core/org/apache/beehive/netui/compiler/typesystem/declaration/ netui/src/compiler-core/org/apache/beehive/netui/compiler/typesystem/type/ netui/src/compiler-core/schema/processed-annotations/ netui/src/compiler-xdoclet/ netui/src/compiler-xdoclet/org/apache/beehive/netui/compiler/xdoclet/tools/ netui/src/compiler-xdoclet/org/apache/beehive/netui/compiler/xdoclet/typesystem/impl/ netui/src/compiler-xdoclet/org/apache/beehive/netui/compiler/xdoclet/typesystem/impl/declaration/ netui/src/compiler-xdoclet/org/apache/beehive/netui/compiler/xdoclet/typesystem/impl/env/ netui/src/compiler-xdoclet/org/apache/beehive/netui/compiler/xdoclet/typesystem/impl/type/ netui/src/compiler-xdoclet/org/apache/beehive/netui/tasks/ netui/src/compiler-xdoclet/org/apache/beehive/netui/xdoclet/ netui/src/compiler/ netui/src/compiler/org/apache/beehive/netui/compiler/apt/ netui/src/compiler/org/apache/beehive/netui/compiler/typesystem/impl/ netui/src/compiler/org/apache/beehive/netui/compiler/typesystem/impl/declaration/ netui/src/compiler/org/apache/beehive/netui/compiler/typesystem/impl/type/ netui/src/pageflow-jdk14/ netui/src/pageflow-jdk14/org/ netui/src/pageflow-jdk14/org/apache/ netui/src/pageflow-jdk14/org/apache/beehive/ netui/src/pageflow-jdk14/org/apache/beehive/netui/ netui/src/pageflow-jdk14/org/apache/beehive/netui/pageflow/ netui/src/pageflow-jdk14/org/apache/beehive/netui/pageflow/internal/ netui/src/pageflow/ netui/src/pageflow/org/apache/beehive/netui/pageflow/ netui/src/pageflow/org/apache/beehive/netui/pageflow/config/ netui/src/pageflow/org/apache/beehive/netui/pageflow/faces/internal/ netui/src/pageflow/org/apache/beehive/netui/pageflow/handler/ netui/src/pageflow/org/apache/beehive/netui/pageflow/interceptor/ netui/src/pageflow/org/apache/beehive/netui/pageflow/interceptor/action/ netui/src/pageflow/org/apache/beehive/netui/pageflow/interceptor/action/internal/ netui/src/pageflow/org/apache/beehive/netui/pageflow/interceptor/request/ netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/ netui/src/pageflow/org/apache/beehive/netui/pageflow/requeststate/ netui/src/pageflow/org/apache/beehive/netui/pageflow/util/ netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/ netui/src/pageflow/org/apache/beehive/netui/script/common/ netui/src/pageflow/org/apache/beehive/netui/script/el/ netui/src/pageflow/org/apache/beehive/netui/script/el/util/ netui/src/scoping/ netui/src/tags-databinding/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/filter/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/pager/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/sort/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/cell/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/rendering/pager/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/sql/ netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/base/style/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/invoke/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/pageinput/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/ netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/xml/ netui/src/tags-html/ netui/src/tags-html/org/apache/beehive/netui/tags/ netui/src/tags-html/org/apache/beehive/netui/tags/html/ netui/src/tags-html/org/apache/beehive/netui/tags/internal/ netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ netui/src/tags-html/org/apache/beehive/netui/tags/rendering/ netui/src/tags-html/org/apache/beehive/netui/tags/tree/ netui/src/tags-template/ netui/src/tags-template/org/apache/beehive/netui/tags/template/ netui/src/testRecorder/ netui/src/tomcat-webapp/5x/org/apache/beehive/netui/tomcat/ netui/src/util/ netui/src/util/org/apache/beehive/netui/core/urls/ netui/src/util/org/apache/beehive/netui/core/urltemplates/ netui/src/util/org/apache/beehive/netui/util/ netui/src/util/org/apache/beehive/netui/util/cache/ netui/src/util/org/apache/beehive/netui/util/classloader/ netui/src/util/org/apache/beehive/netui/util/config/ netui/src/util/org/apache/beehive/netui/util/internal/ netui/src/util/org/apache/beehive/netui/util/internal/concurrent/ netui/src/util/org/apache/beehive/netui/util/type/ netui/test/src/junitTests/ netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/ netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/ netui/test/src/junitTests/org/apache/beehive/netui/test/datagrid/ netui/test/src/junitTests/org/apache/beehive/netui/test/servlet/ netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ netui/test/src/testRecorderQA/ netui/test/webapps/drt/ netui/test/webapps/drt/coreWeb/WEB-INF/src/miniTests/actionInterceptors/ netui/test/webapps/drt/coreWeb/miniTests/actionInterceptors/interruptChain/ netui/test/webapps/drt/coreWeb/miniTests/exceptionMessages/ netui/test/webapps/drt/coreWeb/miniTests/handlePageException/ netui/test/webapps/drt/coreWeb/miniTests/handlers/ netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/ netui/test/webapps/drt/coreWeb/miniTests/preventDoubleSubmit/ netui/test/webapps/drt/coreWeb/miniTests/tiles/ netui/test/webapps/drt/coreWeb/miniTests/updateFormFromNested/ netui/test/webapps/drt/coreWeb/pageFlowCore/inheritance/super1/ netui/test/webapps/drt/coreWeb/pageFlowCore/pfPageInput/ netui/test/webapps/drt/coreWeb/tags/encoding/ netui/test/webapps/drt/coreWeb/template/xhtml/ netui/test/webapps/drt/coreWeb/tiles/pf/ netui/test/webapps/drt/coreWeb/tiles/pf/nested/ netui/test/webapps/drt/coreWeb/validation/addExpressionMessages/ netui/test/webapps/drt/coreWeb/validation/argExpressions/ netui/test/webapps/drt/coreWeb/validation/custom/ netui/test/webapps/drt/coreWeb/validation/declarativeValidation/

12 Apr 2005 06:50:36 -0000

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/ClassLevelCache.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/ClassLevelCache.java?view=diff&r1=161024&r2=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/ClassLevelCache.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/ClassLevelCache.java
 Mon Apr 11 23:42:11 2005
@@ -18,7 +18,7 @@
 package org.apache.beehive.netui.util.cache;
 
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import 
org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
 
 
 /**
@@ -26,8 +26,8 @@
  */
 public final class ClassLevelCache {
 
-    private static ConcurrentHashMap _classCaches = new ConcurrentHashMap();
-    private ConcurrentHashMap _caches = new ConcurrentHashMap();
+    private static InternalConcurrentHashMap _classCaches = new 
InternalConcurrentHashMap();
+    private InternalConcurrentHashMap _caches = new 
InternalConcurrentHashMap();
 
 
     public static ClassLevelCache getCache(Class c) {
@@ -46,7 +46,7 @@
     }
 
     public Object get(String majorKey, String minorKey) {
-        ConcurrentHashMap cache = (ConcurrentHashMap)_caches.get(majorKey);
+        InternalConcurrentHashMap cache = 
(InternalConcurrentHashMap)_caches.get(majorKey);
         return cache != null ? cache.get(minorKey) : null;
     }
 
@@ -63,10 +63,10 @@
     }
 
     public Map getCacheMap(String cacheID, boolean createIfMissing) {
-        ConcurrentHashMap cache = (ConcurrentHashMap)_caches.get(cacheID);
+        InternalConcurrentHashMap cache = 
(InternalConcurrentHashMap)_caches.get(cacheID);
 
         if(cache == null && createIfMissing) {
-            cache = new ConcurrentHashMap();
+            cache = new InternalConcurrentHashMap();
             _caches.put(cacheID, cache);
         }
 

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/MethodCache.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/MethodCache.java?view=diff&r1=161024&r2=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/MethodCache.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/MethodCache.java
 Mon Apr 11 23:42:11 2005
@@ -18,7 +18,7 @@
 package org.apache.beehive.netui.util.cache;
 
 import java.lang.reflect.Method;
-import java.util.concurrent.ConcurrentHashMap;
+import 
org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
 
 import org.apache.beehive.netui.util.logging.Logger;
 
@@ -29,13 +29,13 @@
 
     private static final Logger LOGGER = Logger.getInstance(MethodCache.class);
 
-    private final ConcurrentHashMap _methodCache;
+    private final InternalConcurrentHashMap _methodCache;
 
     /**
      *
      */
     public MethodCache() {
-        _methodCache = new ConcurrentHashMap();
+        _methodCache = new InternalConcurrentHashMap();
     }
 
     /**

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/PropertyCache.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/PropertyCache.java?view=diff&r1=161024&r2=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/PropertyCache.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/cache/PropertyCache.java
 Mon Apr 11 23:42:11 2005
@@ -23,7 +23,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.concurrent.ConcurrentHashMap;
+import 
org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
 import java.util.HashMap;
 import java.util.Iterator;
 
@@ -43,10 +43,10 @@
 
     private static final Logger LOGGER = 
Logger.getInstance(PropertyCache.class);
 
-    private final ConcurrentHashMap _classCache;
+    private final InternalConcurrentHashMap _classCache;
 
     public PropertyCache() {
-        _classCache = new ConcurrentHashMap();
+        _classCache = new InternalConcurrentHashMap();
     }
 
     /**

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/classloader/BouncyClassLoader.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/classloader/BouncyClassLoader.java?view=diff&r1=161024&r2=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/classloader/BouncyClassLoader.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/classloader/BouncyClassLoader.java
 Mon Apr 11 23:42:11 2005
@@ -25,8 +25,9 @@
 import java.io.FileNotFoundException;
 import java.io.BufferedInputStream;
 import java.io.IOException;
-import java.util.concurrent.ConcurrentHashMap;
+import 
org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
 import java.util.Map;
+import java.util.Iterator;
 import java.lang.reflect.Method;
 import java.security.SecureClassLoader;
 
@@ -42,7 +43,7 @@
 {
     private static final Logger _log = Logger.getInstance( 
BouncyClassLoader.class );
     
-    private ConcurrentHashMap< File, Long > _timestamps = new 
ConcurrentHashMap< File, Long >();
+    private InternalConcurrentHashMap/*< File, Long >*/ _timestamps = new 
InternalConcurrentHashMap/*< File, Long >*/();
     private File[] _classDirs;
     
     
@@ -111,9 +112,10 @@
 
     public boolean isStale()
     {
-        for ( Map.Entry< File, Long > entry : _timestamps.entrySet() )
+        for ( Iterator i = _timestamps.entrySet().iterator(); i.hasNext(); )
         {
-            if ( entry.getKey().lastModified() > entry.getValue() ) return 
true;
+            Map.Entry entry = ( Map.Entry ) i.next();
+            if ( ( ( File ) entry.getKey() ).lastModified() > ( ( Long ) 
entry.getValue() ).longValue() ) return true;
         }
         
         return false;

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java?view=diff&r1=161024&r2=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java
 Mon Apr 11 23:42:11 2005
@@ -133,7 +133,7 @@
 
         // Throw an exception if the XML is invalid.
         if(!isValid) {
-            StringBuilder msg = new StringBuilder("Invalid NetUI configuration 
file.");
+            StringBuffer msg = new StringBuffer("Invalid NetUI configuration 
file.");
 
             for(int i = 0; i < errorList.size(); i++) {
                 XmlError error = (XmlError)errorList.get(i);

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/CondVar.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/CondVar.java?view=auto&rev=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/CondVar.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/CondVar.java
 Mon Apr 11 23:42:11 2005
@@ -0,0 +1,149 @@
+/*
+  File: ConditionVariable.java
+  Originally written by Doug Lea and released into the public domain.
+  This may be used for any purposes whatsoever without acknowledgment.
+  Thanks for the assistance and support of Sun Microsystems Labs,
+  and everyone contributing, testing, and using this code.
+  History:
+  Date       Who                What
+  11Jun1998  dl               Create public version
+ */
+
+package org.apache.beehive.netui.util.internal.concurrent;
+
+import java.util.*;
+
+class CondVar implements Condition, java.io.Serializable {
+
+    /** The lock **/
+    protected final LockInfo lock;
+
+    /**
+     * Create a new CondVar that relies on the given mutual
+     * exclusion lock.
+     * @param lock A non-reentrant mutual exclusion lock.
+     **/
+
+    CondVar(LockInfo lock) {
+        this.lock = lock;
+    }
+
+    public void awaitUninterruptibly() {
+        boolean wasInterrupted = false;
+        while (true) {
+            try {
+                await();
+                if (wasInterrupted) {
+                    Thread.currentThread().interrupt();
+                }
+                return;
+            }
+            catch (InterruptedException e) {
+                wasInterrupted = true;
+            }
+        }
+    }
+
+    public void await() throws InterruptedException {
+        if (Thread.interrupted())
+            throw new InterruptedException();
+        try {
+            synchronized (this) {
+                lock.unlock();
+                try {
+                    wait();
+                }
+                catch (InterruptedException ex) {
+                    notify();
+                    throw ex;
+                }
+            }
+        }
+        finally {
+            lock.lock();
+        }
+    }
+
+    public boolean await(long timeout, TimeUnit unit) throws 
InterruptedException {
+        if (Thread.interrupted()) throw new InterruptedException();
+        long nanos = unit.toNanos(timeout);
+        boolean success = false;
+        try {
+            synchronized (this) {
+                lock.unlock();
+                try {
+                    if (nanos > 0) {
+                        long start = Utils.nanoTime();
+                        TimeUnit.NANOSECONDS.timedWait(this, nanos);
+                        // DK: due to coarse-grained (millis) clock, it seems
+                        // preferable to acknowledge timeout (success == false)
+                        // when the equality holds (timing is exact)
+                        success = Utils.nanoTime() - start < nanos;
+                    }
+                }
+                catch (InterruptedException ex) {
+                    notify();
+                    throw ex;
+                }
+            }
+        }
+        finally {
+            lock.lock();
+        }
+        return success;
+    }
+
+//    public long awaitNanos(long timeout) throws InterruptedException {
+//        throw new UnsupportedOperationException();
+//    }
+//
+    public boolean awaitUntil(Date deadline) throws InterruptedException {
+        if (deadline == null) throw new NullPointerException();
+        long abstime = deadline.getTime();
+        if (Thread.interrupted()) throw new InterruptedException();
+
+        boolean success = false;
+        try {
+            synchronized (this) {
+                lock.unlock();
+                try {
+                    long start = System.currentTimeMillis();
+                    long msecs = abstime - start;
+                    if (msecs > 0) {
+                        wait(msecs);
+                        // DK: due to coarse-grained (millis) clock, it seems
+                        // preferable to acknowledge timeout (success == false)
+                        // when the equality holds (timing is exact)
+                        success = System.currentTimeMillis() - start < msecs;
+                    }
+                }
+                catch (InterruptedException ex) {
+                    notify();
+                    throw ex;
+                }
+            }
+        }
+        finally {
+            lock.lock();
+        }
+        return success;
+    }
+
+    public synchronized void signal() {
+        if (!lock.isHeldByCurrentThread()) {
+            throw new IllegalMonitorStateException();
+        }
+        notify();
+    }
+
+    public synchronized void signalAll() {
+        if (!lock.isHeldByCurrentThread()) {
+            throw new IllegalMonitorStateException();
+        }
+        notifyAll();
+    }
+
+    static interface LockInfo extends Lock {
+        boolean isHeldByCurrentThread();
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/CondVar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/Condition.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/Condition.java?view=auto&rev=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/Condition.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/Condition.java
 Mon Apr 11 23:42:11 2005
@@ -0,0 +1,432 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.apache.beehive.netui.util.internal.concurrent;
+
+import java.util.Date;
+
+/**
+ * <tt>Condition</tt> factors out the <tt>Object</tt> monitor
+ * methods ([EMAIL PROTECTED] Object#wait() wait}, [EMAIL PROTECTED] 
Object#notify notify}
+ * and [EMAIL PROTECTED] Object#notifyAll notifyAll}) into distinct objects to
+ * give the effect of having multiple wait-sets per object, by
+ * combining them with the use of arbitrary [EMAIL PROTECTED] Lock} 
implementations.
+ * Where a <tt>Lock</tt> replaces the use of <tt>synchronized</tt> methods
+ * and statements, a <tt>Condition</tt> replaces the use of the Object
+ * monitor methods.
+ *
+ * <p>Conditions (also known as <em>condition queues</em> or
+ * <em>condition variables</em>) provide a means for one thread to
+ * suspend execution (to &quot;wait&quot;) until notified by another
+ * thread that some state condition may now be true.  Because access
+ * to this shared state information occurs in different threads, it
+ * must be protected, so a lock of some form is associated with the
+ * condition. The key property that waiting for a condition provides
+ * is that it <em>atomically</em> releases the associated lock and
+ * suspends the current thread, just like <tt>Object.wait</tt>.
+ *
+ * <p>A <tt>Condition</tt> instance is intrinsically bound to a lock.
+ * To obtain a <tt>Condition</tt> instance for a particular [EMAIL PROTECTED] 
Lock}
+ * instance use its [EMAIL PROTECTED] Lock#newCondition newCondition()} method.
+ *
+ * <p>As an example, suppose we have a bounded buffer which supports
+ * <tt>put</tt> and <tt>take</tt> methods.  If a
+ * <tt>take</tt> is attempted on an empty buffer, then the thread will block
+ * until an item becomes available; if a <tt>put</tt> is attempted on a
+ * full buffer, then the thread will block until a space becomes available.
+ * We would like to keep waiting <tt>put</tt> threads and <tt>take</tt>
+ * threads in separate wait-sets so that we can use the optimization of
+ * only notifying a single thread at a time when items or spaces become
+ * available in the buffer. This can be achieved using two
+ * [EMAIL PROTECTED] Condition} instances.
+ * <pre>
+ * class BoundedBuffer {
+ *   <b>final Lock lock = new ReentrantLock();</b>
+ *   final Condition notFull  = <b>lock.newCondition(); </b>
+ *   final Condition notEmpty = <b>lock.newCondition(); </b>
+ *
+ *   final Object[] items = new Object[100];
+ *   int putptr, takeptr, count;
+ *
+ *   public void put(Object x) throws InterruptedException {
+ *     <b>lock.lock();
+ *     try {</b>
+ *       while (count == items.length)
+ *         <b>notFull.await();</b>
+ *       items[putptr] = x;
+ *       if (++putptr == items.length) putptr = 0;
+ *       ++count;
+ *       <b>notEmpty.signal();</b>
+ *     <b>} finally {
+ *       lock.unlock();
+ *     }</b>
+ *   }
+ *
+ *   public Object take() throws InterruptedException {
+ *     <b>lock.lock();
+ *     try {</b>
+ *       while (count == 0)
+ *         <b>notEmpty.await();</b>
+ *       Object x = items[takeptr];
+ *       if (++takeptr == items.length) takeptr = 0;
+ *       --count;
+ *       <b>notFull.signal();</b>
+ *       return x;
+ *     <b>} finally {
+ *       lock.unlock();
+ *     }</b>
+ *   }
+ * }
+ * </pre>
+ *
+ * (The [EMAIL PROTECTED] 
org.apache.beehive.netui.util.concurrent.ArrayBlockingQueue} class provides
+ * this functionality, so there is no reason to implement this
+ * sample usage class.)
+ *
+ * <p>A <tt>Condition</tt> implementation can provide behavior and semantics
+ * that is
+ * different from that of the <tt>Object</tt> monitor methods, such as
+ * guaranteed ordering for notifications, or not requiring a lock to be held
+ * when performing notifications.
+ * If an implementation provides such specialized semantics then the
+ * implementation must document those semantics.
+ *
+ * <p>Note that <tt>Condition</tt> instances are just normal objects and can
+ * themselves be used as the target in a <tt>synchronized</tt> statement,
+ * and can have their own monitor [EMAIL PROTECTED] Object#wait wait} and
+ * [EMAIL PROTECTED] Object#notify notification} methods invoked.
+ * Acquiring the monitor lock of a <tt>Condition</tt> instance, or using its
+ * monitor methods, has no specified relationship with acquiring the
+ * [EMAIL PROTECTED] Lock} associated with that <tt>Condition</tt> or the use 
of its
+ * [EMAIL PROTECTED] #await waiting} and [EMAIL PROTECTED] #signal signalling} 
methods.
+ * It is recommended that to avoid confusion you never use <tt>Condition</tt>
+ * instances in this way, except perhaps within their own implementation.
+ *
+ * <p>Except where noted, passing a <tt>null</tt> value for any parameter
+ * will result in a [EMAIL PROTECTED] NullPointerException} being thrown.
+ *
+ * <h3>Implementation Considerations</h3>
+ *
+ * <p>When waiting upon a <tt>Condition</tt>, a &quot;<em>spurious
+ * wakeup</em>&quot; is permitted to occur, in
+ * general, as a concession to the underlying platform semantics.
+ * This has little practical impact on most application programs as a
+ * <tt>Condition</tt> should always be waited upon in a loop, testing
+ * the state predicate that is being waited for.  An implementation is
+ * free to remove the possibility of spurious wakeups but it is
+ * recommended that applications programmers always assume that they can
+ * occur and so always wait in a loop.
+ *
+ * <p>The three forms of condition waiting
+ * (interruptible, non-interruptible, and timed) may differ in their ease of
+ * implementation on some platforms and in their performance characteristics.
+ * In particular, it may be difficult to provide these features and maintain
+ * specific semantics such as ordering guarantees.
+ * Further, the ability to interrupt the actual suspension of the thread may
+ * not always be feasible to implement on all platforms.
+ * <p>Consequently, an implementation is not required to define exactly the
+ * same guarantees or semantics for all three forms of waiting, nor is it
+ * required to support interruption of the actual suspension of the thread.
+ * <p>An implementation is required to
+ * clearly document the semantics and guarantees provided by each of the
+ * waiting methods, and when an implementation does support interruption of
+ * thread suspension then it must obey the interruption semantics as defined
+ * in this interface.
+ * <p>As interruption generally implies cancellation, and checks for
+ * interruption are often infrequent, an implementation can favor responding
+ * to an interrupt over normal method return. This is true even if it can be
+ * shown that the interrupt occurred after another action may have unblocked
+ * the thread. An implementation should document this behavior.
+ *
+ *
+ * @since 1.5
+ * @author Doug Lea
+ */
+interface Condition {
+
+    /**
+     * Causes the current thread to wait until it is signalled or
+     * [EMAIL PROTECTED] Thread#interrupt interrupted}.
+     *
+     * <p>The lock associated with this <tt>Condition</tt> is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of four things happens:
+     * <ul>
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signal} method for 
this
+     * <tt>Condition</tt> and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signalAll} method 
for this
+     * <tt>Condition</tt>; or
+     * <li>Some other thread [EMAIL PROTECTED] Thread#interrupt interrupts} 
the current
+     * thread, and interruption of thread suspension is supported; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs
+     * </ul>
+     *
+     * <p>In all cases, before this method can return the current thread must
+     * re-acquire the lock associated with this condition. When the
+     * thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread:
+     * <ul>
+     * <li>has its interrupted status set on entry to this method; or
+     * <li>is [EMAIL PROTECTED] Thread#interrupt interrupted} while waiting
+     * and interruption of thread suspension is supported,
+     * </ul>
+     * then [EMAIL PROTECTED] InterruptedException} is thrown and the current 
thread's
+     * interrupted status is cleared. It is not specified, in the first
+     * case, whether or not the test for interruption occurs before the lock
+     * is released.
+     *
+     * <p><b>Implementation Considerations</b>
+     * <p>The current thread is assumed to hold the lock associated with this
+     * <tt>Condition</tt> when this method is called.
+     * It is up to the implementation to determine if this is
+     * the case and if not, how to respond. Typically, an exception will be
+     * thrown (such as [EMAIL PROTECTED] IllegalMonitorStateException}) and the
+     * implementation must document that fact.
+     *
+     * <p>An implementation can favor responding to an interrupt over normal
+     * method return in response to a signal. In that case the implementation
+     * must ensure that the signal is redirected to another waiting thread, if
+     * there is one.
+     *
+     * @throws InterruptedException if the current thread is interrupted (and
+     * interruption of thread suspension is supported).
+     **/
+    void await() throws InterruptedException;
+
+    /**
+     * Causes the current thread to wait until it is signalled.
+     *
+     * <p>The lock associated with this condition is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of three things happens:
+     * <ul>
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signal} method for 
this
+     * <tt>Condition</tt> and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signalAll} method 
for this
+     * <tt>Condition</tt>; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs
+     * </ul>
+     *
+     * <p>In all cases, before this method can return the current thread must
+     * re-acquire the lock associated with this condition. When the
+     * thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     * <p>If the current thread's interrupted status is set when it enters
+     * this method, or it is [EMAIL PROTECTED] Thread#interrupt interrupted}
+     * while waiting, it will continue to wait until signalled. When it finally
+     * returns from this method its interrupted status will still
+     * be set.
+     *
+     * <p><b>Implementation Considerations</b>
+     * <p>The current thread is assumed to hold the lock associated with this
+     * <tt>Condition</tt> when this method is called.
+     * It is up to the implementation to determine if this is
+     * the case and if not, how to respond. Typically, an exception will be
+     * thrown (such as [EMAIL PROTECTED] IllegalMonitorStateException}) and the
+     * implementation must document that fact.
+     *
+     **/
+    void awaitUninterruptibly();
+
+//    /**
+//     * Causes the current thread to wait until it is signalled or 
interrupted,
+//     * or the specified waiting time elapses.
+//     *
+//     * <p>The lock associated with this condition is atomically
+//     * released and the current thread becomes disabled for thread scheduling
+//     * purposes and lies dormant until <em>one</em> of five things happens:
+//     * <ul>
+//     * <li>Some other thread invokes the [EMAIL PROTECTED] #signal} method 
for this
+//     * <tt>Condition</tt> and the current thread happens to be chosen as the
+//     * thread to be awakened; or
+//     * <li>Some other thread invokes the [EMAIL PROTECTED] #signalAll} 
method for this
+//     * <tt>Condition</tt>; or
+//     * <li>Some other thread [EMAIL PROTECTED] Thread#interrupt interrupts} 
the current
+//     * thread, and interruption of thread suspension is supported; or
+//     * <li>The specified waiting time elapses; or
+//     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+//     * </ul>
+//     *
+//     * <p>In all cases, before this method can return the current thread must
+//     * re-acquire the lock associated with this condition. When the
+//     * thread returns it is <em>guaranteed</em> to hold this lock.
+//     *
+//     * <p>If the current thread:
+//     * <ul>
+//     * <li>has its interrupted status set on entry to this method; or
+//     * <li>is [EMAIL PROTECTED] Thread#interrupt interrupted} while waiting
+//     * and interruption of thread suspension is supported,
+//     * </ul>
+//     * then [EMAIL PROTECTED] InterruptedException} is thrown and the 
current thread's
+//     * interrupted status is cleared. It is not specified, in the first
+//     * case, whether or not the test for interruption occurs before the lock
+//     * is released.
+//     *
+//     * <p>The method returns an estimate of the number of nanoseconds
+//     * remaining to wait given the supplied <tt>nanosTimeout</tt>
+//     * value upon return, or a value less than or equal to zero if it
+//     * timed out. This value can be used to determine whether and how
+//     * long to re-wait in cases where the wait returns but an awaited
+//     * condition still does not hold. Typical uses of this method take
+//     * the following form:
+//     *
+//     * <pre>
+//     * synchronized boolean aMethod(long timeout, TimeUnit unit) {
+//     *   long nanosTimeout = unit.toNanos(timeout);
+//     *   while (!conditionBeingWaitedFor) {
+//     *     if (nanosTimeout &gt; 0)
+//     *         nanosTimeout = theCondition.awaitNanos(nanosTimeout);
+//     *      else
+//     *        return false;
+//     *   }
+//     *   // ...
+//     * }
+//     * </pre>
+//     *
+//     * <p> Design note: This method requires a nanosecond argument so
+//     * as to avoid truncation errors in reporting remaining times.
+//     * Such precision loss would make it difficult for programmers to
+//     * ensure that total waiting times are not systematically shorter
+//     * than specified when re-waits occur.
+//     *
+//     * <p><b>Implementation Considerations</b>
+//     * <p>The current thread is assumed to hold the lock associated with this
+//     * <tt>Condition</tt> when this method is called.
+//     * It is up to the implementation to determine if this is
+//     * the case and if not, how to respond. Typically, an exception will be
+//     * thrown (such as [EMAIL PROTECTED] IllegalMonitorStateException}) and 
the
+//     * implementation must document that fact.
+//     *
+//     * <p>An implementation can favor responding to an interrupt over normal
+//     * method return in response to a signal, or over indicating the elapse
+//     * of the specified waiting time. In either case the implementation
+//     * must ensure that the signal is redirected to another waiting thread, 
if
+//     * there is one.
+//     *
+//     * @param nanosTimeout the maximum time to wait, in nanoseconds
+//     * @return A value less than or equal to zero if the wait has
+//     * timed out; otherwise an estimate, that
+//     * is strictly less than the <tt>nanosTimeout</tt> argument,
+//     * of the time still remaining when this method returned.
+//     *
+//     * @throws InterruptedException if the current thread is interrupted (and
+//     * interruption of thread suspension is supported).
+//     */
+//    long awaitNanos(long nanosTimeout) throws InterruptedException;
+
+    /**
+     * Causes the current thread to wait until it is signalled or interrupted,
+     * or the specified waiting time elapses. This method is behaviorally
+     * equivalent to:<br>
+     * <pre>
+     *   awaitNanos(unit.toNanos(time)) &gt; 0
+     * </pre>
+     * @param time the maximum time to wait
+     * @param unit the time unit of the <tt>time</tt> argument.
+     * @return <tt>false</tt> if the waiting time detectably elapsed
+     * before return from the method, else <tt>true</tt>.
+     * @throws InterruptedException if the current thread is interrupted (and
+     * interruption of thread suspension is supported).
+     */
+    boolean await(long time, TimeUnit unit) throws InterruptedException;
+
+    /**
+     * Causes the current thread to wait until it is signalled or interrupted,
+     * or the specified deadline elapses.
+     *
+     * <p>The lock associated with this condition is atomically
+     * released and the current thread becomes disabled for thread scheduling
+     * purposes and lies dormant until <em>one</em> of five things happens:
+     * <ul>
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signal} method for 
this
+     * <tt>Condition</tt> and the current thread happens to be chosen as the
+     * thread to be awakened; or
+     * <li>Some other thread invokes the [EMAIL PROTECTED] #signalAll} method 
for this
+     * <tt>Condition</tt>; or
+     * <li>Some other thread [EMAIL PROTECTED] Thread#interrupt interrupts} 
the current
+     * thread, and interruption of thread suspension is supported; or
+     * <li>The specified deadline elapses; or
+     * <li>A &quot;<em>spurious wakeup</em>&quot; occurs.
+     * </ul>
+     *
+     * <p>In all cases, before this method can return the current thread must
+     * re-acquire the lock associated with this condition. When the
+     * thread returns it is <em>guaranteed</em> to hold this lock.
+     *
+     *
+     * <p>If the current thread:
+     * <ul>
+     * <li>has its interrupted status set on entry to this method; or
+     * <li>is [EMAIL PROTECTED] Thread#interrupt interrupted} while waiting
+     * and interruption of thread suspension is supported,
+     * </ul>
+     * then [EMAIL PROTECTED] InterruptedException} is thrown and the current 
thread's
+     * interrupted status is cleared. It is not specified, in the first
+     * case, whether or not the test for interruption occurs before the lock
+     * is released.
+     *
+     *
+     * <p>The return value indicates whether the deadline has elapsed,
+     * which can be used as follows:
+     * <pre>
+     * synchronized boolean aMethod(Date deadline) {
+     *   boolean stillWaiting = true;
+     *   while (!conditionBeingWaitedFor) {
+     *     if (stillwaiting)
+     *         stillWaiting = theCondition.awaitUntil(deadline);
+     *      else
+     *        return false;
+     *   }
+     *   // ...
+     * }
+     * </pre>
+     *
+     * <p><b>Implementation Considerations</b>
+     * <p>The current thread is assumed to hold the lock associated with this
+     * <tt>Condition</tt> when this method is called.
+     * It is up to the implementation to determine if this is
+     * the case and if not, how to respond. Typically, an exception will be
+     * thrown (such as [EMAIL PROTECTED] IllegalMonitorStateException}) and the
+     * implementation must document that fact.
+     *
+     * <p>An implementation can favor responding to an interrupt over normal
+     * method return in response to a signal, or over indicating the passing
+     * of the specified deadline. In either case the implementation
+     * must ensure that the signal is redirected to another waiting thread, if
+     * there is one.
+     *
+     *
+     * @param deadline the absolute time to wait until
+     * @return <tt>false</tt> if the deadline has
+     * elapsed upon return, else <tt>true</tt>.
+     *
+     * @throws InterruptedException if the current thread is interrupted (and
+     * interruption of thread suspension is supported).
+     */
+    boolean awaitUntil(Date deadline) throws InterruptedException;
+
+    /**
+     * Wakes up one waiting thread.
+     *
+     * <p>If any threads are waiting on this condition then one
+     * is selected for waking up. That thread must then re-acquire the
+     * lock before returning from <tt>await</tt>.
+     **/
+    void signal();
+
+    /**
+     * Wakes up all waiting threads.
+     *
+     * <p>If any threads are waiting on this condition then they are
+     * all woken up. Each thread must re-acquire the lock before it can
+     * return from <tt>await</tt>.
+     **/
+    void signalAll();
+
+}

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/Condition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/FIFOWaitQueue.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/FIFOWaitQueue.java?view=auto&rev=161025
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/FIFOWaitQueue.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/FIFOWaitQueue.java
 Mon Apr 11 23:42:11 2005
@@ -0,0 +1,73 @@
+package org.apache.beehive.netui.util.internal.concurrent;
+
+import java.util.*;
+
+/**
+ * Simple linked list queue used in FIFOSemaphore.
+ * Methods are not synchronized; they depend on synch of callers.
+ * Must be public, since it is used by Semaphore (outside this package).
+ * NOTE: this class is NOT present in java.util.concurrent.
+ **/
+
+class FIFOWaitQueue extends WaitQueue implements java.io.Serializable {
+    protected transient WaitNode head_ = null;
+    protected transient WaitNode tail_ = null;
+
+    public FIFOWaitQueue() {}
+
+    public void insert(WaitNode w) {
+        if (tail_ == null)
+            head_ = tail_ = w;
+        else {
+            tail_.next = w;
+            tail_ = w;
+        }
+    }
+
+    public WaitNode extract() {
+        if (head_ == null)
+            return null;
+        else {
+            WaitNode w = head_;
+            head_ = w.next;
+            if (head_ == null)
+                tail_ = null;
+            w.next = null;
+            return w;
+        }
+    }
+
+    public boolean hasNodes() {
+        return head_ != null;
+    }
+
+    public int getLength() {
+        int count = 0;
+        WaitNode node = head_;
+        while (node != null) {
+            if (node.waiting) count++;
+            node = node.next;
+        }
+        return count;
+    }
+
+    public Collection getWaitingThreads() {
+        List list = new ArrayList();
+        int count = 0;
+        WaitNode node = head_;
+        while (node != null) {
+            if (node.waiting) list.add(node.owner);
+            node = node.next;
+        }
+        return list;
+    }
+
+    public boolean isWaiting(Thread thread) {
+        if (thread == null) throw new NullPointerException();
+        for (WaitNode node = head_; node != null; node = node.next) {
+            if (node.waiting && node.owner == thread) return true;
+        }
+        return false;
+    }
+
+}

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/internal/concurrent/FIFOWaitQueue.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to