rana_b      2002/10/10 09:09:34

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver/util
                        Queue.java
  Log:
  added wait time method
  
  Revision  Changes    Path
  1.5       +38 -11    
jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/Queue.java
  
  Index: Queue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/Queue.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Queue.java        26 Apr 2002 14:31:20 -0000      1.4
  +++ Queue.java        10 Oct 2002 16:09:34 -0000      1.5
  @@ -9,14 +9,14 @@
   
   package org.apache.avalon.ftpserver.util;
   
  -import java.util.*;
  +import java.util.LinkedList;
   
   /**
  - * Queue (first in first out) implementation. It supports two types
  - * of queues.
  - * <li> Queue is empty throws NoSuchElementException.
  - * <li> Queue is empty waits for the new element.               
  - *
  + * Queue (first in first out) implementation. It supports two types of queues.
  + * <ul>
  + *   <li> Queue is empty : throws NoSuchElementException.</li>
  + *   <li> Queue is empty : waits for the new element.</li>               
  + * </ul>
    * Null values <b>cannot</b> be inserted.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rana Bhattacharyya</a>
  @@ -52,10 +52,37 @@
                       return null;
                   }
               }
  -            return mList.removeLast();
  +            return mList.removeFirst();
           }
           else {
  -           return mList.removeLast();
  +           return mList.removeFirst();
  +        }
  +    }
  +    
  +    /**
  +     * Try to get the first element. If the list is empty,
  +     * the thread will wait. If interrupted returns null.
  +     */
  +    public synchronized Object get(long waitTimeMillis) {
  +        if(mbWait) {
  +            if(mList.size() == 0) {
  +                try {
  +                   wait(waitTimeMillis);
  +                }
  +                catch(InterruptedException ex) {
  +                    return null;
  +                }
  +            }
  +            
  +            if(mList.size() == 0) {
  +                return null;
  +            }
  +            else {
  +                return mList.removeFirst();
  +            }
  +        }
  +        else {
  +           return mList.removeFirst();
           }
       }
       
  @@ -68,8 +95,8 @@
           }
           
           if (miMaxSize <= 0 || mList.size() < miMaxSize) {
  -            mList.addFirst(obj);
  -            notifyAll();
  +            mList.addLast(obj);
  +            notify();
           }
       }
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to