For statistics purposes I want to count how many requests are made on a single Http Connection (how many keep-alive requests are made on one open socket).
In node.js I have access to 'socket' in request and response object and I can dynamically add a field, for example 'requests' and increment it. I can also attach 'socket close' handler and then log 'request' field into syslog and get the 1 min average in Graphite.
Is this possible with vertx.io? I cant find socket field in HttpRequest and HttpResponse classes.
There's no straightforward way to do this.
You might do a hack: HttpServerRequest
is actually an instance of org.vertx.java.core.http.impl.DefaultHttpServerRequest
that has private field ServerConnection conn
. This field can be accessed via reflection, as described for example here: http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html. Request counting might be implemented by creating a map of connections to integers.
This hack is good enough for testing purposes, but I won't work on production because of memory leaks. It would be better to add this functionality into handleMessage
method of ServerConnection
class and expose it via JMX.