package compositions;
import play.libs.F;
import play.mvc.Action;
import play.mvc.Http.Context;
import play.mvc.Result;
import play.mvc.With;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public class ResponseTimeLoggingComposition {
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ResponseTimeLoggingComposition.class);
/**
* Wraps the annotated action in an <code>ResponseTimeLoggingAction</code>.
*/
@With(ResponseTimeLoggingAction.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ResponseTimeLogging {
String value() default "*";
}
public static class ResponseTimeLoggingAction extends Action<ResponseTimeLogging> {
public F.Promise<Result> call(Context context) throws Throwable {
F.Promise<Result> res;
Long start = 0L;
try {
start = System.currentTimeMillis();
res = delegate.call(context);
}
finally {
Long stop = System.currentTimeMillis();
logger.info("responseTime(class:{}, method:{}, time:{}, clientId:\"\")", context.args.get("ROUTE_CONTROLLER"), context.args.get("ROUTE_ACTION_METHOD"), (stop - start));
}
return res;
}
}
}