| 1 |
|
//---PACKAGE DECLARATION--- |
| 2 |
< |
package uk.ac.ukc.iscream.util; |
| 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 |
| 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 |
| 125 |
< |
* includes the current size of each queue, and the total |
| 126 |
< |
* items passed through. |
| 122 |
> |
* This method returns an XML textual status of the queues. |
| 123 |
> |
* It is merely for observation, and would most likely be |
| 124 |
> |
* used by a larger "monitoring" component. Information |
| 125 |
> |
* returned includes the current size of each queue, and |
| 126 |
> |
* the total items passed through. |
| 127 |
|
* |
| 128 |
< |
* @return A String message containing status information. |
| 128 |
> |
* @return A String message containing status information in XML format |
| 129 |
|
*/ |
| 130 |
< |
public String status() { |
| 131 |
< |
String status = ""; |
| 130 |
> |
public String xmlStatus() { |
| 131 |
> |
String status = "<queue "; |
| 132 |
|
for(int i=0; i < _lists.size(); i++) { |
| 133 |
|
// check for null entries |
| 134 |
|
if(_lists.get(i) != null) { |
| 135 |
< |
status += "Queue number "+i+" contains "+((LinkedList) _lists.get(i)).size()+" elements"; |
| 136 |
< |
status += "\n"; |
| 135 |
> |
status += "queue"+i+"=\""+((LinkedList) _lists.get(i)).size()+"\" "; |
| 136 |
|
} |
| 137 |
|
else { |
| 138 |
< |
status += "Slot number "+i+" is currently empty"; |
| 140 |
< |
status += "\n"; |
| 138 |
> |
status += "queue"+i+"=\"[deleted]\" "; |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
< |
status += "A total of "+_count+" elements have been added to the queues"; |
| 141 |
> |
status += "total=\""+_count+"\"></queue>"; |
| 142 |
|
return status; |
| 143 |
|
} |
| 144 |
|
|
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
/** |
| 211 |
+ |
* Start a monitor on our own Queue. This will log XML |
| 212 |
+ |
* statistics about our Queue to a given Queue (could be |
| 213 |
+ |
* the one being monitored). |
| 214 |
+ |
* |
| 215 |
+ |
* @param interval The long interval, in milliseconds, at which to take samples |
| 216 |
+ |
* @param destQueue The queue to monitor to |
| 217 |
+ |
* @param name A name to identify this Queue with |
| 218 |
+ |
* @return whether we succeeded |
| 219 |
+ |
*/ |
| 220 |
+ |
public boolean startMonitor(long interval, Queue destQueue, String name) { |
| 221 |
+ |
if(_queueMon == null) { |
| 222 |
+ |
// start a monitor |
| 223 |
+ |
_queueMon = new QueueMonitor(this, destQueue, interval, name); |
| 224 |
+ |
_queueMon.start(); |
| 225 |
+ |
return true; |
| 226 |
+ |
} |
| 227 |
+ |
else { |
| 228 |
+ |
// already have a monitor running |
| 229 |
+ |
return false; |
| 230 |
+ |
} |
| 231 |
+ |
} |
| 232 |
+ |
|
| 233 |
+ |
/** |
| 234 |
+ |
* Start a monitor on our own Queue. This will log XML |
| 235 |
+ |
* statistics about our Queue to this Queue. |
| 236 |
+ |
* |
| 237 |
+ |
* @param interval The long interval, in milliseconds, at which to take samples |
| 238 |
+ |
* @param name A name to identify this Queue with |
| 239 |
+ |
* @return whether we succeeded |
| 240 |
+ |
*/ |
| 241 |
+ |
public boolean startMonitor(long interval, String name) { |
| 242 |
+ |
return startMonitor(interval, this, name); |
| 243 |
+ |
} |
| 244 |
+ |
|
| 245 |
+ |
/** |
| 246 |
+ |
* Stop a monitor on our Queue if we have on running. |
| 247 |
+ |
* |
| 248 |
+ |
* @return whether we succeeded |
| 249 |
+ |
*/ |
| 250 |
+ |
public boolean stopMonitor() { |
| 251 |
+ |
if(_queueMon != null) { |
| 252 |
+ |
// stop a monitor |
| 253 |
+ |
_queueMon.shutdown(); |
| 254 |
+ |
_queueMon = null; |
| 255 |
+ |
return true; |
| 256 |
+ |
} |
| 257 |
+ |
else { |
| 258 |
+ |
// no monitor running |
| 259 |
+ |
return false; |
| 260 |
+ |
} |
| 261 |
+ |
} |
| 262 |
+ |
|
| 263 |
+ |
/** |
| 264 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 265 |
|
* method to provide clean logging (every class should have this). |
| 266 |
|
* |
| 292 |
|
* passed through, for statistical purposes. |
| 293 |
|
*/ |
| 294 |
|
private int _count = 0; |
| 295 |
+ |
|
| 296 |
+ |
/** |
| 297 |
+ |
* A reference to our QueueMonitor, if we have one. |
| 298 |
+ |
*/ |
| 299 |
+ |
private QueueMonitor _queueMon = null; |
| 300 |
|
|
| 301 |
|
/** |
| 302 |
|
* This is the friendly identifier of the |