【发布时间】:2014-02-20 20:05:45
【问题描述】:
我想在方法的开始和结束时生成事件以记录用于 QOS 和检测目的的时间戳。在 Spring 框架中,使用 AOP 很容易实现,而无需在每个方法中编写样板代码。
我想在游戏中做类似的事情。我查看了操作和 @with 注释,但它没有给出预期的结果。
在开始(之前)和完成(之后)方法上记录事件和时间戳的最佳方法是什么?
下面是我的动作类:
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());
}
}
提前致谢!
【问题讨论】:
标签: playframework playframework-2.0 playframework-2.2