diff --git a/modules/org.restlet/pom.xml b/modules/org.restlet/pom.xml
index c034d1d1ee..3414c2796a 100644
--- a/modules/org.restlet/pom.xml
+++ b/modules/org.restlet/pom.xml
@@ -13,5 +13,11 @@
RESTful web framework for Java (API and Engine).
+
+
+ io.dropwizard.metrics
+ metrics-core
+ 3.2.5
+
diff --git a/modules/org.restlet/src/main/java/org/restlet/Application.java b/modules/org.restlet/src/main/java/org/restlet/Application.java
index ec60ee83ba..6d5dfa164f 100644
--- a/modules/org.restlet/src/main/java/org/restlet/Application.java
+++ b/modules/org.restlet/src/main/java/org/restlet/Application.java
@@ -47,6 +47,10 @@
import org.restlet.service.TunnelService;
import org.restlet.util.ServiceList;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.MetricSet;
+
/**
* Restlet managing a coherent set of resources and services. Applications are
* guaranteed to receive calls with their base reference set relatively to the
@@ -123,7 +127,7 @@ public static void setCurrent(Application application) {
/** The list of services. */
private final ServiceList services;
-
+
/**
* Constructor. Note this constructor is convenient because you don't have
* to provide a context like for {@link #Application(Context)}. Therefore
@@ -174,7 +178,7 @@ public Application(Context context) {
// [ifndef gae]
this.services.add(new org.restlet.service.TaskService(false));
- // [enddef]
+ // [enddef]
}
/**
@@ -271,7 +275,10 @@ public Restlet getInboundRoot() {
if (this.inboundRoot == null) {
synchronized (this) {
if (this.inboundRoot == null) {
- this.inboundRoot = createInboundRoot();
+ Restlet tempInboundRoot = createInboundRoot();
+ RequestCounterFilter requestCounterFilter = createRequestCounterFilter();
+ requestCounterFilter.setNext(tempInboundRoot);
+ this.inboundRoot = requestCounterFilter;
}
}
}
@@ -279,6 +286,11 @@ public Restlet getInboundRoot() {
return this.inboundRoot;
}
+ private RequestCounterFilter createRequestCounterFilter() {
+ RequestCounterFilter requestCounterFilter = new RequestCounterFilter(getName());
+ return requestCounterFilter;
+ }
+
/**
* Returns the metadata service. The service is enabled by default.
*
@@ -483,7 +495,9 @@ public synchronized void setInboundRoot(
* The inbound root Restlet.
*/
public synchronized void setInboundRoot(Restlet inboundRoot) {
- this.inboundRoot = inboundRoot;
+ RequestCounterFilter requestCounterFilter = createRequestCounterFilter();
+ requestCounterFilter.setNext(inboundRoot);
+ this.inboundRoot = requestCounterFilter;
if ((inboundRoot != null) && (inboundRoot.getContext() == null)) {
inboundRoot.setContext(getContext());
diff --git a/modules/org.restlet/src/main/java/org/restlet/Metrics.java b/modules/org.restlet/src/main/java/org/restlet/Metrics.java
new file mode 100644
index 0000000000..f5a2f2e2f1
--- /dev/null
+++ b/modules/org.restlet/src/main/java/org/restlet/Metrics.java
@@ -0,0 +1,14 @@
+package org.restlet;
+
+import com.codahale.metrics.JmxReporter;
+import com.codahale.metrics.MetricRegistry;
+
+public final class Metrics {
+
+ public static final MetricRegistry REGISTRY = new MetricRegistry();
+
+ static {
+ JmxReporter.forRegistry(REGISTRY).build().start();
+ }
+
+}
diff --git a/modules/org.restlet/src/main/java/org/restlet/RequestCounterFilter.java b/modules/org.restlet/src/main/java/org/restlet/RequestCounterFilter.java
new file mode 100644
index 0000000000..bef4d448d3
--- /dev/null
+++ b/modules/org.restlet/src/main/java/org/restlet/RequestCounterFilter.java
@@ -0,0 +1,28 @@
+package org.restlet;
+
+import org.restlet.routing.Filter;
+
+import com.codahale.metrics.Counter;
+
+public class RequestCounterFilter extends Filter{
+
+ private final Counter counter;
+
+ private final String name;
+
+ public RequestCounterFilter(String name) {
+
+ this.name = name;
+ this.counter = new Counter();
+
+ Metrics.REGISTRY.remove(name);
+ Metrics.REGISTRY.register(name, counter);
+ }
+
+ @Override
+ protected int beforeHandle(Request request, Response response) {
+ counter.inc();
+ return super.beforeHandle(request, response);
+ }
+
+}