You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/10/18 09:41:05 UTC
svn commit: r1023668 - in
/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs:
StatisticsImpl.java console/WebConsolePlugin.java
Author: cziegeler
Date: Mon Oct 18 07:41:05 2010
New Revision: 1023668
URL: http://svn.apache.org/viewvc?rev=1023668&view=rev
Log:
Don't throw illegal state exception if queue has been removed in the meantime; use status message
Avoid division by zero
Modified:
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java?rev=1023668&r1=1023667&r2=1023668&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/StatisticsImpl.java Mon Oct 18 07:41:05 2010
@@ -223,10 +223,14 @@ public class StatisticsImpl implements S
this.queuedJobs += other.queuedJobs;
this.waitingTime += other.waitingTime;
this.waitingCount += other.waitingCount;
- this.averageWaitingTime = this.waitingTime / this.waitingCount;
+ if ( this.waitingCount > 0 ) {
+ this.averageWaitingTime = this.waitingTime / this.waitingCount;
+ }
this.processingTime += other.processingTime;
this.processingCount += other.processingCount;
- this.averageProcessingTime = this.processingTime / this.processingCount;
+ if ( this.processingCount > 0 ) {
+ this.averageProcessingTime = this.processingTime / this.processingCount;
+ }
this.finishedJobs += other.finishedJobs;
this.failedJobs += other.failedJobs;
this.cancelledJobs += other.cancelledJobs;
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java?rev=1023668&r1=1023667&r2=1023668&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/console/WebConsolePlugin.java Mon Oct 18 07:41:05 2010
@@ -76,7 +76,7 @@ public class WebConsolePlugin extends Ht
private static final String PAR_QUEUE = "queue";
- private Queue getQueue(final HttpServletRequest req) throws ServletException {
+ private Queue getQueue(final HttpServletRequest req) {
final String name = req.getParameter(PAR_QUEUE);
if ( name != null ) {
for(final Queue q : this.jobManager.getQueues()) {
@@ -85,44 +85,81 @@ public class WebConsolePlugin extends Ht
}
}
}
- throw new ServletException("Wrong parameters");
+ return null;
+ }
+
+ private String getQueueErrorMessage(final HttpServletRequest req, final String command) {
+ final String name = req.getParameter(PAR_QUEUE);
+ if ( name == null || name.length() == 0 ) {
+ return "Queue parameter missing for opertation " + command;
+ }
+ return "Queue with name '" + name + "' not found for operation " + command;
}
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException {
+ String msg = null;
final String cmd = req.getParameter("action");
if ( "suspend".equals(cmd) ) {
final Queue q = this.getQueue(req);
- q.suspend();
+ if ( q != null ) {
+ q.suspend();
+ } else {
+ msg = this.getQueueErrorMessage(req, "suspend");
+ }
} else if ( "resume".equals(cmd) ) {
final Queue q = this.getQueue(req);
- q.resume();
+ if ( q != null ) {
+ q.resume();
+ } else {
+ msg = this.getQueueErrorMessage(req, "resume");
+ }
} else if ( "clear".equals(cmd) ) {
final Queue q = this.getQueue(req);
- q.clear();
+ if ( q != null ) {
+ q.clear();
+ } else {
+ msg = this.getQueueErrorMessage(req, "clear");
+ }
} else if ( "reset".equals(cmd) ) {
if ( req.getParameter(PAR_QUEUE) == null || req.getParameter(PAR_QUEUE).length() == 0 ) {
this.jobManager.getStatistics().reset();
} else {
final Queue q = this.getQueue(req);
- q.getStatistics().reset();
+ if ( q != null ) {
+ q.getStatistics().reset();
+ } else {
+ msg = this.getQueueErrorMessage(req, "reset");
+ }
}
} else if ( "dropall".equals(cmd) ) {
final Queue q = this.getQueue(req);
- q.removeAll();
+ if ( q != null ) {
+ q.removeAll();
+ } else {
+ msg = this.getQueueErrorMessage(req, "drop all");
+ }
+ } else {
+ msg = "Unknown command";
+ }
+ final String path = req.getContextPath() + req.getServletPath() + req.getPathInfo();
+ final String redirectTo;
+ if ( msg == null ) {
+ redirectTo = path;
} else {
- throw new ServletException("Unknown command");
+ redirectTo = path + "?message=" + msg;
}
- resp.sendRedirect(req.getContextPath() + req.getServletPath() + req.getPathInfo());
+ resp.sendRedirect(redirectTo);
}
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
throws ServletException, IOException {
+ final String msg = req.getParameter("message");
final PrintWriter pw = res.getWriter();
- pw.println("<p class='statline ui-state-highlight'>Apache Sling Eventing</p>");
+ pw.printf("<p class='statline ui-state-highlight'>Apache Sling Eventing%s%n</p>", msg != null ? " : " + msg : "");
pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
pw.println("<span style='float: left; margin-left: 1em'>Apache Sling Eventing: Overall Statistics</span>");
this.printForm(pw, null, "Reset Stats", "reset");