I want to generate event on start and end of the method to log time stamp for QOS & instrumentation purpose. In spring framework that it is easy to achieve using AOP without writing boiler plate code in each of the methods.
I want to do similar in play. I looked in action & @with annotation however it is not giving desired result.
What is best way to log event & time stamp on start (before) and on completion (after) method?
Below is my action class:
import play.libs.F.Promise;
import play.mvc.Action;
import play.mvc.Http;
import play.mvc.SimpleResult;
public class PublishEventAction extends Action<PublishEvent> {
@Override
public Promise<SimpleResult> call(Http.Context context) throws Throwable
{
try {
before(context);
Promise<SimpleResult> result = delegate.call(context); // This part calls your real action method
after(context);
return result;
} catch (RuntimeException e) {
throw e;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
private void before(Http.Context context) {
// Do the before things here
System.out.println("Before: " + context.request().path()+context.toString()+"current time : "+System.currentTimeMillis());
}
private void after(Http.Context context) {
// Do the after things here
System.out.println("After: " + context.request().path()+context.toString()+"current time : "+System.currentTimeMillis());
}
}
Thanks in advance!