| 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 |
| 15 |
|
* @author $Author$ |
| 16 |
|
* @version $Id$ |
| 17 |
|
*/ |
| 18 |
< |
class Queue { |
| 18 |
> |
public class Queue { |
| 19 |
|
|
| 20 |
|
//---FINAL ATTRIBUTES--- |
| 21 |
|
|
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
/** |
| 119 |
+ |
* Returns the size of a given queue. A consumer can use |
| 120 |
+ |
* this to see how big their queue is at any given time. |
| 121 |
+ |
* they should use their queue number as the parameter. |
| 122 |
+ |
* |
| 123 |
+ |
* @param queue The queue number to query. |
| 124 |
+ |
* @return the current size of the queue. |
| 125 |
+ |
*/ |
| 126 |
+ |
public int queueSize(int queue) throws InvalidQueueException { |
| 127 |
+ |
if (queue >= _lists.size() || _lists.get(queue) == null) { |
| 128 |
+ |
throw new InvalidQueueException("Requested queue "+queue+" does not exist"); |
| 129 |
+ |
} |
| 130 |
+ |
return ((LinkedList) _lists.get(queue)).size(); |
| 131 |
+ |
} |
| 132 |
+ |
|
| 133 |
+ |
/** |
| 134 |
+ |
* Returns the total numer of elements to have passed |
| 135 |
+ |
* through this queue (ie. a counter on the add method). |
| 136 |
+ |
* |
| 137 |
+ |
* @return the element-ometer |
| 138 |
+ |
*/ |
| 139 |
+ |
public int elementCount() { |
| 140 |
+ |
return _count; |
| 141 |
+ |
} |
| 142 |
+ |
|
| 143 |
+ |
/** |
| 144 |
|
* This method assigns a queue to a consumer. The idea behind |
| 145 |
|
* this is to ensure that only 1 consumer can be associated with |
| 146 |
|
* a given queue, otherwise the whole "blocking" thing fails |
| 188 |
|
* |
| 189 |
|
* @return the name of this class and its CVS revision |
| 190 |
|
*/ |
| 191 |
< |
/*public String toString() { |
| 191 |
> |
public String toString() { |
| 192 |
|
return FormatName.getName( |
| 193 |
|
_name, |
| 194 |
|
getClass().getName(), |
| 195 |
|
REVISION); |
| 196 |
< |
}*/ |
| 196 |
> |
} |
| 197 |
|
|
| 198 |
|
//---PRIVATE METHODS--- |
| 199 |
|
|
| 221 |
|
* can be placed here. This name could also |
| 222 |
|
* be changed to null for utility classes. |
| 223 |
|
*/ |
| 224 |
< |
//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(); |
| 224 |
> |
private String _name = null; |
| 225 |
|
|
| 226 |
|
//---STATIC ATTRIBUTES--- |
| 227 |
|
|