WICKET-3558 Expose active requests via JMX
git-svn-id: https://svn.apache.org/repos/asf/wicket/branches/wicket-1.4.x@1085993 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLogger.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLogger.java
index 072a506..86a0ce8 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLogger.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLogger.java
@@ -45,11 +45,11 @@
// do this so that we don't have to cast all the time
if (application instanceof WebApplication)
{
- this.webApplication = (WebApplication)application;
+ webApplication = (WebApplication)application;
}
else
{
- this.webApplication = null;
+ webApplication = null;
}
}
@@ -93,6 +93,32 @@
}
/**
+ * @see org.apache.wicket.jmx.RequestLoggerMBean#getNumberOfCurrentActiveRequests()
+ */
+ public Integer getNumberOfCurrentActiveRequests() throws IOException
+ {
+ org.apache.wicket.protocol.http.IRequestLogger logger = getRequestLogger();
+ if (logger != null)
+ {
+ return Integer.valueOf(logger.getCurrentActiveRequestCount());
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.wicket.jmx.RequestLoggerMBean#getPeakNumberOfActiveRequests()
+ */
+ public Integer getPeakNumberOfActiveRequests() throws IOException
+ {
+ org.apache.wicket.protocol.http.IRequestLogger logger = getRequestLogger();
+ if (logger != null)
+ {
+ return Integer.valueOf(logger.getPeakActiveRequestCount());
+ }
+ return null;
+ }
+
+ /**
* @see org.apache.wicket.jmx.RequestLoggerMBean#restart()
*/
public void restart() throws IOException
diff --git a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLoggerMBean.java b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLoggerMBean.java
index ca0fc66..fcda010 100644
--- a/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLoggerMBean.java
+++ b/wicket-jmx/src/main/java/org/apache/wicket/jmx/RequestLoggerMBean.java
@@ -62,6 +62,23 @@
Integer getPeakNumberOfSessions() throws IOException;
/**
+ * Gets the current active requests number
+ *
+ * @return current (at the time of method invocation) number of concurrent request being
+ * processed
+ * @throws IOException
+ */
+ Integer getNumberOfCurrentActiveRequests() throws IOException;
+
+ /**
+ * The high water mark for the number of requests being processed concurrently
+ *
+ * @return the largest number of the concurrent requests being processed
+ * @throws IOException
+ */
+ Integer getPeakNumberOfActiveRequests() throws IOException;
+
+ /**
* Registers a new request logger at the application. You need a request logger for some
* functions of the session bean. Be aware that sessions will be logged from this time on, so
* they may not reflect the actual number of sessions. Also, if one was registered, it will be
diff --git a/wicket/src/main/java/org/apache/wicket/protocol/http/IRequestLogger.java b/wicket/src/main/java/org/apache/wicket/protocol/http/IRequestLogger.java
index 14a07d3..1de9497 100644
--- a/wicket/src/main/java/org/apache/wicket/protocol/http/IRequestLogger.java
+++ b/wicket/src/main/java/org/apache/wicket/protocol/http/IRequestLogger.java
@@ -67,6 +67,11 @@
public int getCurrentActiveRequestCount();
/**
+ * @return The peak active requests
+ */
+ public int getPeakActiveRequestCount();
+
+ /**
* called when the session is created and has an id. (for http it means that the http session is
* created)
*
diff --git a/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java b/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
index 30b667d..e32d16b 100644
--- a/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
+++ b/wicket/src/main/java/org/apache/wicket/protocol/http/RequestLogger.java
@@ -100,6 +100,8 @@
private final AtomicInteger active = new AtomicInteger();
+ private final AtomicInteger peakActive = new AtomicInteger();
+
/**
* Construct.
*/
@@ -150,6 +152,14 @@
}
/**
+ * @see org.apache.wicket.protocol.http.IRequestLogger#getPeakActiveRequestCount()
+ */
+ public int getPeakActiveRequestCount()
+ {
+ return peakActive.get();
+ }
+
+ /**
* @see org.apache.wicket.protocol.http.IRequestLogger#getRequests()
*/
public List<RequestData> getRequests()
@@ -194,7 +204,12 @@
{
rd = new RequestData();
requestCycle.setMetaData(REQUEST_DATA, rd);
- active.incrementAndGet();
+ int activeCount = active.incrementAndGet();
+
+ if (activeCount > peakActive.get())
+ {
+ peakActive.set(activeCount);
+ }
}
return rd;
}