15 |
|
* @author $Author$ |
16 |
|
* @version $Id$ |
17 |
|
*/ |
18 |
< |
class Queue { |
18 |
> |
public class Queue { |
19 |
|
|
20 |
|
//---FINAL ATTRIBUTES--- |
21 |
|
|
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 erases the contents of a given queue. This |
108 |
+ |
* method should be used with care. It can only empty one |
109 |
+ |
* internal queue, not all of them. This must be called |
110 |
+ |
* multiple times to empty all queues. |
111 |
+ |
* |
112 |
+ |
* @param queue the queue to empty. |
113 |
+ |
*/ |
114 |
+ |
public void clearQueue(int queue) { |
115 |
+ |
synchronized(this) { |
116 |
+ |
((LinkedList) _lists.get(queue)).clear(); |
117 |
+ |
} |
118 |
+ |
} |
119 |
+ |
|
120 |
+ |
/** |
121 |
|
* This method returns a textual status of the queues. It |
122 |
|
* is merely for observation, and would most likely be used |
123 |
|
* by a larger "monitoring" component. Information returned |
144 |
|
} |
145 |
|
|
146 |
|
/** |
147 |
+ |
* Returns the size of a given queue. A consumer can use |
148 |
+ |
* this to see how big their queue is at any given time. |
149 |
+ |
* they should use their queue number as the parameter. |
150 |
+ |
* |
151 |
+ |
* @param queue The queue number to query. |
152 |
+ |
* @return the current size of the queue. |
153 |
+ |
*/ |
154 |
+ |
public int queueSize(int queue) throws InvalidQueueException { |
155 |
+ |
if (queue >= _lists.size() || _lists.get(queue) == null) { |
156 |
+ |
throw new InvalidQueueException("Requested queue "+queue+" does not exist"); |
157 |
+ |
} |
158 |
+ |
return ((LinkedList) _lists.get(queue)).size(); |
159 |
+ |
} |
160 |
+ |
|
161 |
+ |
/** |
162 |
+ |
* Returns the total numer of elements to have passed |
163 |
+ |
* through this queue (ie. a counter on the add method). |
164 |
+ |
* |
165 |
+ |
* @return the element-ometer |
166 |
+ |
*/ |
167 |
+ |
public int elementCount() { |
168 |
+ |
return _count; |
169 |
+ |
} |
170 |
+ |
|
171 |
+ |
/** |
172 |
|
* This method assigns a queue to a consumer. The idea behind |
173 |
|
* this is to ensure that only 1 consumer can be associated with |
174 |
|
* a given queue, otherwise the whole "blocking" thing fails |
216 |
|
* |
217 |
|
* @return the name of this class and its CVS revision |
218 |
|
*/ |
219 |
< |
/*public String toString() { |
219 |
> |
public String toString() { |
220 |
|
return FormatName.getName( |
221 |
|
_name, |
222 |
|
getClass().getName(), |
223 |
|
REVISION); |
224 |
< |
}*/ |
224 |
> |
} |
225 |
|
|
226 |
|
//---PRIVATE METHODS--- |
227 |
|
|
249 |
|
* can be placed here. This name could also |
250 |
|
* be changed to null for utility classes. |
251 |
|
*/ |
252 |
< |
//private String _name = <!THIS SHOULD CALL A STATIC NAME IN THE COMPONENT CLASS FOR THIS OBJECT!>; |
200 |
< |
|
201 |
< |
/** |
202 |
< |
* This holds a reference to the |
203 |
< |
* system logger that is being used. |
204 |
< |
*/ |
205 |
< |
//private Logger _logger = ReferenceManager.getInstance().getLogger(); |
252 |
> |
private String _name = null; |
253 |
|
|
254 |
|
//---STATIC ATTRIBUTES--- |
255 |
|
|