ps.println("<tr><td>Queue Name</td><td>Size</td><td>Producers</td><td>Consumers</td><td>Last Producer Date</td><td>Last Consumer Date</td></tr>");
// print out a list of every queue
Enumeration<Queue> queues = queueManager.getQueues();
while (queues.hasMoreElements()) {
Queue queue = queues.nextElement();
ps.print("<tr><td>");
ps.print(queue.getName());
ps.print("</td><td>");
ps.print(queue.getSize());
ps.print("</td><td>");
ps.print(queue.getProducerCount());
ps.print("</td><td>");
ps.print(queue.getConsumerCount());
ps.print("</td><td>");
ps.print(queue.getLastProducerCountChangeTime());
ps.print("</td><td>");
ps.print(queue.getLastConsumerCountChangeTime());
ps.print("</td></tr>");
}
ps.println("</table>");
} else if (cmd.equals("monitor")) {
// is the optional "since" parameter included -- this is asking
// for updates only after this timestamp....
long since = -1;
String sinceString = request.getParameter("since");
if (!StringUtil.isEmpty(sinceString)) {
try {
since = Long.parseLong(sinceString);
} catch (Exception e) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
ps.print("Unable to convert since query parameter to a long value");
return;
}
}
// print out result code, version, areaId
ps.print(ProtocolConstants.KEY_RESULT_CODE + ":" + ProtocolConstants.RC_OK + ProtocolConstants.LINE_DELIMITER);
ps.print(ProtocolConstants.KEY_VERSION + ":" + ProtocolConstants.CURRENT_VERSION + ProtocolConstants.LINE_DELIMITER);
ps.print(ProtocolConstants.KEY_AREA_ID + ":" + dqm.getConfiguration().getAreaId() + ProtocolConstants.LINE_DELIMITER);
// print out a list of every queue
Enumeration<Queue> queues = queueManager.getQueues();
while (queues.hasMoreElements()) {
Queue queue = queues.nextElement();
// should we match the last timestamp for a consumer change?
if (since > 0) {
// if this queue hasn't been changed since the last time
if (queue.getLastConsumerCountChangeTime() < since) {
continue;
}
}
// is this a "local only" queue?
if (queue.isLocalOnly()) {
continue;
}
ps.print(ProtocolConstants.KEY_QUEUE);
ps.print(":");
ps.print(queue.getName());
ps.print(",");
ps.print(queue.getConsumerCount());
ps.print(ProtocolConstants.LINE_DELIMITER);
}
} else if (cmd.equals("transfer")) {
String queueName = request.getParameter("queue");
if (StringUtil.isEmpty(queueName)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
ps.print("Parameter queue is required for a transfer request");
return;
}
byte[] entityContent = requestToByteArray(request);
if (entityContent == null || entityContent.length <= 0) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
ps.print("Probably not a POST request since body does not contain an entity");
return;
}
logger.trace("[{}] Received transfer request to queue with an item having a byteLength [{}]", queueName, entityContent.length);
// at this point, we'll be returning an actual response back
int result = 0;
String message = "OK";
// ahh, let's see if the queue exists...
if (!queueManager.hasQueue(queueName)) {
result = ProtocolConstants.RC_NO_QUEUE;
message = "The queue " + queueName + " was not found";
} else {
// get the queue -- we know it exists
Queue queue = queueManager.getQueue(queueName);
// are there still consumers?
if (queue.getConsumerCount() <= 0) {
result = ProtocolConstants.RC_NO_CONSUMER;
message = "No local consumers for queue " + queueName;
} else {
// get the transcoder
Transcoder tc = queue.getTranscoder();
try {
// transcode the item
Object item = item = tc.decode(entityContent);
logger.trace("[{}] Parsed item: {}", queueName, item);