ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/Queue/Queue.java
(Generate patch)

Comparing experimental/server/Queue/Queue.java (file contents):
Revision 1.3 by tdb, Tue Jan 2 01:50:17 2001 UTC vs.
Revision 1.6 by tdb, Tue Jan 30 02:13:09 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.util;
3  
4   //---IMPORTS---
5   import java.util.LinkedList;
6   import java.util.NoSuchElementException;
7 < //import uk.ac.ukc.iscream.util.*;
7 > import uk.ac.ukc.iscream.util.*;
8  
9   /**
10   * A Queue class designed to operate in a multi-threaded environment, with
# Line 14 | Line 15 | import java.util.NoSuchElementException;
15   * @author  $Author$
16   * @version $Id$
17   */
18 < class Queue {
18 > public class Queue {
19  
20   //---FINAL ATTRIBUTES---
21  
# Line 61 | Line 62 | class Queue {
62       * This method returns an object from the front of a given queue.
63       * It will block until data exists in the queue if required.
64       *
65 +     * @param The queue to retrieve data from.
66       * @return The object from the front of the queue.
67       * @throws InvalidQueueException if the queue does not exist.
68       */
# Line 87 | Line 89 | class Queue {
89          }
90          return o;
91      }
92 <      
92 >    
93      /**
94 +     * This method releases a get() method that's currently
95 +     * waiting on an empty queue. This was designed for
96 +     * shutdown() type methods that may have problems closing
97 +     * if the thread of control is waiting on a queue.
98 +     *
99 +     * @param queue the queue to release.
100 +     */
101 +    public void releaseQueue(int queue) {
102 +        synchronized(((LinkedList) _lists.get(queue))) {
103 +                ((LinkedList) _lists.get(queue)).notifyAll();
104 +        }
105 +    }
106 +
107 +    /**
108 +     * This method erases the contents of a given queue. This
109 +     * method should be used with care. It can only empty one
110 +     * internal queue, not all of them. This must be called
111 +     * multiple times to empty all queues.
112 +     *
113 +     * @param queue the queue to empty.
114 +     */
115 +    public void clearQueue(int queue) {
116 +        synchronized(this) {
117 +            ((LinkedList) _lists.get(queue)).clear();
118 +        }
119 +    }
120 +    
121 +    /**
122       * This method returns a textual status of the queues. It
123       * is merely for observation, and would most likely be used
124       * by a larger "monitoring" component. Information returned
# Line 115 | Line 145 | class Queue {
145      }
146      
147      /**
148 +     * Returns the size of a given queue. A consumer can use
149 +     * this to see how big their queue is at any given time.
150 +     * they should use their queue number as the parameter.
151 +     *
152 +     * @param queue The queue number to query.
153 +     * @return the current size of the queue.
154 +     * @throws InvalidQueueException if the queue does not exist.
155 +     */
156 +    public int queueSize(int queue) throws InvalidQueueException {
157 +        if (queue >= _lists.size() || _lists.get(queue) == null) {
158 +            throw new InvalidQueueException("Requested queue "+queue+" does not exist");
159 +        }
160 +        return ((LinkedList) _lists.get(queue)).size();
161 +    }
162 +    
163 +    /**
164 +     * Returns the total numer of elements to have passed
165 +     * through this queue (ie. a counter on the add method).
166 +     *
167 +     * @return the element-ometer.
168 +     */
169 +    public int elementCount() {
170 +        return _count;
171 +    }
172 +    
173 +    /**
174       * This method assigns a queue to a consumer. The idea behind
175       * this is to ensure that only 1 consumer can be associated with
176       * a given queue, otherwise the whole "blocking" thing fails
# Line 160 | Line 216 | class Queue {
216       * This uses the uk.ac.ukc.iscream.util.FormatName class
217       * to format the toString()
218       *
219 <     * @return the name of this class and its CVS revision
219 >     * @return the name of this class and its CVS revision.
220       */
221 <    /*public String toString() {
221 >    public String toString() {
222          return FormatName.getName(
223              _name,
224              getClass().getName(),
225              REVISION);
226 <    }*/
226 >    }
227  
228   //---PRIVATE METHODS---
229  
# Line 195 | Line 251 | class Queue {
251       * can be placed here.  This name could also
252       * be changed to null for utility classes.
253       */
254 <    //private String _name = <!THIS SHOULD CALL A STATIC NAME IN THE COMPONENT CLASS FOR THIS OBJECT!>;
199 <
200 <    /**
201 <     * This holds a reference to the
202 <     * system logger that is being used.
203 <     */
204 <    //private Logger _logger = ReferenceManager.getInstance().getLogger();
254 >    private String _name = null;
255  
256   //---STATIC ATTRIBUTES---
257  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines