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.5 by tdb, Tue Jan 23 20:14: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 87 | Line 88 | class Queue {
88          }
89          return o;
90      }
91 <      
91 >    
92      /**
93 +     * This method releases a get() method that's currently
94 +     * waiting on an empty queue. This was designed for
95 +     * shutdown() type methods that may have problems closing
96 +     * if the thread of control is waiting on a queue.
97 +     *
98 +     * @param queue the queue to release
99 +     */
100 +    public void releaseQueue(int queue) {
101 +        synchronized(((LinkedList) _lists.get(queue))) {
102 +                ((LinkedList) _lists.get(queue)).notifyAll();
103 +        }
104 +    }
105 +    
106 +    /**
107       * This method returns a textual status of the queues. It
108       * is merely for observation, and would most likely be used
109       * by a larger "monitoring" component. Information returned
# Line 115 | Line 130 | class Queue {
130      }
131      
132      /**
133 +     * Returns the size of a given queue. A consumer can use
134 +     * this to see how big their queue is at any given time.
135 +     * they should use their queue number as the parameter.
136 +     *
137 +     * @param queue The queue number to query.
138 +     * @return the current size of the queue.
139 +     */
140 +    public int queueSize(int queue) throws InvalidQueueException {
141 +        if (queue >= _lists.size() || _lists.get(queue) == null) {
142 +            throw new InvalidQueueException("Requested queue "+queue+" does not exist");
143 +        }
144 +        return ((LinkedList) _lists.get(queue)).size();
145 +    }
146 +    
147 +    /**
148 +     * Returns the total numer of elements to have passed
149 +     * through this queue (ie. a counter on the add method).
150 +     *
151 +     * @return the element-ometer
152 +     */
153 +    public int elementCount() {
154 +        return _count;
155 +    }
156 +    
157 +    /**
158       * This method assigns a queue to a consumer. The idea behind
159       * this is to ensure that only 1 consumer can be associated with
160       * a given queue, otherwise the whole "blocking" thing fails
# Line 162 | Line 202 | class Queue {
202       *
203       * @return the name of this class and its CVS revision
204       */
205 <    /*public String toString() {
205 >    public String toString() {
206          return FormatName.getName(
207              _name,
208              getClass().getName(),
209              REVISION);
210 <    }*/
210 >    }
211  
212   //---PRIVATE METHODS---
213  
# Line 195 | Line 235 | class Queue {
235       * can be placed here.  This name could also
236       * be changed to null for utility classes.
237       */
238 <    //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();
238 >    private String _name = null;
239  
240   //---STATIC ATTRIBUTES---
241  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines