You could create a common subclass (let's call it JeffRemoteServiceServlet) of RemoteServiceServlet that overrides the onAfterRequestDeserialized(RPCRequest) method. That method is called, as the name implies, everytime the servlet receives an RPC request, so it's the perfect spot to collect information for logging.
That doesn't get you the timing information you're after, though, so you could instead override RemoteServiceServlet.processCall(String) to
1. Start a timer (i.e., record System.nanoTime() or whatever)
2. Call super.processCall
3. Stop the timer
Now, so long as all of your service implementations override JeffRemoteServiceServlet, you've got the desired behavior everywhere. I'm not sure where the best spot to do the actual averaging would be, but this should at least let you hook in at the right spot.
Another (much more difficult) option, that you and Philippe have alluded to, is to call setServiceEntryPoint client-side and pipe all of your RPC requests through a single servlet. You can make this happen automatically, or even completely take over the RPC transport process by creating a custom proxy generator. We've done this, and as you mentioned, it's a little difficult to wrap your head around at first, but once you have, the changes are actually pretty minor (unless you decide to start adding features like batching, etc.). You'd need:
1. A new subclass of RemoteServiceProxy (let's call it DispatchedRemoteServiceProxy) that overrides doInvoke() to take control of the transport of the request
2. A new subclass of ProxyCreator (let's call it DispatchedRemoteProxyCreator) that overrides getProxySupertype() to return DispatchedRemoteServiceProxy.class
3. A new subclass of ServiceInterfaceProxyGenerator (let's call it DispatchedRemoteServiceGenerator) that overrides createProxyCreator() to return a new DispatchedRemoteProxyCreator
4. Have your services inherit a new interface (DispatchedRemoteService) and set up your .gwt.xml file generate impls of that interface with DispatchedRemoteServiceGenerator.
The trickiest part is what to do in DispatchedRemoteServiceProxy.doInvoke(). You'll want to make a request to your special dispatch servlet, of course, and then decode it once you get a response. RequestCallbackAdapter holds the keys to making this happen. Dispatching the request server-side is relatively trivial once you have the decoded RPCRequest.
The point of all this is of course to have all your requests one through a single servlet, which would, among other things, probably make collecting information about requests a little easier.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Post a Comment